Adding new koans for map sets

This commit is contained in:
Mahmut Surekci
2016-05-26 02:02:20 +01:00
parent 65553d966f
commit 5e9e5e3891
3 changed files with 84 additions and 0 deletions

62
lib/koans/17_map_sets.ex Normal file
View 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

View File

@@ -15,6 +15,7 @@ defmodule Runner do
Processes, Processes,
Tasks, Tasks,
Agents, Agents,
MapSets,
] ]
def koan?(koan), do: Enum.member?(@modules, koan) def koan?(koan), do: Enum.member?(@modules, koan)

View 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