diff options
| -rw-r--r-- | hamlet.go | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -10,16 +10,20 @@ func (a Assertion) Assert() bool { return a.value } +// New returns a new Assertion. An assertion is true iff its +// underlying value is non-zero in the Go sense. func New(v any) Assertion { return Assertion{!reflect.ValueOf(v).IsZero()} } +// Not computes ~a, given assertion a. func Not(a Assertion) Assertion { negation := !a.value return Assertion{negation} } +// Or computes a v b, given assertions a and b. func Or(a Assertion, b Assertion) Assertion { av := a.value bv := b.value @@ -27,6 +31,7 @@ func Or(a Assertion, b Assertion) Assertion { return Assertion{av || bv} } +// And computes a ^ b, given assertions a and b. func And(a Assertion, b Assertion) Assertion { av := a.value bv := b.value @@ -34,14 +39,17 @@ func And(a Assertion, b Assertion) Assertion { return Assertion{av && bv} } +// If computes a → b, given assertions a and b. func If(a Assertion, b Assertion) Assertion { return Or(Not(a), b) } +// If computes a ↔ b, given assertions a and b. func Iff(a Assertion, b Assertion) Assertion { return And(If(a, b), If(b, a)) } +// Xor computes a ⊻ b, given assertions a and b. func Xor(a Assertion, b Assertion) Assertion { return Not(Iff(a, b)) } |
