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
@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

View File

@@ -34,7 +34,7 @@ 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
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

View File

@@ -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

View File

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

View File

@@ -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