|
| 1 | +import LeanTest |
| 2 | +import CustomSet |
| 3 | + |
| 4 | +open LeanTest |
| 5 | + |
| 6 | +def customSetTests : TestSuite := |
| 7 | + (TestSuite.empty "CustomSet") |
| 8 | + |>.addTest "Returns true if the set contains no elements -> sets with no elements are empty" (do |
| 9 | + return assertEqual ∅ <| CustomSet.Set.ofList []) |
| 10 | + |>.addTest "Returns true if the set contains no elements -> sets with elements are not empty" (do |
| 11 | + return assertNotEqual ∅ <| CustomSet.Set.ofList [1]) |
| 12 | + |>.addTest "Sets can report if they contain an element -> nothing is contained in an empty set" (do |
| 13 | + return assert <| decide <| 1 ∉ CustomSet.Set.ofList []) |
| 14 | + |>.addTest "Sets can report if they contain an element -> when the element is in the set" (do |
| 15 | + return assert <| decide <| 1 ∈ CustomSet.Set.ofList [1, 2, 3]) |
| 16 | + |>.addTest "Sets can report if they contain an element -> when the element is not in the set" (do |
| 17 | + return assert <| decide <| 4 ∉ CustomSet.Set.ofList [1, 2, 3]) |
| 18 | + |>.addTest "A set is a subset if all of its elements are contained in the other set -> empty set is a subset of another empty set" (do |
| 19 | + return assert <| decide <| CustomSet.Set.ofList [] ⊆ CustomSet.Set.ofList []) |
| 20 | + |>.addTest "A set is a subset if all of its elements are contained in the other set -> empty set is a subset of non-empty set" (do |
| 21 | + return assert <| decide <| CustomSet.Set.ofList [] ⊆ CustomSet.Set.ofList [1]) |
| 22 | + |>.addTest "A set is a subset if all of its elements are contained in the other set -> non-empty set is not a subset of empty set" (do |
| 23 | + return assert <| decide <| CustomSet.Set.ofList [1] ⊈ CustomSet.Set.ofList []) |
| 24 | + |>.addTest "A set is a subset if all of its elements are contained in the other set -> set is a subset of set with exact same elements" (do |
| 25 | + return assert <| decide <| CustomSet.Set.ofList [1, 2, 3] ⊆ CustomSet.Set.ofList [1, 2, 3]) |
| 26 | + |>.addTest "A set is a subset if all of its elements are contained in the other set -> set is a subset of larger set with same elements" (do |
| 27 | + return assert <| decide <| CustomSet.Set.ofList [1, 2, 3] ⊆ CustomSet.Set.ofList [4, 1, 2, 3]) |
| 28 | + |>.addTest "A set is a subset if all of its elements are contained in the other set -> set is not a subset of set that does not contain its elements" (do |
| 29 | + return assert <| decide <| CustomSet.Set.ofList [1, 2, 3] ⊈ CustomSet.Set.ofList [4, 1, 3]) |
| 30 | + |>.addTest "Sets are disjoint if they share no elements -> the empty set is disjoint with itself" (do |
| 31 | + return assertTrue <| (CustomSet.Set.ofList []).disjoint <| CustomSet.Set.ofList []) |
| 32 | + |>.addTest "Sets are disjoint if they share no elements -> empty set is disjoint with non-empty set" (do |
| 33 | + return assertTrue <| (CustomSet.Set.ofList []).disjoint <| CustomSet.Set.ofList [1]) |
| 34 | + |>.addTest "Sets are disjoint if they share no elements -> non-empty set is disjoint with empty set" (do |
| 35 | + return assertTrue <| (CustomSet.Set.ofList [1]).disjoint <| CustomSet.Set.ofList []) |
| 36 | + |>.addTest "Sets are disjoint if they share no elements -> sets are not disjoint if they share an element" (do |
| 37 | + return assertFalse <| (CustomSet.Set.ofList [1, 2]).disjoint <| CustomSet.Set.ofList [2, 3]) |
| 38 | + |>.addTest "Sets are disjoint if they share no elements -> sets are disjoint if they share no elements" (do |
| 39 | + return assertTrue <| (CustomSet.Set.ofList [1, 2]).disjoint <| CustomSet.Set.ofList [3, 4]) |
| 40 | + |>.addTest "Sets with the same elements are equal -> empty sets are equal" (do |
| 41 | + return assert <| CustomSet.Set.ofList [] == CustomSet.Set.ofList []) |
| 42 | + |>.addTest "Sets with the same elements are equal -> empty set is not equal to non-empty set" (do |
| 43 | + return assert <| CustomSet.Set.ofList [] != CustomSet.Set.ofList [1, 2, 3]) |
| 44 | + |>.addTest "Sets with the same elements are equal -> non-empty set is not equal to empty set" (do |
| 45 | + return assert <| CustomSet.Set.ofList [1, 2, 3] != CustomSet.Set.ofList []) |
| 46 | + |>.addTest "Sets with the same elements are equal -> sets with the same elements are equal" (do |
| 47 | + return assert <| CustomSet.Set.ofList [1, 2] == CustomSet.Set.ofList [2, 1]) |
| 48 | + |>.addTest "Sets with the same elements are equal -> sets with different elements are not equal" (do |
| 49 | + return assert <| CustomSet.Set.ofList [1, 2, 3] != CustomSet.Set.ofList [1, 2, 4]) |
| 50 | + |>.addTest "Sets with the same elements are equal -> set is not equal to larger set with same elements" (do |
| 51 | + return assert <| CustomSet.Set.ofList [1, 2, 3] != CustomSet.Set.ofList [1, 2, 3, 4]) |
| 52 | + |>.addTest "Sets with the same elements are equal -> set is equal to a set constructed from an array with duplicates" (do |
| 53 | + return assert <| CustomSet.Set.ofList [1] == CustomSet.Set.ofList [1, 1]) |
| 54 | + |>.addTest "Unique elements can be added to a set -> add to empty set" (do |
| 55 | + return assertEqual (CustomSet.Set.ofList [3]) <| (CustomSet.Set.ofList []).add 3) |
| 56 | + |>.addTest "Unique elements can be added to a set -> add to non-empty set" (do |
| 57 | + return assertEqual (CustomSet.Set.ofList [1, 2, 3, 4]) <| (CustomSet.Set.ofList [1, 2, 4]).add 3) |
| 58 | + |>.addTest "Unique elements can be added to a set -> adding an existing element does not change the set" (do |
| 59 | + return assertEqual (CustomSet.Set.ofList [1, 2, 3]) <| (CustomSet.Set.ofList [1, 2, 3]).add 3) |
| 60 | + |>.addTest "Intersection returns a set of all shared elements -> intersection of two empty sets is an empty set" (do |
| 61 | + return assertEqual (CustomSet.Set.ofList []) <| CustomSet.Set.ofList [] ∩ CustomSet.Set.ofList []) |
| 62 | + |>.addTest "Intersection returns a set of all shared elements -> intersection of an empty set and non-empty set is an empty set" (do |
| 63 | + return assertEqual (CustomSet.Set.ofList []) <| CustomSet.Set.ofList [] ∩ CustomSet.Set.ofList [3, 2, 5]) |
| 64 | + |>.addTest "Intersection returns a set of all shared elements -> intersection of a non-empty set and an empty set is an empty set" (do |
| 65 | + return assertEqual (CustomSet.Set.ofList []) <| CustomSet.Set.ofList [1, 2, 3, 4] ∩ CustomSet.Set.ofList []) |
| 66 | + |>.addTest "Intersection returns a set of all shared elements -> intersection of two sets with no shared elements is an empty set" (do |
| 67 | + return assertEqual (CustomSet.Set.ofList []) <| CustomSet.Set.ofList [1, 2, 3] ∩ CustomSet.Set.ofList [4, 5, 6]) |
| 68 | + |>.addTest "Intersection returns a set of all shared elements -> intersection of two sets with shared elements is a set of the shared elements" (do |
| 69 | + return assertEqual (CustomSet.Set.ofList [2, 3]) <| CustomSet.Set.ofList [1, 2, 3, 4] ∩ CustomSet.Set.ofList [3, 2, 5]) |
| 70 | + |>.addTest "Difference (or Complement) of a set is a set of all elements that are only in the first set -> difference of two empty sets is an empty set" (do |
| 71 | + return assertEqual (CustomSet.Set.ofList []) <| CustomSet.Set.ofList [] \ CustomSet.Set.ofList []) |
| 72 | + |>.addTest "Difference (or Complement) of a set is a set of all elements that are only in the first set -> difference of empty set and non-empty set is an empty set" (do |
| 73 | + return assertEqual (CustomSet.Set.ofList []) <| CustomSet.Set.ofList [] \ CustomSet.Set.ofList [3, 2, 5]) |
| 74 | + |>.addTest "Difference (or Complement) of a set is a set of all elements that are only in the first set -> difference of a non-empty set and an empty set is the non-empty set" (do |
| 75 | + return assertEqual (CustomSet.Set.ofList [1, 2, 3, 4]) <| CustomSet.Set.ofList [1, 2, 3, 4] \ CustomSet.Set.ofList []) |
| 76 | + |>.addTest "Difference (or Complement) of a set is a set of all elements that are only in the first set -> difference of two non-empty sets is a set of elements that are only in the first set" (do |
| 77 | + return assertEqual (CustomSet.Set.ofList [1, 3]) <| CustomSet.Set.ofList [3, 2, 1] \ CustomSet.Set.ofList [2, 4]) |
| 78 | + |>.addTest "Difference (or Complement) of a set is a set of all elements that are only in the first set -> difference removes all duplicates in the first set" (do |
| 79 | + return assertEqual (CustomSet.Set.ofList []) <| CustomSet.Set.ofList [1, 1] \ CustomSet.Set.ofList [1]) |
| 80 | + |>.addTest "Union returns a set of all elements in either set -> union of empty sets is an empty set" (do |
| 81 | + return assertEqual (CustomSet.Set.ofList []) <| CustomSet.Set.ofList [] ∪ CustomSet.Set.ofList []) |
| 82 | + |>.addTest "Union returns a set of all elements in either set -> union of an empty set and non-empty set is the non-empty set" (do |
| 83 | + return assertEqual (CustomSet.Set.ofList [2]) <| CustomSet.Set.ofList [] ∪ CustomSet.Set.ofList [2]) |
| 84 | + |>.addTest "Union returns a set of all elements in either set -> union of a non-empty set and empty set is the non-empty set" (do |
| 85 | + return assertEqual (CustomSet.Set.ofList [1, 3]) <| CustomSet.Set.ofList [1, 3] ∪ CustomSet.Set.ofList []) |
| 86 | + |>.addTest "Union returns a set of all elements in either set -> union of non-empty sets contains all unique elements" (do |
| 87 | + return assertEqual (CustomSet.Set.ofList [3, 2, 1]) <| CustomSet.Set.ofList [1, 3] ∪ CustomSet.Set.ofList [2, 3]) |
| 88 | + |
| 89 | +def main : IO UInt32 := do |
| 90 | + runTestSuitesWithExitCode [customSetTests] |
0 commit comments