conversion_test.go 920 Bytes
Newer Older
Jonny Schäfer's avatar
Jonny Schäfer committed
1
2
3
4
5
6
7
8
9
package radolan

import (
	"math"
	"testing"
)

func TestConversion(t *testing.T) {
	testcases := []struct {
Jonny Schäfer's avatar
Go fmt    
Jonny Schäfer committed
10
11
12
		rvp RVP6
		dbz DBZ
		zr  float64
Jonny Schäfer's avatar
Jonny Schäfer committed
13
14
15
16
17
18
19
20
21
	}{
		{0, -32.5, 0.0001},
		{65, 0, 0.0201},
		{100, 17.5, 0.3439},
		{200, 67.5, 1141.7670},
	}

	for _, test := range testcases {
		dbz := test.rvp.ToDBZ()
22
23
		zr := dbz.PrecipitationRate(Aniol80)
		rz := Reflectivity(zr, Aniol80)
Jonny Schäfer's avatar
Jonny Schäfer committed
24
25
26
27
28
29
30
31
		rvp := dbz.ToRVP6()

		if dbz != test.dbz {
			t.Errorf("RVP6(%f).ToDBZ() = %f; expected: %f", test.rvp, dbz, test.dbz)
		}
		if rvp != test.rvp {
			t.Errorf("RVP6(%f).ToDBZ().ToRVP6() = %f; expected: %f", test.rvp, rvp, test.rvp)
		}
Jonny Schäfer's avatar
Jonny Schäfer committed
32
33
34
		if math.Abs(test.zr-zr) > 0.0001 {
			t.Errorf("RVP6(%f).ToDBZ().PrecipitationRate() = %f; expected: %f", test.rvp, zr, test.zr)
		}
Jonny Schäfer's avatar
Go fmt    
Jonny Schäfer committed
35
		if math.Abs(float64(test.dbz-rz)) > 0.0000001 {
Jonny Schäfer's avatar
Jonny Schäfer committed
36
37
			t.Errorf("Reflectivity(RVP6(%f).ToDBZ().PrecipitationRate()) = %f; expected: %f",
				test.rvp, rz, test.dbz)
Jonny Schäfer's avatar
Jonny Schäfer committed
38
39
40
		}
	}
}