mirror of
https://github.com/duke-git/lancet.git
synced 2025-10-07 16:30:59 +08:00
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:
@@ -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!"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user