-
Notifications
You must be signed in to change notification settings - Fork 192
/
go_test.go
89 lines (79 loc) · 1.96 KB
/
go_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
// Skip these test since they have different results based on the CPU architecture.
//go:build skip
package lua
// Test assumptions about how Go works
import (
"math"
"strconv"
"testing"
"unicode"
)
func TestStringCompare(t *testing.T) {
s1 := "hello\x00world"
s2 := "hello\x00sweet"
if s1 <= s2 {
t.Error("s1 <= s2")
}
}
func TestStringLength(t *testing.T) {
s := "hello\x00world"
if len(s) != 11 {
t.Error("go doesn't count embedded nulls in string length")
}
}
func TestIsControl(t *testing.T) {
t.Skip()
for i := 0; i < 256; i++ {
control := i < 0x20 || i == 0x7f
if lib := unicode.Is(unicode.Cc, rune(i)); control != lib {
t.Errorf("%x: is control? %s", i, strconv.FormatBool(lib))
}
}
}
func TestReslicing(t *testing.T) {
a := [5]int{0, 1, 2, 3, 4}
s := a[:0]
if cap(s) != cap(a) {
t.Error("cap(s) != cap(a)")
}
if len(s) != 0 {
t.Error("len(s) != 0")
}
s = a[1:3]
if cap(s) == len(s) {
t.Error("cap(s) == len(s)")
}
s = s[:cap(s)]
if cap(s) != len(s) {
t.Error("cap(s) != len(s)")
}
}
func TestPow(t *testing.T) {
// if a, b := math.Pow(10.0, 33.0), 1.0e33; a != b {
// t.Errorf("%v != %v\n", a, b)
// }
if a, b := math.Pow10(33), 1.0e33; a != b {
t.Errorf("%v != %v\n", a, b)
}
}
func TestParseFloat(t *testing.T) {
if f, err := strconv.ParseFloat("inf", 64); err != nil {
t.Error("ParseFloat('inf', 64) == ", f, err)
}
}
func TestUnsigned(t *testing.T) {
n := -1.0
const supUnsigned = float64(^uint32(0)) + 1
if x := math.Floor(n / supUnsigned); x != -1.0 {
t.Error("math.Floor(-1/supUnsigned) == ", x)
}
if x := math.Floor(n/supUnsigned) * supUnsigned; x != -4294967296.0 {
t.Error("math.Floor(n/supUnsigned)*supUnsigned == ", x)
}
if x := n - math.Floor(n/supUnsigned)*supUnsigned; x != 4294967295.0 {
t.Error("n-math.Floor(n/supUnsigned)*supUnsigned == ", x)
}
if x := uint(n - math.Floor(n/supUnsigned)*supUnsigned); x != 4294967295 {
t.Error("uint(n-math.Floor(n/supUnsigned)*supUnsigned) == ", x)
}
}