-
Notifications
You must be signed in to change notification settings - Fork 0
/
mzrecal_test.go
107 lines (98 loc) · 2.66 KB
/
mzrecal_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"errors"
"testing"
)
func TestParseFloat64Range(t *testing.T) {
// Test case 1: Valid input range
min, max, err := parseFloat64Range("0.5:1.5", 0.0, 2.0)
if err != nil {
t.Errorf("Expected no error, got: %v", err)
}
if min != 0.5 {
t.Errorf("Expected min to be 0.5, got: %f", min)
}
if max != 1.5 {
t.Errorf("Expected max to be 1.5, got: %f", max)
}
// Test case 2: Empty input range
min, max, err = parseFloat64Range("", 0.0, 2.0)
if err != nil {
t.Errorf("Expected no error, got: %v", err)
}
if min != 0.0 {
t.Errorf("Expected min to be 0.0, got: %f", min)
}
if max != 2.0 {
t.Errorf("Expected max to be 2.0, got: %f", max)
}
// Test case 3: Invalid input range
min, max, err = parseFloat64Range("2.5:1.5", 0.0, 2.0)
if err == nil {
t.Errorf("Expected error, got nil")
}
if !errors.Is(err, ErrRangeSpec) {
t.Errorf("Expected error: %v, got: %v", ErrRangeSpec, err)
}
if min != 1.5 {
t.Errorf("Expected min to be 1.5, got: %f", min)
}
if max != 1.5 {
t.Errorf("Expected max to be 1.5, got: %f", max)
}
// Test case 4: Only max specified
min, max, err = parseFloat64Range(":1.5", 0.0, 2.0)
if err != nil {
t.Errorf("Expected no error, got: %v", err)
}
if min != 0.0 {
t.Errorf("Expected min to be 0.0, got: %f", min)
}
if max != 1.5 {
t.Errorf("Expected max to be 1.5, got: %f", max)
}
// Test case 5: Only min specified
min, max, err = parseFloat64Range("0.5:", 0.0, 2.0)
if err != nil {
t.Errorf("Expected no error, got: %v", err)
}
if min != 0.5 {
t.Errorf("Expected min to be 0.5, got: %f", min)
}
if max != 2.0 {
t.Errorf("Expected max to be 2.0, got: %f", max)
}
// Test case 6: Only ":" specified
min, max, err = parseFloat64Range(":", 0.0, 2.0)
if err != nil {
t.Errorf("Expected no error, got: %v", err)
}
if min != 0.0 {
t.Errorf("Expected min to be 0.0, got: %f", min)
}
if max != 2.0 {
t.Errorf("Expected max to be 2.0, got: %f", max)
}
// Test case 7: Exponents in numbers
min, max, err = parseFloat64Range("-2.0e10:3.0e10", -1000000000000.0, 1000000000000.0)
if err != nil {
t.Errorf("Expected no error, got: %v", err)
}
if min != -2.0e10 {
t.Errorf("Expected min to be -2.0e10, got: %f", min)
}
if max != 3.0e10 {
t.Errorf("Expected max to be 3.0e10, got: %f", max)
}
// Test case 8: Out of range
min, max, err = parseFloat64Range("-2.0:2.0", -1.0, 1.0)
if err != nil {
t.Errorf("Expected no error, got: %v", err)
}
if min != -1.0 {
t.Errorf("Expected min to be -1.0, got: %f", min)
}
if max != 1.0 {
t.Errorf("Expected max to be 1.0, got: %f", max)
}
}