-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlxgata_test.go
68 lines (63 loc) · 1.63 KB
/
lxgata_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package lxgata
import (
"math"
"testing"
)
func TestLoadCrossSections(t *testing.T) {
cs, err := LoadCrossSections("LXCat_format_test.txt")
if err != nil {
t.Fatalf("Unable to load cross sections %v", err.Error())
}
if len(cs) != 4 {
t.Fatalf("Not all processes were loaded")
}
for _, p := range cs {
if (p.Type == IONIZATION || p.Type == EXCITATION || p.Type == ROTATION) && p.Data[0].Value != 0. {
t.Fatalf("Zero beyond threshold energy is not added for process %v", p)
}
}
//todo: add more tests
}
func TestCrossSectionAt(t *testing.T) {
collision := Collision{Data: []CrossSectionPoint{
{1.0e+1, 0, (1 - 0) / (1.6e+1 - 1.0e+1)},
{1.6e+1, 1, (2 - 1) / (3.2e+1 - 1.6e+1)},
{3.2e+1, 2, (7 - 2) / (5.0e+2 - 3.2e+1)},
{5.0e+2, 7, 0},
}}
eps := 1e-5
tests := map[string]struct {
input float64
result float64
}{
"energy < any in Collision.Data": {
input: 1.0e+0,
result: 0,
},
"energy exactly at lowest point in Collision.Data": {
input: 1.0e+1,
result: 0,
},
"energy between two Collision.Data points": {
input: 266.,
result: 4.5,
},
"energy exactly at maximum in Collision.Data": {
input: 5.0e+2,
result: 7,
},
"energy > any in Collision.Data": {
input: 6.0e+2,
result: 7,
},
}
for name, test := range tests {
test := test // NOTE: uncomment for Go < 1.22, see /doc/faq#closures_and_goroutines
t.Run(name, func(t *testing.T) {
t.Parallel()
if got, expected := collision.CrossSectionAt(test.input), test.result; math.Abs(got-expected) > eps {
t.Fatalf("%v (c).CrossSectionAt(%v) returned %v; expected %v", name, test.input, got, expected)
}
})
}
}