-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheng_test.go
41 lines (33 loc) · 951 Bytes
/
eng_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
package main
import (
"math"
"testing"
)
func testVal(t *testing.T, n float64, s string) string {
n_string := Eng(n)
if len(n_string) != 12 {
t.Errorf("|%v| %v\n", n_string, n)
}
if s != "" && s != n_string {
t.Logf("<%v>\n", s)
t.Errorf("|%v| %v\n", n_string, n)
}
if !t.Failed() {
t.Logf("«%v» %v\n", n_string, n)
}
return n_string
}
func TestEng(t *testing.T) {
testVal(t, 0.0, " 0.00e+00")
testVal(t, math.MaxInt64, " 9.22e+18")
testVal(t, -math.MaxInt64, " -9.22e+18")
testVal(t, math.MaxInt32, " 2.15e+09")
testVal(t, -math.MaxInt32, " -2.15e+09")
testVal(t, 1.0/math.MaxInt64, " 108.42e-21")
testVal(t, 1.0/math.MaxInt32, " 465.66e-12")
testVal(t, -1.0/math.MaxInt64, " -108.42e-21")
testVal(t, -1.0/math.MaxInt32, " -465.66e-12")
testVal(t, math.MaxFloat64, " 179.77e+306")
testVal(t, -math.MaxFloat64, "-179.77e+306")
testVal(t, math.Sqrt(math.SmallestNonzeroFloat64), " 2.22e-162")
}