-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathop.go
53 lines (44 loc) · 851 Bytes
/
op.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
package comver
const (
greaterThanOrEqualTo op = iota
greaterThan
lessThan
lessThanOrEqualTo
errUnexpectedOp stringError = "unexpected op"
)
type op int8
func (o op) String() string {
switch o {
case lessThanOrEqualTo:
return "<="
case lessThan:
return "<"
case greaterThan:
return ">"
case greaterThanOrEqualTo:
return ">="
default:
// logic error! This should never happen
panic(errUnexpectedOp)
}
}
func (o op) compare(other op) int {
i := int(o) - int(other)
switch {
case i < 0:
return -1
case i > 0:
return 1
default:
return 0
}
}
func (o op) ceilingBounded() bool {
return o == lessThan || o == lessThanOrEqualTo
}
func (o op) floorBounded() bool {
return o == greaterThan || o == greaterThanOrEqualTo
}
func (o op) inclusive() bool {
return o == lessThanOrEqualTo || o == greaterThanOrEqualTo
}