Various suggestion improvements

This commit is contained in:
Ria Cataquian
2016-05-08 02:59:48 +08:00
parent d931df84cc
commit 65756b933d
5 changed files with 23 additions and 21 deletions

View File

@@ -2,13 +2,13 @@ defmodule Maps do
use Koans use Koans
@person %{ @person %{
name: "Jon", first_name: "Jon",
last_name: "Snow", last_name: "Snow",
age: 27, age: 27,
} }
koan "Maps represent structured data, like a person" do koan "Maps represent structured data, like a person" do
assert @person == %{name: ___, assert @person == %{first_name: ___,
last_name: "Snow", last_name: "Snow",
age: 27 } age: 27 }
end end
@@ -42,7 +42,7 @@ defmodule Maps do
end end
koan "Can merge maps" do koan "Can merge maps" do
assert Map.merge(%{name: "Jon"}, %{last_name: "Snow"}) == ___ assert Map.merge(%{first_name: "Jon"}, %{last_name: "Snow"}) == ___
end end
koan "When merging, the last map wins" do koan "When merging, the last map wins" do
@@ -51,7 +51,7 @@ defmodule Maps do
end end
koan "You can also select sub-maps out of a larger map" do koan "You can also select sub-maps out of a larger map" do
initial = %{name: "Jon", last_name: "Snow", age: 15} initial = %{first_name: "Jon", last_name: "Snow", age: 15}
assert Map.take(initial, [:name, :last_name]) == ___ assert Map.take(initial, [:first_name, :last_name]) == ___
end end
end end

View File

@@ -34,7 +34,7 @@ defmodule Functions do
def sum_up(thing) when is_list(thing), do: :entire_list def sum_up(thing) when is_list(thing), do: :entire_list
def sum_up(_thing), do: :single_thing def sum_up(_thing), do: :single_thing
koan "Functions can be picky and apply only to certain types" do koan "Functions can have guard expressions" do
assert sum_up([1 ,2 ,3]) == ___ assert sum_up([1 ,2 ,3]) == ___
assert sum_up(1) == ___ assert sum_up(1) == ___
end end
@@ -47,12 +47,12 @@ defmodule Functions do
assert bigger(4, 27) == ___ assert bigger(4, 27) == ___
end end
def the_length(0), do: "It was zero" def get_number(0), do: "The number was zero"
def the_length(number), do: "The length was #{number}" def get_number(number), do: "The number was #{number}"
koan "For simpler cases, pattern matching is effective" do koan "For simpler cases, pattern matching is effective" do
assert the_length(0) == ___ assert get_number(0) == ___
assert the_length(5) == ___ assert get_number(5) == ___
end end
koan "Little anonymous functions are common, and called with a dot" do koan "Little anonymous functions are common, and called with a dot" do
@@ -60,7 +60,7 @@ defmodule Functions do
assert multiply.(2,3) == ___ assert multiply.(2,3) == ___
end 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) multiply = &(&1 * &2)
assert multiply.(2,3) == ___ assert multiply.(2,3) == ___
end end
@@ -77,11 +77,11 @@ defmodule Functions do
assert times_five_and_then(2, cube) == ___ assert times_five_and_then(2, cube) == ___
end 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" result = "full-name"
|> String.split("-") |> String.split("-")
|> Enum.map(&(String.capitalize(&1))) |> Enum.map(&(String.capitalize(&1)))
|> Enum.join(" ") |> Enum.join(" ")
assert result == ___ assert result == ___
end end

View File

@@ -22,7 +22,7 @@ defmodule Enums do
end end
koan "Sometimes you just want to know if an element is part of the party" do 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, 1) == ___
assert Enum.member?(input, 30) == ___ assert Enum.member?(input, 30) == ___
end end
@@ -56,7 +56,7 @@ defmodule Enums do
koan "Zip-up in pairs!" do koan "Zip-up in pairs!" do
letters = [:a, :b, :c] letters = [:a, :b, :c]
numbers = [1 ,2 ,3] numbers = [1, 2, 3]
assert Enum.zip(letters, numbers) == ___ assert Enum.zip(letters, numbers) == ___
end end

View File

@@ -81,8 +81,8 @@ defmodule Processes do
koan "Processes can be used to hold state" do koan "Processes can be used to hold state" do
initial_state = "foo" initial_state = "foo"
pid = spawn(fn -> pid = spawn(fn ->
state(initial_state) state(initial_state)
end) end)
send pid, {self, :get} send pid, {self, :get}
assert_receive ___ assert_receive ___
@@ -111,7 +111,7 @@ defmodule Processes do
receive do receive do
{:EXIT, _pid, reason} -> send parent, {:exited, reason} {:EXIT, _pid, reason} -> send parent, {:exited, reason}
end end
end) end)
receive do receive do
:ready -> true :ready -> true

View File

@@ -12,7 +12,7 @@ defmodule Tasks do
assert result == ___ assert result == ___
end 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 -> handle = Task.async(fn ->
:timer.sleep(100) :timer.sleep(100)
3 * 3 3 * 3
@@ -25,8 +25,10 @@ defmodule Tasks do
:timer.sleep(100) :timer.sleep(100)
3 * 3 3 * 3
end) end)
%Task{pid: pid} = handle %Task{pid: pid} = handle
Task.shutdown(handle) Task.shutdown(handle)
assert Process.alive?(pid) == ___ assert Process.alive?(pid) == ___
end end