-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil_test.go
More file actions
64 lines (58 loc) · 1.69 KB
/
Copy pathutil_test.go
File metadata and controls
64 lines (58 loc) · 1.69 KB
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
package pint
import "testing"
func TestUnitsContainerCreation(t *testing.T) {
x := NewUnitsContainer(map[string]float64{"meter": 1, "second": 2})
y := NewUnitsContainer(map[string]float64{"meter": 1, "second": 2})
if !x.Equal(y) || x.Get("meter") != 1 {
t.Fatal(x)
}
}
func TestUnitsContainerString(t *testing.T) {
if NewUnitsContainer(nil).String() != "dimensionless" {
t.Fatal("empty")
}
x := NewUnitsContainer(map[string]float64{"meter": 1, "second": 2})
if x.String() != "meter * second ** 2" {
t.Fatalf("got %q", x.String())
}
}
func TestUnitsContainerBool(t *testing.T) {
if NewUnitsContainer(map[string]float64{"meter": 1}).Empty() {
t.Fatal("should be nonempty")
}
if !NewUnitsContainer(nil).Empty() {
t.Fatal("should be empty")
}
}
func TestUnitsContainerArithmetic(t *testing.T) {
x := unitPair("meter", 1)
y := unitPair("second", 1)
z := NewUnitsContainer(map[string]float64{"meter": 1, "second": -2})
if !x.Mul(y).Equal(NewUnitsContainer(map[string]float64{"meter": 1, "second": 1})) {
t.Fatal("mul")
}
if !x.Div(y).Equal(NewUnitsContainer(map[string]float64{"meter": 1, "second": -1})) {
t.Fatal("div")
}
if !z.Pow(2).Equal(NewUnitsContainer(map[string]float64{"meter": 2, "second": -4})) {
t.Fatal("pow")
}
}
func TestPreprocessorSquareCube(t *testing.T) {
cases := []struct{ in, want string }{
{"bcd^3", "bcd**3"},
{"bcd squared", "bcd**2"},
{"bcd cubed", "bcd**3"},
{"square bcd", "bcd**2"},
{"cubic bcd", "bcd**3"},
{"miles per hour", "miles/hour"},
{"1,234,567", "1234567"},
{"1hour", "1 hour"},
}
for _, tc := range cases {
got := Preprocess(tc.in)
if got != tc.want {
t.Errorf("Preprocess(%q)=%q want %q", tc.in, got, tc.want)
}
}
}