From 917f878d4d74738ab655dd793f7664431b34af53 Mon Sep 17 00:00:00 2001 From: Tjaco Oostdijk Date: Fri, 13 Jan 2017 23:13:02 +0100 Subject: [PATCH 1/2] minor refactoring in explanations --- .../.workshop/exercises/determine_pair/exercise.exs | 2 +- .../.workshop/exercises/first_exercise/exercise.exs | 12 ++++++------ .../exercises/first_exercise/solution/fizz_buzz.exs | 6 +++--- .../exercises/first_exercise/test/check.exs | 6 +++--- .../.workshop/exercises/arrange/exercise.exs | 7 +++++-- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/studygroup_001/.workshop/exercises/determine_pair/exercise.exs b/studygroup_001/.workshop/exercises/determine_pair/exercise.exs index 632f5b6..5fd8ea7 100644 --- a/studygroup_001/.workshop/exercises/determine_pair/exercise.exs +++ b/studygroup_001/.workshop/exercises/determine_pair/exercise.exs @@ -8,7 +8,7 @@ defmodule Workshop.Exercise.DeterminePair do # given `@task`. @description """ Complete the function determine_pair, which will return a boolean, determining - if the hand of 5 cards does include a pair (two cards of samen number). + if the hand of 5 cards does include a pair (two cards of same number). # What's next? Get the task for this exercise by executing `mix workshop.task`. When you are diff --git a/studygroup_001/.workshop/exercises/first_exercise/exercise.exs b/studygroup_001/.workshop/exercises/first_exercise/exercise.exs index d1a6467..e6eccb0 100644 --- a/studygroup_001/.workshop/exercises/first_exercise/exercise.exs +++ b/studygroup_001/.workshop/exercises/first_exercise/exercise.exs @@ -8,9 +8,9 @@ defmodule Workshop.Exercise.FirstExercise do # given `@task`. @description """ Write a FizzBuzz program without if/unless/case etc. The FizzBuzz program - outputs numbers 1 - 100. Each number which can be divided by 5 should be - replaced by "fizz", each multiple number of 3 should be replaced by "buzz" - and each number which can be divided by both should be replace by "fizzbuzz" + outputs numbers 1 - 100. Each number that is divisible by 3 should be + replaced by "Fizz", each number divisible by 5 should be replaced by "Buzz" + and each number that is divisible by both should be replace by "FizzBuzz" # What's next? Get the task for this exercise by executing `mix workshop.task`. When you are @@ -26,9 +26,9 @@ defmodule Workshop.Exercise.FirstExercise do @task """ Write a FizzBuzz program without if/unless/case etc. The FizzBuzz program - outputs numbers 1 - 100. Each number which can be divided by 5 should be - replaced by "fizz", each multiple number of 3 should be replaced by "buzz" - and each number which can be divided by both should be replace by "fizzbuzz" + outputs numbers 1 - 100. Each number that is divisible by 3 should be + replaced by "Fizz", each number divisible by 5 should be replaced by "Buzz" + and each number that is divisible by both should be replace by "FizzBuzz" """ @hint [ diff --git a/studygroup_001/.workshop/exercises/first_exercise/solution/fizz_buzz.exs b/studygroup_001/.workshop/exercises/first_exercise/solution/fizz_buzz.exs index 6c6b678..15d1a9b 100644 --- a/studygroup_001/.workshop/exercises/first_exercise/solution/fizz_buzz.exs +++ b/studygroup_001/.workshop/exercises/first_exercise/solution/fizz_buzz.exs @@ -1,8 +1,8 @@ defmodule FizzBuzz do import Kernel, except: [if: 2, unless: 2, case: 2] - def translate(number) when rem(number, 15) == 0, do: "fizzbuzz" - def translate(number) when rem(number, 5) == 0, do: "fizz" - def translate(number) when rem(number, 3) == 0, do: "buzz" + def translate(number) when rem(number, 15) == 0, do: "FizzBuzz" + def translate(number) when rem(number, 5) == 0, do: "Buzz" + def translate(number) when rem(number, 3) == 0, do: "Fizz" def translate(number), do: number end diff --git a/studygroup_001/.workshop/exercises/first_exercise/test/check.exs b/studygroup_001/.workshop/exercises/first_exercise/test/check.exs index 7fad9db..f7784a4 100644 --- a/studygroup_001/.workshop/exercises/first_exercise/test/check.exs +++ b/studygroup_001/.workshop/exercises/first_exercise/test/check.exs @@ -7,14 +7,14 @@ defmodule Workshop.Exercise.FirstExerciseCheck do end verify "verify FizzBuzz.translate(5)" do - (FizzBuzz.translate(5) == "fizz" && :ok) || {:error, "FizzBuzz.translate(5) == 'fizz', got #{FizzBuzz.translate(5)} "} + (FizzBuzz.translate(5) == "Buzz" && :ok) || {:error, "FizzBuzz.translate(5) == 'Buzz', got #{FizzBuzz.translate(5)} "} end verify "verify FizzBuzz.translate(3)" do - (FizzBuzz.translate(3) == "buzz" && :ok) || {:error, "FizzBuzz.translate(3) == 'buzz' expected, got #{FizzBuzz.translate(3)}"} + (FizzBuzz.translate(3) == "Fizz" && :ok) || {:error, "FizzBuzz.translate(3) == 'Fizz' expected, got #{FizzBuzz.translate(3)}"} end verify "verify FizzBuzz.translate(45)" do - (FizzBuzz.translate(45) == "fizzbuzz" && :ok) || {:error, "FizzBuzz.translate(45) 'fizzbuzz' expected, got #{FizzBuzz.translate(45)}"} + (FizzBuzz.translate(45) == "FizzBuzz" && :ok) || {:error, "FizzBuzz.translate(45) 'FizzBuzz' expected, got #{FizzBuzz.translate(45)}"} end end diff --git a/studygroup_002/.workshop/exercises/arrange/exercise.exs b/studygroup_002/.workshop/exercises/arrange/exercise.exs index 80e3b48..f20640e 100644 --- a/studygroup_002/.workshop/exercises/arrange/exercise.exs +++ b/studygroup_002/.workshop/exercises/arrange/exercise.exs @@ -10,7 +10,8 @@ defmodule Workshop.Exercise.Arrange do The sliced veggies & meat dices have to be arranged so next person can quickly combine them into a delicious high cuisine item. Implement arrange function which given a list of (unarranged) :vegetable_slices and :meat_dices arranges them alternately - starting with a :vegetable_slice + starting with a :vegetable_slice. You can assume that for this exercise the list + will have an equal number of meat_dice and vegetable_slices. # What's next? Take a look into arranger.exs and implement missing stuff. When you are @@ -27,7 +28,9 @@ defmodule Workshop.Exercise.Arrange do @task """ Implement arrange function which given a list of (unarranged) :vegetable_slices and :meat_dices arranges them alternately - starting with a :vegetable_slice + starting with a :vegetable_slice. + You can assume that for this exercise the list + will have an equal number of meat_dice and vegetable_slices. """ @hint [ From ee9c328ebb093e4bfc80b1b81e0f7d5c1c75b9df Mon Sep 17 00:00:00 2001 From: Tjaco Oostdijk Date: Sat, 14 Jan 2017 00:23:09 +0100 Subject: [PATCH 2/2] fix pair test and solution --- .../determine_pair/solution/pair.exs | 15 ++++--- .../exercises/determine_pair/test/check.exs | 43 +++++++++++-------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/studygroup_001/.workshop/exercises/determine_pair/solution/pair.exs b/studygroup_001/.workshop/exercises/determine_pair/solution/pair.exs index cf46150..b9eb57c 100644 --- a/studygroup_001/.workshop/exercises/determine_pair/solution/pair.exs +++ b/studygroup_001/.workshop/exercises/determine_pair/solution/pair.exs @@ -2,10 +2,13 @@ defmodule Pair do # One pair @spec determine_pair(list) :: boolean - def determine_pair([[_, a], [_, a], _, _, _]), do: true - def determine_pair([_, [_, a], [_, a], _, _]), do: true - def determine_pair([_, _, [_, a], [_, a], _]), do: true - def determine_pair([_, _, _, [_, a], [_, a]]), do: true - - def determine_pair(_), do: false + def determine_pair(list) do + new_list = Enum.uniq_by(list, fn [_, x] -> x end) + cond do + length(new_list) < 5 -> + true + true -> + false + end + end end diff --git a/studygroup_001/.workshop/exercises/determine_pair/test/check.exs b/studygroup_001/.workshop/exercises/determine_pair/test/check.exs index 26cfc3d..548a85c 100644 --- a/studygroup_001/.workshop/exercises/determine_pair/test/check.exs +++ b/studygroup_001/.workshop/exercises/determine_pair/test/check.exs @@ -1,34 +1,37 @@ defmodule Workshop.Exercise.DeterminePairCheck do use Workshop.Validator use ExUnit.Case - import Pair - test "one pair" do - assert(determine_pair(one_pair)) + verify "one pair" do + (Pair.determine_pair(one_pair) == true && :ok) || {:error, "One Pair failed to validate"} end - test "straight has no pair" do - refute(determine_pair(straight)) + verify "one pair separated should be valid" do + (Pair.determine_pair(one_pair_separated) == true && :ok) || {:error, "One Pair failed to validate"} end - test "two pairs has a pair" do - assert(determine_pair(two_pairs)) + verify "straight has no pair" do + (Pair.determine_pair(straight) != true && :ok) || {:error, "One Pair failed to validate"} end - test "full house has no pair" do - assert(determine_pair(full_house)) + verify "two pairs has a pair" do + (Pair.determine_pair(two_pairs) == true && :ok) || {:error, "One Pair failed to validate"} end - test "something has no pair" do - refute(determine_pair(something)) + verify "full house has a pair" do + (Pair.determine_pair(full_house) == true && :ok) || {:error, "One Pair failed to validate"} end - test "four of kind has a pair" do - assert(determine_pair(four_of_kind)) + verify "something has no pair" do + (Pair.determine_pair(something) != true && :ok) || {:error, "One Pair failed to validate"} end - test "three of kind has a pair" do - assert(determine_pair(three_of_kind)) + verify "four of kind has a pair" do + (Pair.determine_pair(four_of_kind) == true && :ok) || {:error, "One Pair failed to validate"} + end + + verify "three of kind has a pair" do + (Pair.determine_pair(three_of_kind) == true && :ok) || {:error, "One Pair failed to validate"} end defp four_of_kind do @@ -55,11 +58,15 @@ defmodule Workshop.Exercise.DeterminePairCheck do [ [:hearts, 5], [:spades, 5], [:diamonds, 6], [:clubs, :ace], [:hearts, 7] ] end + defp one_pair_separated do + [ [:hearts, 5], [:hearts, 7], [:diamonds, 6], [:clubs, :ace], [:spades, 5] ] + end + defp something do [ [:hearts, 5], [:spades, 4], [:diamonds, 6], [:clubs, :jack], [:hearts, 7] ] end -# verify "all tests pass" do -# ((%{failures: 0} = ExUnit.run) && :ok) || ExUnit.start && {:error, "Some tests have failed"} -# end + # verify "all tests pass" do + # ((%{failures: 0} = ExUnit.run) && :ok) || ExUnit.start && {:error, "Some tests have failed"} + # end end