Merge pull request #114 from riacataquian/suggestions
Improvements suggestions
This commit is contained in:
@@ -2,13 +2,13 @@ defmodule Maps do
|
||||
use Koans
|
||||
|
||||
@person %{
|
||||
name: "Jon",
|
||||
first_name: "Jon",
|
||||
last_name: "Snow",
|
||||
age: 27,
|
||||
}
|
||||
|
||||
koan "Maps represent structured data, like a person" do
|
||||
assert @person == %{name: ___,
|
||||
assert @person == %{first_name: ___,
|
||||
last_name: "Snow",
|
||||
age: 27 }
|
||||
end
|
||||
@@ -42,7 +42,7 @@ defmodule Maps do
|
||||
end
|
||||
|
||||
koan "Can merge maps" do
|
||||
assert Map.merge(%{name: "Jon"}, %{last_name: "Snow"}) == ___
|
||||
assert Map.merge(%{first_name: "Jon"}, %{last_name: "Snow"}) == ___
|
||||
end
|
||||
|
||||
koan "When merging, the last map wins" do
|
||||
@@ -51,7 +51,7 @@ defmodule Maps do
|
||||
end
|
||||
|
||||
koan "You can also select sub-maps out of a larger map" do
|
||||
initial = %{name: "Jon", last_name: "Snow", age: 15}
|
||||
assert Map.take(initial, [:name, :last_name]) == ___
|
||||
initial = %{first_name: "Jon", last_name: "Snow", age: 15}
|
||||
assert Map.take(initial, [:first_name, :last_name]) == ___
|
||||
end
|
||||
end
|
||||
|
@@ -16,7 +16,7 @@ defmodule PatternMatching do
|
||||
assert a == ___
|
||||
end
|
||||
|
||||
koan "A variable can be pinned to be prevent it from being rebound" do
|
||||
koan "A variable can be pinned to prevent it from being rebounded" do
|
||||
a = 1
|
||||
assert_raise MatchError, fn() ->
|
||||
^a = ___
|
||||
|
@@ -34,8 +34,8 @@ defmodule Functions do
|
||||
def sum_up(thing) when is_list(thing), do: :entire_list
|
||||
def sum_up(_thing), do: :single_thing
|
||||
|
||||
koan "Functions can be picky and apply only to certain types" do
|
||||
assert sum_up([1 ,2 ,3]) == ___
|
||||
koan "Functions can have guard expressions" do
|
||||
assert sum_up([1, 2, 3]) == ___
|
||||
assert sum_up(1) == ___
|
||||
end
|
||||
|
||||
@@ -47,12 +47,12 @@ defmodule Functions do
|
||||
assert bigger(4, 27) == ___
|
||||
end
|
||||
|
||||
def the_length(0), do: "It was zero"
|
||||
def the_length(number), do: "The length was #{number}"
|
||||
def get_number(0), do: "The number was zero"
|
||||
def get_number(number), do: "The number was #{number}"
|
||||
|
||||
koan "For simpler cases, pattern matching is effective" do
|
||||
assert the_length(0) == ___
|
||||
assert the_length(5) == ___
|
||||
assert get_number(0) == ___
|
||||
assert get_number(5) == ___
|
||||
end
|
||||
|
||||
koan "Little anonymous functions are common, and called with a dot" do
|
||||
@@ -60,7 +60,7 @@ defmodule Functions do
|
||||
assert multiply.(2,3) == ___
|
||||
end
|
||||
|
||||
koan "You can even go shorter, by using &(..) and positional arguments" do
|
||||
koan "You can even go shorter, by using capture syntax `&()` and positional arguments" do
|
||||
multiply = &(&1 * &2)
|
||||
assert multiply.(2,3) == ___
|
||||
end
|
||||
@@ -77,11 +77,11 @@ defmodule Functions do
|
||||
assert times_five_and_then(2, cube) == ___
|
||||
end
|
||||
|
||||
koan "The result of a function can be piped into the first argument of another function" do
|
||||
koan "The result of a function can be piped into another function as its first argument" do
|
||||
result = "full-name"
|
||||
|> String.split("-")
|
||||
|> Enum.map(&(String.capitalize(&1)))
|
||||
|> Enum.join(" ")
|
||||
|> String.split("-")
|
||||
|> Enum.map(&(String.capitalize(&1)))
|
||||
|> Enum.join(" ")
|
||||
|
||||
assert result == ___
|
||||
end
|
||||
|
@@ -22,7 +22,7 @@ defmodule Enums do
|
||||
end
|
||||
|
||||
koan "Sometimes you just want to know if an element is part of the party" do
|
||||
input = [1 ,2 ,3]
|
||||
input = [1, 2, 3]
|
||||
assert Enum.member?(input, 1) == ___
|
||||
assert Enum.member?(input, 30) == ___
|
||||
end
|
||||
@@ -56,7 +56,7 @@ defmodule Enums do
|
||||
|
||||
koan "Zip-up in pairs!" do
|
||||
letters = [:a, :b, :c]
|
||||
numbers = [1 ,2 ,3]
|
||||
numbers = [1, 2, 3]
|
||||
assert Enum.zip(letters, numbers) == ___
|
||||
end
|
||||
|
||||
|
@@ -111,7 +111,7 @@ defmodule Processes do
|
||||
receive do
|
||||
{:EXIT, _pid, reason} -> send parent, {:exited, reason}
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
receive do
|
||||
:ready -> true
|
||||
|
@@ -12,7 +12,7 @@ defmodule Tasks do
|
||||
assert result == ___
|
||||
end
|
||||
|
||||
koan "Yield returns nothing if the task isn't done yet" do
|
||||
koan "Yield returns nil if the task isn't done yet" do
|
||||
handle = Task.async(fn ->
|
||||
:timer.sleep(100)
|
||||
3 * 3
|
||||
@@ -25,8 +25,10 @@ defmodule Tasks do
|
||||
:timer.sleep(100)
|
||||
3 * 3
|
||||
end)
|
||||
|
||||
%Task{pid: pid} = handle
|
||||
Task.shutdown(handle)
|
||||
|
||||
assert Process.alive?(pid) == ___
|
||||
end
|
||||
|
||||
|
@@ -10,7 +10,7 @@ defmodule FunctionsTests do
|
||||
{:multiple, ["Hello Hello Hello Hello Hello ","Hello Hello "]},
|
||||
{:multiple, [:entire_list, :single_thing]},
|
||||
{:multiple, ["10 is bigger than 5", "4 is not bigger than 27"]},
|
||||
{:multiple, ["It was zero", "The length was 5"]},
|
||||
{:multiple, ["The number was zero", "The number was 5"]},
|
||||
6,
|
||||
6,
|
||||
100,
|
||||
|
@@ -11,9 +11,9 @@ defmodule MapsTests do
|
||||
{:ok, 37},
|
||||
{:ok, 16},
|
||||
false,
|
||||
%{:name => "Jon", :last_name => "Snow"},
|
||||
%{:first_name => "Jon", :last_name => "Snow"},
|
||||
{:ok, "Baratheon"},
|
||||
%{ :name => "Jon", :last_name => "Snow"},
|
||||
%{:first_name => "Jon", :last_name => "Snow"},
|
||||
]
|
||||
|
||||
test_all(Maps, answers)
|
||||
|
Reference in New Issue
Block a user