Adding new koans for map sets
This commit is contained in:
62
lib/koans/17_map_sets.ex
Normal file
62
lib/koans/17_map_sets.ex
Normal file
@@ -0,0 +1,62 @@
|
||||
defmodule MapSets do
|
||||
use Koans
|
||||
|
||||
@intro "Map sets"
|
||||
|
||||
@set MapSet.new([1, 2, 3, 4, 5])
|
||||
|
||||
koan "Does this value exist in the map set?" do
|
||||
assert MapSet.member?(@set, 3) == ___
|
||||
end
|
||||
|
||||
koan "Multiply everything by 3 in my set" do
|
||||
new_set = MapSet.new(@set, fn x -> 3 * x end)
|
||||
|
||||
assert MapSet.member?(new_set, 15) == ___
|
||||
assert MapSet.member?(new_set, 1) == ___
|
||||
end
|
||||
|
||||
koan "Add this value into a map set" do
|
||||
modified_set = MapSet.put(@set, 6)
|
||||
|
||||
assert MapSet.member?(modified_set, 6) == ___
|
||||
end
|
||||
|
||||
koan "Delete this value from the map set" do
|
||||
modified_set = MapSet.delete(@set, 1)
|
||||
|
||||
assert MapSet.member?(modified_set, 1) == ___
|
||||
end
|
||||
|
||||
koan "How large is my map set?" do
|
||||
assert MapSet.size(@set) == ___
|
||||
end
|
||||
|
||||
koan "Are these maps twins?" do
|
||||
new_set = MapSet.new([1, 2, 3])
|
||||
|
||||
assert MapSet.equal?(@set, new_set) == ___
|
||||
end
|
||||
|
||||
koan "I want only the common values in both sets" do
|
||||
intersection_set = MapSet.intersection(@set, MapSet.new([5, 6, 7]))
|
||||
|
||||
assert MapSet.member?(intersection_set, 5) == ___
|
||||
end
|
||||
|
||||
koan "Duplication is a no-no" do
|
||||
new_set = MapSet.new([1, 1, 2, 3, 3])
|
||||
|
||||
assert MapSet.size(new_set) == ___
|
||||
end
|
||||
|
||||
koan "Unify my sets" do
|
||||
new_set = MapSet.union(@set, MapSet.new([1, 5, 6, 7]))
|
||||
|
||||
assert MapSet.size(new_set) == ___
|
||||
end
|
||||
|
||||
koan "I want my set in a list" do
|
||||
assert MapSet.to_list(@set) == ___
|
||||
end
|
||||
end
|
@@ -15,6 +15,7 @@ defmodule Runner do
|
||||
Processes,
|
||||
Tasks,
|
||||
Agents,
|
||||
MapSets,
|
||||
]
|
||||
|
||||
def koan?(koan), do: Enum.member?(@modules, koan)
|
||||
|
21
test/koans/map_sets_koans_test.exs
Normal file
21
test/koans/map_sets_koans_test.exs
Normal file
@@ -0,0 +1,21 @@
|
||||
defmodule MapSetsTest do
|
||||
use ExUnit.Case
|
||||
import TestHarness
|
||||
|
||||
test "MapSets" do
|
||||
answers = [
|
||||
true,
|
||||
{:multiple, [true, false]},
|
||||
true,
|
||||
false,
|
||||
5,
|
||||
false,
|
||||
true,
|
||||
3,
|
||||
7,
|
||||
[1, 2, 3, 4, 5],
|
||||
]
|
||||
|
||||
test_all(MapSets, answers)
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user