Add credo to the project and:
- Run mix credo --all to identify possible code optimizations - Resolve most of the errors generated by credo such as: - Numbers larger than 9999 should be written with underscores: 58_127 - Modules should have a @moduledoc tag - Comparison will always return true
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
defmodule Equalities do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro """
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule Strings do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "Strings"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule Numbers do
|
||||
@moduledoc false
|
||||
require Integer
|
||||
use Koans
|
||||
|
||||
@@ -49,7 +50,7 @@ defmodule Numbers do
|
||||
end
|
||||
|
||||
koan "Let's grab the individual digits in a list" do
|
||||
individual_digits = Integer.digits(58127)
|
||||
individual_digits = Integer.digits(58_127)
|
||||
assert individual_digits == ___
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule Atoms do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "Atoms"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule Tuples do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "Tuples"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule Lists do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "Lists"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule KeywordLists do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "KeywordLists"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule Maps do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "Maps"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule MapSets do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "My name is Set, MapSet."
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
defmodule Structs do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "Structs"
|
||||
|
||||
defmodule Person do
|
||||
@moduledoc false
|
||||
defstruct [:name, :age]
|
||||
end
|
||||
|
||||
@@ -35,10 +37,12 @@ defmodule Structs do
|
||||
end
|
||||
|
||||
defmodule Plane do
|
||||
@moduledoc false
|
||||
defstruct passengers: 0, maker: :boeing
|
||||
end
|
||||
|
||||
defmodule Airline do
|
||||
@moduledoc false
|
||||
defstruct plane: %Plane{}, name: "Southwest"
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule Sigils do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "Sigils"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule PatternMatching do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "PatternMatching"
|
||||
@@ -94,6 +95,7 @@ defmodule PatternMatching do
|
||||
end
|
||||
|
||||
defmodule Animal do
|
||||
@moduledoc false
|
||||
defstruct [:kind, :name]
|
||||
end
|
||||
|
||||
@@ -103,6 +105,7 @@ defmodule PatternMatching do
|
||||
end
|
||||
|
||||
defmodule Plane do
|
||||
@moduledoc false
|
||||
defstruct passengers: 0, maker: :boeing
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule Functions do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "Functions"
|
||||
@@ -104,8 +105,7 @@ defmodule Functions do
|
||||
result =
|
||||
"full-name"
|
||||
|> String.split("-")
|
||||
|> Enum.map(&String.capitalize/1)
|
||||
|> Enum.join(" ")
|
||||
|> Enum.map_join(" ", &String.capitalize/1)
|
||||
|
||||
assert result == ___
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule Enums do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "Enums"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule Processes do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "Processes"
|
||||
@@ -88,8 +89,12 @@ defmodule Processes do
|
||||
|
||||
send(pid, {:hello, self()})
|
||||
|
||||
timeout = 100 # ms
|
||||
failure_message = "Sorry, I didn't get the right message. Look at the message that is sent back very closely, and try again"
|
||||
# ms
|
||||
timeout = 100
|
||||
|
||||
failure_message =
|
||||
"Sorry, I didn't get the right message. Look at the message that is sent back very closely, and try again"
|
||||
|
||||
assert_receive ___, timeout, failure_message
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule Tasks do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "Tasks"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule Agents do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "Agents"
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
defmodule GenServers do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "GenServers"
|
||||
|
||||
defmodule Laptop do
|
||||
@moduledoc false
|
||||
use GenServer
|
||||
|
||||
#####
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
defmodule Protocols do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "Want to follow the rules? Adhere to the protocol!"
|
||||
@@ -12,13 +13,25 @@ defmodule Protocols do
|
||||
end
|
||||
|
||||
defmodule Painter do
|
||||
@moduledoc false
|
||||
@derive Artist
|
||||
defstruct name: ""
|
||||
end
|
||||
|
||||
defmodule(Musician, do: defstruct(name: "", instrument: ""))
|
||||
defmodule(Dancer, do: defstruct(name: "", dance_style: ""))
|
||||
defmodule(Physicist, do: defstruct(name: ""))
|
||||
defmodule Musician do
|
||||
@moduledoc false
|
||||
defstruct(name: "", instrument: "")
|
||||
end
|
||||
|
||||
defmodule Dancer do
|
||||
@moduledoc false
|
||||
defstruct(name: "", dance_style: "")
|
||||
end
|
||||
|
||||
defmodule Physicist do
|
||||
@moduledoc false
|
||||
defstruct(name: "")
|
||||
end
|
||||
|
||||
defimpl Artist, for: Musician do
|
||||
def perform(musician) do
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
defmodule Comprehensions do
|
||||
@moduledoc false
|
||||
use Koans
|
||||
|
||||
@intro "A comprehension is made of three parts: generators, filters, and collectibles. We will look at how these interact with each other"
|
||||
|
||||
koan "The generator, `n <- [1, 2, 3, 4]`, is providing the values for our comprehension" do
|
||||
assert (for n <- [1, 2, 3, 4], do: n * n) == ___
|
||||
assert for(n <- [1, 2, 3, 4], do: n * n) == ___
|
||||
end
|
||||
|
||||
koan "Any enumerable can be a generator" do
|
||||
assert (for n <- 1..4, do: n * n) == ___
|
||||
assert for(n <- 1..4, do: n * n) == ___
|
||||
end
|
||||
|
||||
koan "A generator specifies how to extract values from a collection" do
|
||||
collection = [["Hello","World"], ["Apple", "Pie"]]
|
||||
assert (for [a, b] <- collection, do: "#{a} #{b}") == ___
|
||||
collection = [["Hello", "World"], ["Apple", "Pie"]]
|
||||
assert for([a, b] <- collection, do: "#{a} #{b}") == ___
|
||||
end
|
||||
|
||||
koan "You can use multiple generators at once" do
|
||||
assert (for x <- ["little", "big"], y <- ["dogs", "cats"], do: "#{x} #{y}") == ___
|
||||
assert for(x <- ["little", "big"], y <- ["dogs", "cats"], do: "#{x} #{y}") == ___
|
||||
end
|
||||
|
||||
koan "Use a filter to reduce your work" do
|
||||
assert (for n <- [1, 2, 3, 4, 5, 6], n > 3, do: n) == ___
|
||||
assert for(n <- [1, 2, 3, 4, 5, 6], n > 3, do: n) == ___
|
||||
end
|
||||
|
||||
koan "Add the result of a comprehension to an existing collection" do
|
||||
collection = for x <- ["Pecan", "Pumpkin"], into: %{}, do: {x, "#{x} Pie"}
|
||||
assert collection == ___
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user