-
-
Save aaronlifton3/5e497840c801e9a4f69e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // a ∨ (b ∨ c) = (a ∨ b) ∨ c, a ∧ (b ∧ c) = (a ∧ b) ∧ c associativity | |
| // a ∨ b = b ∨ a, a ∧ b = b ∧ a commutativity | |
| // a ∨ (a ∧ b) = a, a ∧ (a ∨ b) = a absorption | |
| // a ∨ 0 = a, a ∧ 1 = a identity | |
| // a ∨ (b ∧ c) = (a ∨ b) ∧ (a ∨ c), a ∧ (b ∨ c) = (a ∧ b) ∨ (a ∧ c) distributivity | |
| // a ∨ ¬a = 1, a ∧ ¬a = 0 complements | |
| class AlgebraPoliceman[A : BooleanAlgebra : Arbitrary : Eq]() extends Properties("BooleanAlgebra") { | |
| def zero = implicitly[BooleanAlgebra[A]].zero | |
| def one = implicitly[BooleanAlgebra[A]].one | |
| property("associative law (||)") = forAll((a: A, b: A, c: A) => (a || (b || c)) === ((a || b) || c)) | |
| property("associative law (&&)") = forAll((a: A, b: A, c: A) => (a && (b && c)) === ((a && b) && c)) | |
| property("distributive law (||)") = forAll((a: A, b: A, c: A) => (a || (b && c)) === ((a || b) && (a || c))) | |
| property("distributive law (&&)") = forAll((a: A, b: A, c: A) => (a && (b || c)) === ((a && b) || (a && c))) | |
| property("commutative law") = forAll((a: A, b: A) => ((a || b) === (b || a)) && ((a && b) === (b && a))) | |
| property("absorption law") = forAll((a: A, b: A) => ((a || (a && b)) === a) && (a && (a || b)) === a) | |
| property("identity law") = forAll((a: A) => ((a || zero) === a) && ((a && one) === a)) | |
| property("complement law") = forAll((a: A) => ((a || !a) === one) && ((a && !a) === zero)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment