forked from pion/mediadevices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bool.go
37 lines (29 loc) · 790 Bytes
/
bool.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
package prop
import "fmt"
// BoolConstraint is an interface to represent bool value constraint.
type BoolConstraint interface {
Compare(bool) (float64, bool)
Value() bool
}
// BoolExact specifies exact bool value.
type BoolExact bool
// Compare implements BoolConstraint.
func (b BoolExact) Compare(o bool) (float64, bool) {
if bool(b) == o {
return 0.0, true
}
return 1.0, false
}
// Value implements BoolConstraint.
func (b BoolExact) Value() bool { return bool(b) }
// String implements Stringify
func (b BoolExact) String() string {
return fmt.Sprintf("%t (exact)", b)
}
// Bool specifies ideal bool value.
type Bool BoolExact
// Compare implements BoolConstraint.
func (b Bool) Compare(o bool) (float64, bool) {
dist, _ := BoolExact(b).Compare(o)
return dist, true
}