diff options
| author | demo <demo@antix1> | 2026-05-30 22:51:24 -0400 |
|---|---|---|
| committer | demo <demo@antix1> | 2026-05-30 22:51:24 -0400 |
| commit | 1d90d466a8f6f23c4cedcfc97438fc10bbd80d3e (patch) | |
| tree | 8f24dfdd2999e873736f1768895557ffad83623f | |
| parent | dd68cfd62603fa728b9707d7f37de092436d94ab (diff) | |
feat: use Present/Absent instead of New
| -rw-r--r-- | hamlet.go | 22 | ||||
| -rw-r--r-- | hamlet_test.go | 4 |
2 files changed, 14 insertions, 12 deletions
@@ -3,38 +3,40 @@ package hamlet import "reflect" type Assertion struct { - value bool + truth bool } func (a Assertion) Assert() bool { - return a.value + return a.truth } -// 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 { +func Present(v any) Assertion { return Assertion{!reflect.ValueOf(v).IsZero()} } +func Absent(v any) Assertion { + return Assertion{reflect.ValueOf(v).IsZero()} +} + // Not computes ~a, given assertion a. func Not(a Assertion) Assertion { - negation := !a.value + negation := !a.truth 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 + av := a.truth + bv := b.truth 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 + av := a.truth + bv := b.truth return Assertion{av && bv} } diff --git a/hamlet_test.go b/hamlet_test.go index ca69425..bbd50fe 100644 --- a/hamlet_test.go +++ b/hamlet_test.go @@ -5,8 +5,8 @@ import ( ) func TestAssertion(t *testing.T) { - p := New("") - q := New(4) + p := Present("") + q := Present(4) theorem1 := If(p, q) if !theorem1.Assert() { |
