-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasserts.go
116 lines (100 loc) · 3.3 KB
/
asserts.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
108
109
110
111
112
113
114
115
116
package asserts
import (
"fmt"
"testing"
)
// Test a string value matches another string
func Equals (t *testing.T, name string , got string, expected string ) {
if got != expected {
t.Errorf("Failed %s\ngot\n%s\n\nexpected\n%s\n\n", name, got, expected )
t.FailNow()
}
}
// Test a string value does not match another string
func NotEquals (t *testing.T, name string , got string, expected string ) {
if got == expected {
t.Errorf("Failed %s\ngot\n%s\n\nexpected something different\n%s\n\n", name, got, expected )
t.FailNow()
}
}
// Test an int value
func IntEquals (t *testing.T, name string , got int, expected int ) {
if got != expected {
fmt.Printf("in IntEquals with failure for test %v, got %v, expected %v\n", name, got ,expected)
t.Errorf("Faild %s\ngot\n%d\n\nexpected\n%d\n\n", name, got, expected )
//t.FailNow()
}
}
// Test a float64 value
func Float64Equals (t *testing.T, name string , got float64, expected float64 ) {
if got != expected {
t.Errorf("Failed %s\ngot\n%v\n\nexpected\n%v\n\n", name, got, expected )
t.FailNow()
}
}
// Given a value, test that it falls inclusively within (>=) start and (<=) end. This is the opposite of Outside
func Bounded( t *testing.T, name string, value ,start, end interface{}) {
valueI := value.(int64) / 1
startI := start.(int64) / 1
endI := end.(int64) / 1
if startI > endI {
tmp := endI
endI = startI
startI = tmp
}
if valueI < startI || valueI > endI {
t.Errorf("Failed %s\n%v is out of bounds(%v,%v)\n\n", name, value, start, end)
t.FailNow()
}
}
// Given a value, test that it falls exclusively outside of the interval >= start and <= end. This is the opposite of Bounded.
func Outside( t *testing.T, name string, value ,start, end interface{}) {
valueI := value.(int64) / 1
startI := start.(int64) / 1
endI := end.(int64) / 1
if startI > endI {
tmp := endI
endI = startI
startI = tmp
}
if valueI >= startI || valueI <= endI {
t.Errorf("Failed %s\n%v is within bounds(%v,%v)\n\n", name, value, start, end)
t.FailNow()
}
}
// Test that a value is true. Synonym of Ok and Is
func True (t *testing.T, name string , got bool ) {
if !got {
t.Errorf("Failed %s\ngot\n%s\n\nexpected\n%s\n\n", name, got, true)
t.FailNow()
}
}
// Test that a value is true. Synonym of True and Is
var Ok func (*testing.T, string , bool ) = True
// Test that a value is true. Synonym of True and Ok
var Is func (*testing.T, string , bool ) = True
// Test that a value is false. Synonym of NotOk and Isnt
func False (t *testing.T, name string , got bool ) {
if got {
t.Errorf("Failed %s\ngot\n%s\n\nexpected\n%s\n\n", name, got, false)
t.FailNow()
}
}
// Test that a value is false. Synonyms with False and Isnt
var NotOk func (*testing.T, string , bool ) = False
// Test that a value is false. Synonyms with False and NotOk
var Isnt func (*testing.T, string , bool ) = False
// Test that a value is nil.
func Nil (t *testing.T, name string , got ...interface{}) {
if got == nil {
t.Errorf("Failed %s\ngot\n%s\n\nexpected\n%s\n\n", name, got, nil)
t.FailNow()
}
}
// Test that a value is not nil.
func NotNil (t *testing.T, name string , got ...interface{}) {
if got != nil {
t.Errorf("Failed %s\ngot\n%s\n\nexpected\n(not nil)\n\n", name, got)
t.FailNow()
}
}