allergies/allergies_test.exs
77: set = Enum.into(list, HashSet.new)
79: |> Enum.into(HashSet.new)
80: |> Set.equal?(set)
82: "Expected a set with: #{inspect to_contain} got #{inspect set |> Set.to_list}"
custom-set/custom_set.exs
1:defmodule CustomSet do
2: # This lets the compiler check that all Set callback functions have been
4: @behaviour Set
custom-set/custom_set_test.exs
10:defmodule CustomSetTest do
13: # Tip: to make your set work with the Set module be sure that your set value
14: # is a tuple with as first element `CustomSet`. A record with tag `CustomSet`
19: assert Set.equal?(Set.delete(CustomSet.new([3,2,1]), 2), CustomSet.new([1,3]))
20: assert Set.equal?(Set.delete(CustomSet.new([3,2,1]), 4), CustomSet.new([1,2,3]))
21: assert Set.equal?(Set.delete(CustomSet.new([3,2,1]), 2.0), CustomSet.new([1,2,3]))
26: assert Set.equal?(
27: Set.difference(CustomSet.new([1,2,3]), CustomSet.new([2,4])),
28: CustomSet.new([1,3]))
29: assert Set.equal?(
30: Set.difference(CustomSet.new([1,2.0,3]), CustomSet.new([2,4])),
31: CustomSet.new([1,2.0,3]))
36: assert Set.disjoint?(CustomSet.new([1,2]), CustomSet.new([3,4]))
37: refute Set.disjoint?(CustomSet.new([1,2]), CustomSet.new([2,3]))
38: assert Set.disjoint?(CustomSet.new([1.0,2.0]), CustomSet.new([2,3]))
39: assert Set.disjoint?(CustomSet.new, CustomSet.new)
44: assert Set.equal?(Set.empty(CustomSet.new([1,2])), CustomSet.new)
45: assert Set.equal?(Set.empty(CustomSet.new), CustomSet.new)
50: assert Set.equal?(
51: Set.intersection(CustomSet.new([:a, :b, :c]), CustomSet.new([:a, :c, :d])),
52: CustomSet.new([:a, :c]))
53: assert Set.equal?(
54: Set.intersection(CustomSet.new([1, 2, 3]), CustomSet.new([1.0, 2.0, 3])),
55: CustomSet.new([3]))
60: assert Set.member?(CustomSet.new([1,2,3]), 2)
61: assert Set.member?(CustomSet.new(1..3), 2)
62: refute Set.member?(CustomSet.new(1..3), 2.0)
63: refute Set.member?(CustomSet.new(1..3), 4)
68: assert Set.equal?(
69: Set.put(CustomSet.new([1,2,4]), 3),
70: CustomSet.new([1,2,3,4]))
71: assert Set.equal?(
72: Set.put(CustomSet.new([1,2,3]), 3),
73: CustomSet.new([1,2,3]))
74: assert Set.equal?(
75: Set.put(CustomSet.new([1,2,3]), 3.0),
76: CustomSet.new([1,2,3,3.0]))
81: assert Set.size(CustomSet.new) == 0
82: assert Set.size(CustomSet.new([1,2,3])) == 3
83: assert Set.size(CustomSet.new([1,2,3,2])) == 3
88: assert Set.subset?(CustomSet.new([1,2,3]), CustomSet.new([1,2,3]))
89: assert Set.subset?(CustomSet.new([1,2,3]), CustomSet.new([4,1,2,3]))
90: refute Set.subset?(CustomSet.new([1,2,3]), CustomSet.new([4,1,3]))
91: refute Set.subset?(CustomSet.new([1,2,3.0]), CustomSet.new([1,2,3,4]))
92: assert Set.subset?(CustomSet.new, CustomSet.new([4,1,3]))
93: assert Set.subset?(CustomSet.new, CustomSet.new)
98: assert Enum.sort(Set.to_list(CustomSet.new)) == []
99: assert Enum.sort(Set.to_list(CustomSet.new([3,1,2]))) == [1,2,3]
100: assert Enum.sort(Set.to_list(CustomSet.new([3,1,2,1]))) == [1,2,3]
105: assert Set.equal?(
106: CustomSet.union(CustomSet.new([1,3]), CustomSet.new([2])),
107: CustomSet.new([3,2,1]))
108: assert Set.equal?(
109: CustomSet.union(CustomSet.new([1,3]), CustomSet.new([2,3.0])),
110: CustomSet.new([3.0,3,2,1]))
111: assert Set.equal?(
112: CustomSet.union(CustomSet.new([1,3]), CustomSet.new),
113: CustomSet.new([3,1]))
114: assert Set.equal?(
115: CustomSet.union(CustomSet.new, CustomSet.new([2])),
116: CustomSet.new([2]))
117: assert Set.equal?(
118: CustomSet.union(CustomSet.new, CustomSet.new),
119: CustomSet.new([]))
124: assert inspect(CustomSet.new) == "%CustomSet{list: []}"
125: assert inspect(CustomSet.new([1,3,2])) == "%CustomSet{list: [1, 2, 3]}"
128: assert inspect(CustomSet.new(["A",:b,?C])) == "%CustomSet{list: [67, :b, \"A\"]}"
Per https://github.com/elixir-lang/elixir/blob/v1.2.0/CHANGELOG.md