From 4ca9ab44ad408585cf1ea7295ea0e4c19d5bcda6 Mon Sep 17 00:00:00 2001 From: Felipe Sere Date: Tue, 8 Mar 2016 11:36:24 +0000 Subject: [PATCH 1/2] Squash compiler warnings. --- lib/koans/05_functions.ex | 2 +- lib/koans/07_arithmetic.ex | 3 ++- lib/koans/08_structs.ex | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/koans/05_functions.ex b/lib/koans/05_functions.ex index c791938..e4a3b78 100644 --- a/lib/koans/05_functions.ex +++ b/lib/koans/05_functions.ex @@ -52,7 +52,7 @@ defmodule Functions do end 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 "You can 'guard' functions against their arguments" do assert sum_up([1,2,3]) == :entire_list assert sum_up(1) == :single_thing diff --git a/lib/koans/07_arithmetic.ex b/lib/koans/07_arithmetic.ex index b7d37d3..0ebaa9b 100644 --- a/lib/koans/07_arithmetic.ex +++ b/lib/koans/07_arithmetic.ex @@ -53,8 +53,9 @@ defmodule Arithmetic do end koan "it can not divide by zero" do + div_by = fn(n) -> 1 / n end try do - 1 / 0.0 + div_by.(0) rescue ArithmeticError -> true end diff --git a/lib/koans/08_structs.ex b/lib/koans/08_structs.ex index 8e70a12..569e260 100644 --- a/lib/koans/08_structs.ex +++ b/lib/koans/08_structs.ex @@ -6,7 +6,8 @@ defmodule Structs do end koan "structs are defined and named after a module" do - assert %Person{} + person = %Person{} + assert person == %Person{} end koan "you can access the fields of a struct" do @@ -53,7 +54,6 @@ defmodule Structs do koan "are basically maps" do silvia = %Person{age: 22, name: "Silvia"} - assert is_map(silvia) assert Map.fetch!(silvia, :age) == 22 end end From 894e0504b966821e056583434bacaeaa86106cc9 Mon Sep 17 00:00:00 2001 From: Felipe Sere Date: Tue, 8 Mar 2016 11:50:58 +0000 Subject: [PATCH 2/2] Get rid of divison by zero --- lib/koans/07_arithmetic.ex | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/koans/07_arithmetic.ex b/lib/koans/07_arithmetic.ex index 0ebaa9b..f64e164 100644 --- a/lib/koans/07_arithmetic.ex +++ b/lib/koans/07_arithmetic.ex @@ -51,13 +51,4 @@ defmodule Arithmetic do koan "it finds the minimum in a list" do assert Enum.min([1,2,3,4]) == 1 end - - koan "it can not divide by zero" do - div_by = fn(n) -> 1 / n end - try do - div_by.(0) - rescue - ArithmeticError -> true - end - end end