Merge pull request #215 from elixirkoans/minor-koan-rearrangement
Minor koan rearrangement
This commit is contained in:
@@ -31,17 +31,4 @@ defmodule KeywordLists do
|
||||
|
||||
assert_raise ArgumentError, fn -> not_kw_list[___] end
|
||||
end
|
||||
|
||||
koan "Conveniently keyword lists can be used for function options" do
|
||||
transform = fn str, opts ->
|
||||
if opts[:upcase] do
|
||||
String.upcase(str)
|
||||
else
|
||||
str
|
||||
end
|
||||
end
|
||||
|
||||
assert transform.("good", upcase: true) == ___
|
||||
assert transform.("good", upcase: false) == ___
|
||||
end
|
||||
end
|
||||
|
@@ -28,24 +28,16 @@ defmodule Structs do
|
||||
assert older.age == ___
|
||||
end
|
||||
|
||||
defmodule Plane do
|
||||
defstruct passengers: 0, maker: :boeing
|
||||
end
|
||||
|
||||
def plane?(%Plane{}), do: true
|
||||
def plane?(_), do: false
|
||||
|
||||
koan "Or onto the type of the struct itself" do
|
||||
assert plane?(%Plane{passengers: 417, maker: :boeing}) == ___
|
||||
assert plane?(%Person{}) == ___
|
||||
end
|
||||
|
||||
koan "Struct can be treated like maps" do
|
||||
silvia = %Person{age: 22, name: "Silvia"}
|
||||
|
||||
assert Map.fetch(silvia, :age) == ___
|
||||
end
|
||||
|
||||
defmodule Plane do
|
||||
defstruct passengers: 0, maker: :boeing
|
||||
end
|
||||
|
||||
defmodule Airline do
|
||||
defstruct plane: %Plane{}, name: "Southwest"
|
||||
end
|
||||
@@ -57,7 +49,7 @@ defmodule Structs do
|
||||
|
||||
koan "Use the update_in macro to modify a nested value" do
|
||||
airline = %Airline{plane: %Plane{maker: :boeing, passengers: 200}}
|
||||
assert update_in(airline.plane.passengers, &(&1 + 2)) == ___
|
||||
assert update_in(airline.plane.passengers, fn(x) -> (x + 2) end) == ___
|
||||
end
|
||||
|
||||
koan "Use the put_in macro with atoms to replace a nested value in a non-struct" do
|
||||
|
@@ -101,6 +101,18 @@ defmodule PatternMatching do
|
||||
assert name == ___
|
||||
end
|
||||
|
||||
defmodule Plane do
|
||||
defstruct passengers: 0, maker: :boeing
|
||||
end
|
||||
|
||||
def plane?(%Plane{}), do: true
|
||||
def plane?(_), do: false
|
||||
|
||||
koan "...or onto the type of the struct itself" do
|
||||
assert plane?(%Plane{passengers: 417, maker: :boeing}) == ___
|
||||
assert plane?(%Animal{}) == ___
|
||||
end
|
||||
|
||||
koan "Structs will even match with a regular map" do
|
||||
%{name: name} = %Animal{kind: "dog", name: "Max"}
|
||||
assert name == ___
|
||||
|
@@ -97,4 +97,17 @@ defmodule Functions do
|
||||
|
||||
assert result == ___
|
||||
end
|
||||
|
||||
koan "Conveniently keyword lists can be used for function options" do
|
||||
transform = fn str, opts ->
|
||||
if opts[:upcase] do
|
||||
String.upcase(str)
|
||||
else
|
||||
str
|
||||
end
|
||||
end
|
||||
|
||||
assert transform.("good", upcase: true) == ___
|
||||
assert transform.("good", upcase: false) == ___
|
||||
end
|
||||
end
|
||||
|
@@ -18,6 +18,7 @@ defmodule FunctionsTests do
|
||||
100,
|
||||
1000,
|
||||
"Full Name",
|
||||
{:multiple, ["GOOD", "good"]},
|
||||
]
|
||||
|
||||
test_all(Functions, answers)
|
||||
|
@@ -9,7 +9,6 @@ defmodule KeywordListsTests do
|
||||
"baz",
|
||||
{:multiple, [:foo, "bar"]},
|
||||
"foo",
|
||||
{:multiple, ["GOOD", "good"]},
|
||||
]
|
||||
|
||||
test_all(KeywordLists, answers)
|
||||
|
@@ -17,6 +17,7 @@ defmodule PatternsTests do
|
||||
{:multiple, ["Mickey", "Donald", "I need a name!"]},
|
||||
"dog",
|
||||
"Max",
|
||||
{:multiple, [true, false]},
|
||||
"Max",
|
||||
1,
|
||||
2,
|
||||
|
@@ -8,7 +8,6 @@ defmodule StructsTests do
|
||||
nil,
|
||||
"Joe",
|
||||
33,
|
||||
{:multiple, [true, false]},
|
||||
{:ok, 22},
|
||||
%Structs.Airline{plane: %Structs.Plane{maker: :airbus}, name: "Southwest"},
|
||||
%Structs.Airline{plane: %Structs.Plane{maker: :boeing, passengers: 202}, name: "Southwest"},
|
||||
|
Reference in New Issue
Block a user