Fix punctuation
This commit is contained in:
@@ -63,7 +63,7 @@ defmodule Functions do
|
|||||||
def bigger(a,b) when a > b, do: "#{a} is bigger than #{b}"
|
def bigger(a,b) when a > b, do: "#{a} is bigger than #{b}"
|
||||||
def bigger(a,b) when a <= b, do: "#{a} is not bigger than #{b}"
|
def bigger(a,b) when a <= b, do: "#{a} is not bigger than #{b}"
|
||||||
|
|
||||||
koan "You can also create intricate guards based on the values." do
|
koan "You can also create intricate guards based on the values" do
|
||||||
assert bigger(10, 5) == :__
|
assert bigger(10, 5) == :__
|
||||||
assert bigger(4, 27) == :__
|
assert bigger(4, 27) == :__
|
||||||
end
|
end
|
||||||
@@ -97,7 +97,7 @@ defmodule Functions do
|
|||||||
def multiply_then_call(number, fun), do: fun.(number*5)
|
def multiply_then_call(number, fun), do: fun.(number*5)
|
||||||
def square(number), do: number * number
|
def square(number), do: number * number
|
||||||
|
|
||||||
koan "You can 'capture' functions if you want to pass them around as values. Mind the ampersand '&' and the slash followed by the number of args." do
|
koan "You can 'capture' functions if you want to pass them around as values. Mind the ampersand '&' and the slash followed by the number of args" do
|
||||||
assert multiply_then_call(2, &square/1) == :__
|
assert multiply_then_call(2, &square/1) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -5,34 +5,34 @@ defmodule Enums do
|
|||||||
assert Enum.count([1,2,3]) == :__
|
assert Enum.count([1,2,3]) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "...the same applies for counting elements in a map..." do
|
koan "The same applies for counting elements in a map" do
|
||||||
assert Enum.count(%{ :a => :foo, :b => :bar}) == :__
|
assert Enum.count(%{ :a => :foo, :b => :bar}) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "..or a keyword list..." do
|
koan "Or a keyword list" do
|
||||||
assert Enum.count([a: 77, b: 23, c: 12, d: 33, e: 90, f: 113]) == :__
|
assert Enum.count([a: 77, b: 23, c: 12, d: 33, e: 90, f: 113]) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
def less_than_five(n), do: n < 5
|
def less_than_five?(n), do: n < 5
|
||||||
koan "Elements can have a lot in common" do
|
koan "Elements can have a lot in common" do
|
||||||
assert Enum.all?([1,2,3], &less_than_five/1) == :__
|
assert Enum.all?([1,2,3], &less_than_five?/1) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
def less_than_two(n), do: n < 2
|
def less_than_two?(n), do: n < 2
|
||||||
koan "If one if different, all elements are not alike" do
|
koan "If one if different, all elements are not alike" do
|
||||||
assert Enum.all?([1, 2, 3, 2], &less_than_two/1) == :__
|
assert Enum.all?([1, 2, 3, 2], &less_than_two?/1) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_even?(n), do: rem(n, 2) == 0
|
def even?(n), do: rem(n, 2) == 0
|
||||||
|
|
||||||
koan "sometimes you you just want to know if there are any elements fullfilling a condition" do
|
koan "sometimes you you just want to know if there are any elements fullfilling a condition" do
|
||||||
assert Enum.any?([1,2,3], &is_even?/1) == :__
|
assert Enum.any?([1,2,3], &even?/1) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
def divisible_by_five(n), do: rem(n, 5) == 0
|
def divisible_by_five?(n), do: rem(n, 5) == 0
|
||||||
|
|
||||||
koan "if not a single element fits the bill, any? returns false" do
|
koan "if not a single element fits the bill, any? returns false" do
|
||||||
assert Enum.any?([1,2,3], &divisible_by_five/1) == :__
|
assert Enum.any?([1,2,3], &divisible_by_five?/1) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "Sometimes you just want to know if an element is part of the party" do
|
koan "Sometimes you just want to know if an element is part of the party" do
|
||||||
@@ -50,24 +50,23 @@ defmodule Enums do
|
|||||||
end
|
end
|
||||||
|
|
||||||
koan "You can even return a list with entirely different types" do
|
koan "You can even return a list with entirely different types" do
|
||||||
assert Enum.map([1,2,3], &is_even?/1) == :__
|
assert Enum.map([1,2,3], &even?/1) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
koan "But keep in mind that the original list remains unchanged" do
|
koan "But keep in mind that the original list remains unchanged" do
|
||||||
input = [1,2,3,4]
|
input = [1,2,3,4]
|
||||||
assert Enum.map(input, &is_even?/1) == :__
|
assert Enum.map(input, &even?/1) == :__
|
||||||
assert input == :__
|
assert input == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_odd?(n), do: rem(n, 2) == 1
|
def odd?(n), do: rem(n, 2) == 1
|
||||||
|
|
||||||
koan "Filter allows you to only keep what you really care about" do
|
koan "Filter allows you to only keep what you really care about" do
|
||||||
assert Enum.filter([1,2,3], &is_odd?/1) == :__
|
assert Enum.filter([1,2,3], &odd?/1) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "Reject will help you throw out unwanted cruft" do
|
koan "Reject will help you throw out unwanted cruft" do
|
||||||
assert Enum.reject([1,2,3], &is_odd?/1) == :__
|
assert Enum.reject([1,2,3], &odd?/1) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "You three there, follow me!" do
|
koan "You three there, follow me!" do
|
||||||
@@ -78,9 +77,8 @@ defmodule Enums do
|
|||||||
assert Enum.take([1,2,3,4,5], 10) == :__
|
assert Enum.take([1,2,3,4,5], 10) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
def less_than_four(n), do: n < 4
|
|
||||||
koan "Take what you can..." do
|
koan "Take what you can..." do
|
||||||
assert Enum.take_while([1,2,3,4,5,6,7], &less_than_four/1) == :__
|
assert Enum.take_while([1,2,3,4,5,6,7], &less_than_five?/1) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "Just like taking, you can also drop elements" do
|
koan "Just like taking, you can also drop elements" do
|
||||||
@@ -115,15 +113,15 @@ defmodule Enums do
|
|||||||
end
|
end
|
||||||
|
|
||||||
koan "When you want to find that one pesky element" do
|
koan "When you want to find that one pesky element" do
|
||||||
assert Enum.find([1,2,3], &is_even?/1) == :__
|
assert Enum.find([1,2,3], &even?/1) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "...but you don't quite find it..." do
|
koan "...but you don't quite find it..." do
|
||||||
assert Enum.find([1,2,3], &divisible_by_five/1) == :__
|
assert Enum.find([1,2,3], &divisible_by_five?/1) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "...you can settle for a consolation prize" do
|
koan "...you can settle for a consolation prize" do
|
||||||
assert Enum.find([1,2,3], :no_such_element, &divisible_by_five/1) == :__
|
assert Enum.find([1,2,3], :no_such_element, &divisible_by_five?/1) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "Collapse an entire list of elements down to a single one by repeating a function." do
|
koan "Collapse an entire list of elements down to a single one by repeating a function." do
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ defmodule Processes do
|
|||||||
use Koans
|
use Koans
|
||||||
|
|
||||||
koan "Tests run in a process" do
|
koan "Tests run in a process" do
|
||||||
assert Process.alive?(:__)
|
assert Process.alive?(self()) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "You can ask a process to introduce itself" do
|
koan "You can ask a process to introduce itself" do
|
||||||
information = Process.info(self)
|
information = Process.info(self())
|
||||||
|
|
||||||
assert information[:status] == :__
|
assert information[:status] == :__
|
||||||
end
|
end
|
||||||
@@ -76,7 +76,7 @@ defmodule Processes do
|
|||||||
assert Process.alive?(pid) == :__
|
assert Process.alive?(pid) == :__
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "Exiting yourself on the other hand DOES termiante you" do
|
koan "Exiting yourself on the other hand DOES terminate you" do
|
||||||
pid = spawn(fn -> receive do
|
pid = spawn(fn -> receive do
|
||||||
:bye -> Process.exit(self(), :normal)
|
:bye -> Process.exit(self(), :normal)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ defmodule KoansHarnessTest do
|
|||||||
[2],
|
[2],
|
||||||
[1,2,3],
|
[1,2,3],
|
||||||
[1,2,3,4,5],
|
[1,2,3,4,5],
|
||||||
[1,2,3],
|
[1,2,3,4],
|
||||||
[1,2,3],
|
[1,2,3],
|
||||||
[0,1,2,3],
|
[0,1,2,3],
|
||||||
%{ :odd => [3,1], :even => [4,2] },
|
%{ :odd => [3,1], :even => [4,2] },
|
||||||
@@ -198,7 +198,7 @@ defmodule KoansHarnessTest do
|
|||||||
|
|
||||||
test "Processes" do
|
test "Processes" do
|
||||||
answers = [
|
answers = [
|
||||||
self,
|
true,
|
||||||
:running,
|
:running,
|
||||||
"hola!",
|
"hola!",
|
||||||
:how_are_you?,
|
:how_are_you?,
|
||||||
|
|||||||
Reference in New Issue
Block a user