Skip to content

Commit

Permalink
Add xor operation to the base standard library
Browse files Browse the repository at this point in the history
Should xor have a corresponding infix operator?
  • Loading branch information
mariari authored and lukaszcz committed Dec 1, 2024
1 parent 1bbc9f8 commit 2db2a01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Stdlib/Data/Bool/Base.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,11 @@ or (a b : Bool) : Bool := a || b;
--- Logical conjunction.
and (a b : Bool) : Bool := a && b;

--- Logical exclusive or.
xor : Bool -> Bool -> Bool
| true true := false
| false flase := false
| _ _ := true;

builtin assert
assert (x : Bool) : Bool := x;
10 changes: 9 additions & 1 deletion test/Test/Prelude.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import Test.JuvixUnit open;
import Stdlib.Prelude open;

tests : List Test :=
[testCase "And" (assertEqual "and works as expected" (and true false) false)];
[
testCase "And" (assertEqual "and works as expected" (and true false) false);
testCase
"Xor"
(assertEqual "and works as expected" (xor true false) (xor false true));
testCase
"Xor-2"
(assertEqual "and works as expected" (xor false false) (xor true true));
];

suite : TestSuite := testSuite "Prelude" tests;

Expand Down

0 comments on commit 2db2a01

Please sign in to comment.