From 52f8ed0d6cc477ad200eff469cd914c7a54869a3 Mon Sep 17 00:00:00 2001 From: Jay Hayes Date: Wed, 4 May 2016 19:11:32 -0500 Subject: [PATCH 1/6] Add atoms koan as between strings and tuples --- lib/koans/03_atoms.ex | 0 lib/koans/{03_tuples.ex => 04_tuples.ex} | 0 lib/koans/{04_lists.ex => 05_lists.ex} | 0 lib/koans/{05_maps.ex => 06_maps.ex} | 0 lib/koans/{06_structs.ex => 07_structs.ex} | 0 lib/koans/{07_pattern_matching.ex => 08_pattern_matching.ex} | 0 lib/koans/{08_functions.ex => 09_functions.ex} | 0 lib/koans/{09_enums.ex => 10_enums.ex} | 0 lib/koans/{10_processes.ex => 11_processes.ex} | 0 lib/koans/{11_tasks.ex => 12_tasks.ex} | 0 lib/koans/{12_agents.ex => 13_agents.ex} | 0 11 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/koans/03_atoms.ex rename lib/koans/{03_tuples.ex => 04_tuples.ex} (100%) rename lib/koans/{04_lists.ex => 05_lists.ex} (100%) rename lib/koans/{05_maps.ex => 06_maps.ex} (100%) rename lib/koans/{06_structs.ex => 07_structs.ex} (100%) rename lib/koans/{07_pattern_matching.ex => 08_pattern_matching.ex} (100%) rename lib/koans/{08_functions.ex => 09_functions.ex} (100%) rename lib/koans/{09_enums.ex => 10_enums.ex} (100%) rename lib/koans/{10_processes.ex => 11_processes.ex} (100%) rename lib/koans/{11_tasks.ex => 12_tasks.ex} (100%) rename lib/koans/{12_agents.ex => 13_agents.ex} (100%) diff --git a/lib/koans/03_atoms.ex b/lib/koans/03_atoms.ex new file mode 100644 index 00000000..e69de29b diff --git a/lib/koans/03_tuples.ex b/lib/koans/04_tuples.ex similarity index 100% rename from lib/koans/03_tuples.ex rename to lib/koans/04_tuples.ex diff --git a/lib/koans/04_lists.ex b/lib/koans/05_lists.ex similarity index 100% rename from lib/koans/04_lists.ex rename to lib/koans/05_lists.ex diff --git a/lib/koans/05_maps.ex b/lib/koans/06_maps.ex similarity index 100% rename from lib/koans/05_maps.ex rename to lib/koans/06_maps.ex diff --git a/lib/koans/06_structs.ex b/lib/koans/07_structs.ex similarity index 100% rename from lib/koans/06_structs.ex rename to lib/koans/07_structs.ex diff --git a/lib/koans/07_pattern_matching.ex b/lib/koans/08_pattern_matching.ex similarity index 100% rename from lib/koans/07_pattern_matching.ex rename to lib/koans/08_pattern_matching.ex diff --git a/lib/koans/08_functions.ex b/lib/koans/09_functions.ex similarity index 100% rename from lib/koans/08_functions.ex rename to lib/koans/09_functions.ex diff --git a/lib/koans/09_enums.ex b/lib/koans/10_enums.ex similarity index 100% rename from lib/koans/09_enums.ex rename to lib/koans/10_enums.ex diff --git a/lib/koans/10_processes.ex b/lib/koans/11_processes.ex similarity index 100% rename from lib/koans/10_processes.ex rename to lib/koans/11_processes.ex diff --git a/lib/koans/11_tasks.ex b/lib/koans/12_tasks.ex similarity index 100% rename from lib/koans/11_tasks.ex rename to lib/koans/12_tasks.ex diff --git a/lib/koans/12_agents.ex b/lib/koans/13_agents.ex similarity index 100% rename from lib/koans/12_agents.ex rename to lib/koans/13_agents.ex From 53fc465c3f6afd312a9995f6e16cca958c15bf73 Mon Sep 17 00:00:00 2001 From: Jay Hayes Date: Wed, 4 May 2016 19:13:09 -0500 Subject: [PATCH 2/6] Add atom koans --- lib/koans/03_atoms.ex | 39 +++++++++++++++++++++++++++++++++ test/koans/atoms_koans_test.exs | 17 ++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 test/koans/atoms_koans_test.exs diff --git a/lib/koans/03_atoms.ex b/lib/koans/03_atoms.ex index e69de29b..f1685f2a 100644 --- a/lib/koans/03_atoms.ex +++ b/lib/koans/03_atoms.ex @@ -0,0 +1,39 @@ +defmodule Atoms do + use Koans + + koan "Atoms are sort of like strings" do + adam = :human + assert adam == ___ + end + + koan "Strings can be converted to atoms, and vice versa" do + assert String.to_atom("atomized") == ___ + assert Atom.to_string(:stringified) == ___ + end + + koan "Atoms are often used as keys, because they're faster than strings" do + map = %{name: "Jay"} + list = [name: "Jay"] + + assert map[:name] == ___ + assert list[:name] == ___ + end + + koan "It is surprising to find out that booleans are atoms" do + assert is_atom(true) == ___ + assert is_atom(false) == ___ + assert :true == ___ + assert :false == ___ + end + + koan "Modules are also atoms" do + assert is_atom(String) == ___ + assert :"Elixir.String" == ___ + assert :"Elixir.String".upcase("hello") == ___ + end + + koan "Atoms are used to access Erlang" do + assert :erlang.is_list([]) == ___ + assert :lists.sort([2, 3, 1]) == ___ + end +end diff --git a/test/koans/atoms_koans_test.exs b/test/koans/atoms_koans_test.exs new file mode 100644 index 00000000..9e64d845 --- /dev/null +++ b/test/koans/atoms_koans_test.exs @@ -0,0 +1,17 @@ +defmodule AtomsTests do + use ExUnit.Case + import TestHarness + + test "Atoms" do + answers = [ + :human, + {:multiple, [:atomized, "stringified"]}, + {:multiple, ["Jay", "Jay"]}, + {:multiple, [true, true, true, false]}, + {:multiple, [true, String, "HELLO"]}, + {:multiple, [true, [1,2,3]]}, + ] + + test_all(Atoms, answers) + end +end From 7b64bd36e9818ff846328ad77da05f0aa5105af6 Mon Sep 17 00:00:00 2001 From: Jay Hayes Date: Wed, 4 May 2016 19:13:37 -0500 Subject: [PATCH 3/6] Add other lessons that don't work with answer system --- lib/koans/03_atoms.ex | 16 ++++++++++++++++ test/koans/atoms_koans_test.exs | 2 ++ 2 files changed, 18 insertions(+) diff --git a/lib/koans/03_atoms.ex b/lib/koans/03_atoms.ex index f1685f2a..162f3bc7 100644 --- a/lib/koans/03_atoms.ex +++ b/lib/koans/03_atoms.ex @@ -19,6 +19,22 @@ defmodule Atoms do assert list[:name] == ___ end + #koan "Only atom keys may be accessed with dot syntax" do + # map = %{name: "Jay"} + # assert map.name == ___ + + # map = %{"name" => "Jay"} + # assert_raise KeyError, fn -> ___ end + # assert map["name"] == ___ + #end + + #koan "Dot syntax is stricter than access with brackets" do + # map = %{name: "Jay"} + + # assert map[:age] == ___ + # assert_raise KeyError, fn -> ___ end + #end + koan "It is surprising to find out that booleans are atoms" do assert is_atom(true) == ___ assert is_atom(false) == ___ diff --git a/test/koans/atoms_koans_test.exs b/test/koans/atoms_koans_test.exs index 9e64d845..036cfbfa 100644 --- a/test/koans/atoms_koans_test.exs +++ b/test/koans/atoms_koans_test.exs @@ -7,6 +7,8 @@ defmodule AtomsTests do :human, {:multiple, [:atomized, "stringified"]}, {:multiple, ["Jay", "Jay"]}, + #{:multiple, ["Jay", quote(do: map.name), "Jay"]}, + #{:multiple, [nil, quote(do: map.age)]}, {:multiple, [true, true, true, false]}, {:multiple, [true, String, "HELLO"]}, {:multiple, [true, [1,2,3]]}, From ee89055af69863fb0b9974e49c448181ba840e19 Mon Sep 17 00:00:00 2001 From: Jay Hayes Date: Thu, 5 May 2016 10:41:57 -0500 Subject: [PATCH 4/6] Remove commented koans We can't pull this off right now since answers can't be expressions. --- lib/koans/03_atoms.ex | 16 ---------------- test/koans/atoms_koans_test.exs | 2 -- 2 files changed, 18 deletions(-) diff --git a/lib/koans/03_atoms.ex b/lib/koans/03_atoms.ex index 162f3bc7..f1685f2a 100644 --- a/lib/koans/03_atoms.ex +++ b/lib/koans/03_atoms.ex @@ -19,22 +19,6 @@ defmodule Atoms do assert list[:name] == ___ end - #koan "Only atom keys may be accessed with dot syntax" do - # map = %{name: "Jay"} - # assert map.name == ___ - - # map = %{"name" => "Jay"} - # assert_raise KeyError, fn -> ___ end - # assert map["name"] == ___ - #end - - #koan "Dot syntax is stricter than access with brackets" do - # map = %{name: "Jay"} - - # assert map[:age] == ___ - # assert_raise KeyError, fn -> ___ end - #end - koan "It is surprising to find out that booleans are atoms" do assert is_atom(true) == ___ assert is_atom(false) == ___ diff --git a/test/koans/atoms_koans_test.exs b/test/koans/atoms_koans_test.exs index 036cfbfa..9e64d845 100644 --- a/test/koans/atoms_koans_test.exs +++ b/test/koans/atoms_koans_test.exs @@ -7,8 +7,6 @@ defmodule AtomsTests do :human, {:multiple, [:atomized, "stringified"]}, {:multiple, ["Jay", "Jay"]}, - #{:multiple, ["Jay", quote(do: map.name), "Jay"]}, - #{:multiple, [nil, quote(do: map.age)]}, {:multiple, [true, true, true, false]}, {:multiple, [true, String, "HELLO"]}, {:multiple, [true, [1,2,3]]}, From 948fbddcdf08f2400467259a2af359c72acdc66f Mon Sep 17 00:00:00 2001 From: Jay Hayes Date: Thu, 5 May 2016 10:42:57 -0500 Subject: [PATCH 5/6] Remove unhelpful example Not really useful without showing dot access. --- lib/koans/03_atoms.ex | 8 -------- test/koans/atoms_koans_test.exs | 1 - 2 files changed, 9 deletions(-) diff --git a/lib/koans/03_atoms.ex b/lib/koans/03_atoms.ex index f1685f2a..05cec3a2 100644 --- a/lib/koans/03_atoms.ex +++ b/lib/koans/03_atoms.ex @@ -11,14 +11,6 @@ defmodule Atoms do assert Atom.to_string(:stringified) == ___ end - koan "Atoms are often used as keys, because they're faster than strings" do - map = %{name: "Jay"} - list = [name: "Jay"] - - assert map[:name] == ___ - assert list[:name] == ___ - end - koan "It is surprising to find out that booleans are atoms" do assert is_atom(true) == ___ assert is_atom(false) == ___ diff --git a/test/koans/atoms_koans_test.exs b/test/koans/atoms_koans_test.exs index 9e64d845..c25b72d0 100644 --- a/test/koans/atoms_koans_test.exs +++ b/test/koans/atoms_koans_test.exs @@ -6,7 +6,6 @@ defmodule AtomsTests do answers = [ :human, {:multiple, [:atomized, "stringified"]}, - {:multiple, ["Jay", "Jay"]}, {:multiple, [true, true, true, false]}, {:multiple, [true, String, "HELLO"]}, {:multiple, [true, [1,2,3]]}, From ad011d80f3bc93a55dd21f0e24136571493bca01 Mon Sep 17 00:00:00 2001 From: Jay Hayes Date: Thu, 5 May 2016 10:43:17 -0500 Subject: [PATCH 6/6] Establish that modules are atoms, then show function call on them --- lib/koans/03_atoms.ex | 8 +++----- test/koans/atoms_koans_test.exs | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/koans/03_atoms.ex b/lib/koans/03_atoms.ex index 05cec3a2..596fe79c 100644 --- a/lib/koans/03_atoms.ex +++ b/lib/koans/03_atoms.ex @@ -20,12 +20,10 @@ defmodule Atoms do koan "Modules are also atoms" do assert is_atom(String) == ___ - assert :"Elixir.String" == ___ - assert :"Elixir.String".upcase("hello") == ___ end - koan "Atoms are used to access Erlang" do - assert :erlang.is_list([]) == ___ - assert :lists.sort([2, 3, 1]) == ___ + koan "Functions can be called on the atom too" do + assert :"Elixir.String" == String + assert :"Elixir.String".upcase("hello") == ___ end end diff --git a/test/koans/atoms_koans_test.exs b/test/koans/atoms_koans_test.exs index c25b72d0..743d986d 100644 --- a/test/koans/atoms_koans_test.exs +++ b/test/koans/atoms_koans_test.exs @@ -7,8 +7,8 @@ defmodule AtomsTests do :human, {:multiple, [:atomized, "stringified"]}, {:multiple, [true, true, true, false]}, - {:multiple, [true, String, "HELLO"]}, - {:multiple, [true, [1,2,3]]}, + true, + "HELLO", ] test_all(Atoms, answers)