Skip to content

Commit 18ce175

Browse files
authored
Merge pull request #215 from elixirkoans/minor-koan-rearrangement
Minor koan rearrangement
2 parents b9b1a58 + 03c6ddc commit 18ce175

8 files changed

Lines changed: 32 additions & 28 deletions

lib/koans/07_keyword_lists.ex

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,4 @@ defmodule KeywordLists do
3131

3232
assert_raise ArgumentError, fn -> not_kw_list[___] end
3333
end
34-
35-
koan "Conveniently keyword lists can be used for function options" do
36-
transform = fn str, opts ->
37-
if opts[:upcase] do
38-
String.upcase(str)
39-
else
40-
str
41-
end
42-
end
43-
44-
assert transform.("good", upcase: true) == ___
45-
assert transform.("good", upcase: false) == ___
46-
end
4734
end

lib/koans/10_structs.ex

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,16 @@ defmodule Structs do
2828
assert older.age == ___
2929
end
3030

31-
defmodule Plane do
32-
defstruct passengers: 0, maker: :boeing
33-
end
34-
35-
def plane?(%Plane{}), do: true
36-
def plane?(_), do: false
37-
38-
koan "Or onto the type of the struct itself" do
39-
assert plane?(%Plane{passengers: 417, maker: :boeing}) == ___
40-
assert plane?(%Person{}) == ___
41-
end
42-
4331
koan "Struct can be treated like maps" do
4432
silvia = %Person{age: 22, name: "Silvia"}
4533

4634
assert Map.fetch(silvia, :age) == ___
4735
end
4836

37+
defmodule Plane do
38+
defstruct passengers: 0, maker: :boeing
39+
end
40+
4941
defmodule Airline do
5042
defstruct plane: %Plane{}, name: "Southwest"
5143
end
@@ -57,7 +49,7 @@ defmodule Structs do
5749

5850
koan "Use the update_in macro to modify a nested value" do
5951
airline = %Airline{plane: %Plane{maker: :boeing, passengers: 200}}
60-
assert update_in(airline.plane.passengers, &(&1 + 2)) == ___
52+
assert update_in(airline.plane.passengers, fn(x) -> (x + 2) end) == ___
6153
end
6254

6355
koan "Use the put_in macro with atoms to replace a nested value in a non-struct" do

lib/koans/12_pattern_matching.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ defmodule PatternMatching do
101101
assert name == ___
102102
end
103103

104+
defmodule Plane do
105+
defstruct passengers: 0, maker: :boeing
106+
end
107+
108+
def plane?(%Plane{}), do: true
109+
def plane?(_), do: false
110+
111+
koan "...or onto the type of the struct itself" do
112+
assert plane?(%Plane{passengers: 417, maker: :boeing}) == ___
113+
assert plane?(%Animal{}) == ___
114+
end
115+
104116
koan "Structs will even match with a regular map" do
105117
%{name: name} = %Animal{kind: "dog", name: "Max"}
106118
assert name == ___

lib/koans/13_functions.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,17 @@ defmodule Functions do
9797

9898
assert result == ___
9999
end
100+
101+
koan "Conveniently keyword lists can be used for function options" do
102+
transform = fn str, opts ->
103+
if opts[:upcase] do
104+
String.upcase(str)
105+
else
106+
str
107+
end
108+
end
109+
110+
assert transform.("good", upcase: true) == ___
111+
assert transform.("good", upcase: false) == ___
112+
end
100113
end

test/koans/functions_koans_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ defmodule FunctionsTests do
1818
100,
1919
1000,
2020
"Full Name",
21+
{:multiple, ["GOOD", "good"]},
2122
]
2223

2324
test_all(Functions, answers)

test/koans/keyword_lists_koans_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ defmodule KeywordListsTests do
99
"baz",
1010
{:multiple, [:foo, "bar"]},
1111
"foo",
12-
{:multiple, ["GOOD", "good"]},
1312
]
1413

1514
test_all(KeywordLists, answers)

test/koans/patterns_koans_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ defmodule PatternsTests do
1717
{:multiple, ["Mickey", "Donald", "I need a name!"]},
1818
"dog",
1919
"Max",
20+
{:multiple, [true, false]},
2021
"Max",
2122
1,
2223
2,

test/koans/structs_koans_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ defmodule StructsTests do
88
nil,
99
"Joe",
1010
33,
11-
{:multiple, [true, false]},
1211
{:ok, 22},
1312
%Structs.Airline{plane: %Structs.Plane{maker: :airbus}, name: "Southwest"},
1413
%Structs.Airline{plane: %Structs.Plane{maker: :boeing, passengers: 202}, name: "Southwest"},

0 commit comments

Comments
 (0)