Add functional predicate NAND (#182)

Add new function, NAND, designed to create a composed predicate representing the logical NAND operation
applied to a list of predicates. The NAND operation is a logical operation
that returns true only if all perdicate result in false otherwise false
This commit is contained in:
donutloop authored and GitHub committed 2024-02-26 09:58:19 +08:00
1 parent a43bc554ee
commit 805e2543d0
3 files changed
+54 -4

No files matched your search

+22 -4
View File
@@ -54,6 +54,21 @@ func TestPredicatesAndPure(t *testing.T) {
assert.ShouldBeFalse(isNumericAndLength5("abcde"))
}
func TestPredicatesNandPure(t *testing.T) {
t.Parallel()
assert := internal.NewAssert(t, "TestPredicatesNandPure")
isNumericAndLength5 := Nand(
func(s string) bool { return strings.ContainsAny(s, "0123456789") },
func(s string) bool { return len(s) == 5 },
)
assert.ShouldBeFalse(isNumericAndLength5("12345"))
assert.ShouldBeFalse(isNumericAndLength5("1234"))
assert.ShouldBeTrue(isNumericAndLength5("abcdef"))
}
func TestPredicatesNorPure(t *testing.T) {
t.Parallel()
@@ -108,9 +123,12 @@ func TestPredicatesMix(t *testing.T) {
assert.ShouldBeFalse(c("hello!"))
c = Nor(a, b)
assert.ShouldBeFalse(c("hello!"))
k := Nor(a, b)
assert.ShouldBeFalse(k("hello!"))
c = Xnor(a, b)
assert.ShouldBeTrue(c("hello!"))
o := Xnor(a, b)
assert.ShouldBeTrue(o("hello!"))
p := Nand(c, k)
assert.ShouldBeTrue(p("hello!"))
}