Add functional predicate XNOR (#181)

Add new function, Xnor, designed to create a composed predicate representing
the logical Exclusive NOR (XNOR) operation applied to a list of predicates.
The XNOR operation is a logical operation that returns true only
if all operands have the same boolean value
This commit is contained in:
donutloop
2024-02-25 13:24:47 +01:00
committed by GitHub
parent aebab7c944
commit a43bc554ee
3 changed files with 62 additions and 0 deletions

View File

@@ -74,6 +74,21 @@ func TestPredicatesNorPure(t *testing.T) {
assert.ShouldBeFalse(match("0123456789"))
}
func TestPredicatesXnorPure(t *testing.T) {
t.Parallel()
assert := internal.NewAssert(t, "TestPredicatesXnorPure")
isEven := func(i int) bool { return i%2 == 0 }
isPositive := func(i int) bool { return i > 0 }
match := Xnor(isEven, isPositive)
assert.ShouldBeTrue(match(2))
assert.ShouldBeTrue(match(-3))
assert.ShouldBeFalse(match(3))
}
func TestPredicatesMix(t *testing.T) {
t.Parallel()
@@ -95,4 +110,7 @@ func TestPredicatesMix(t *testing.T) {
c = Nor(a, b)
assert.ShouldBeFalse(c("hello!"))
c = Xnor(a, b)
assert.ShouldBeTrue(c("hello!"))
}