-
Notifications
You must be signed in to change notification settings - Fork 5
/
number.go
61 lines (49 loc) · 1.33 KB
/
number.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
package gohamcrest
type greaterThanMatcher struct {
BaseMatcher
}
func (this *greaterThanMatcher) Match(actual interface{}) bool {
validateParamType(actual,this.Expected)
switch actual.(type) { //多选语句switch
case float64:
return actual.(float64)>this.Expected.(float64)
case float32:
return actual.(float32)>this.Expected.(float32)
case int:
return actual.(int)>this.Expected.(int)
}
return false
}
func GreaterThan(expected interface{}) Matcher {
matcher := &greaterThanMatcher{}
matcher.Expected=expected
matcher.Reason="%v is %s greater than %v(excepted)"
return matcher
}
func LessThanOrEquals(expected interface{}) Matcher {
return Not(GreaterThan(expected))
}
type lessThanMatcher struct {
BaseMatcher
}
func (this *lessThanMatcher) Match(actual interface{}) bool {
validateParamType(actual,this.Expected)
switch actual.(type) { //多选语句switch
case float64:
return actual.(float64)<this.Expected.(float64)
case float32:
return actual.(float32)<this.Expected.(float32)
case int:
return actual.(int)<this.Expected.(int)
}
return false
}
func LessThan(expected interface{}) Matcher {
matcher := &lessThanMatcher{}
matcher.Expected=expected
matcher.Reason="%v is %s less than %v(excepted)"
return matcher
}
func GreaterThanOrEquals(expected interface{}) Matcher {
return Not(LessThan(expected))
}