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

import (
	"math"
	"testing"
)

func TestConversion(t *testing.T) {
	testcases := []struct {
		rvp  RVP6
		dbz  DBZ
Jonny Schäfer's avatar
Jonny Schäfer committed
12
		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()
Jonny Schäfer's avatar
Jonny Schäfer committed
22
23
		zr := dbz.PrecipitationRate()
		rz := Reflectivity(zr)
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
35
36
37
		if math.Abs(test.zr-zr) > 0.0001 {
			t.Errorf("RVP6(%f).ToDBZ().PrecipitationRate() = %f; expected: %f", test.rvp, zr, test.zr)
		}
		if math.Abs(float64(test.dbz - rz)) > 0.0000001 {
			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
		}
	}
}