Merge pull request #123 from msurekci/add_map_sets_koans

Adding new koans for map sets
This commit is contained in:
Felipe Seré
2016-05-27 19:09:37 +01:00
11 changed files with 94 additions and 0 deletions

70
lib/koans/10_map_sets.ex Normal file
View File

@@ -0,0 +1,70 @@
defmodule MapSets do
use Koans
@intro "My name is Set, MapSet."
@set MapSet.new([1, 2, 3, 4, 5])
koan "I am very similar to a list" do
assert Enum.fetch(@set, 0) == {:ok, ___}
end
koan "However, I do not allow duplication" do
new_set = MapSet.new([1, 1, 2, 3, 3, 3])
assert MapSet.size(new_set) == ___
end
koan "Even though I am like a list I am unordered after 32 elements" do
assert 1..33 |> MapSet.new() |> Enum.fetch(0) == {___, 11}
end
koan "I am merely another collection but, you can perform some operations on me" 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 "Does this value exist in the map set?" do
assert MapSet.member?(@set, 3) == ___
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 "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

@@ -9,6 +9,7 @@ defmodule Runner do
Lists,
KeywordLists,
Maps,
MapSets,
Structs,
PatternMatching,
Functions,

View File

@@ -0,0 +1,23 @@
defmodule MapSetsTest do
use ExUnit.Case
import TestHarness
test "MapSets" do
answers = [
1,
3,
:ok,
{:multiple, [true, false]},
true,
true,
false,
5,
false,
true,
7,
[1, 2, 3, 4, 5],
]
test_all(MapSets, answers)
end
end