Skip to content

Commit

Permalink
Run mix format (exercism#391)
Browse files Browse the repository at this point in the history
Closes exercism#387.
  • Loading branch information
sotojuan authored and devonestes committed Feb 26, 2018
1 parent 74e2383 commit 771a49c
Show file tree
Hide file tree
Showing 247 changed files with 2,619 additions and 2,355 deletions.
3 changes: 3 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
inputs: ["mix.exs", "{exercises}/**/*.{ex,exs}"]
]
16 changes: 8 additions & 8 deletions exercises/accumulate/accumulate_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
Code.load_file("accumulate.exs", __DIR__)
end

ExUnit.start
ExUnit.configure exclude: :pending, trace: true
ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)

defmodule AccumulateTest do
use ExUnit.Case

test "accumulate empty list" do
assert Accumulate.accumulate([], fn(n) -> n * n end) == []
assert Accumulate.accumulate([], fn n -> n * n end) == []
end

@tag :pending
test "accumulate square numbers" do
assert Accumulate.accumulate([1, 2, 3], fn(n) -> n * n end) == [1, 4, 9]
assert Accumulate.accumulate([1, 2, 3], fn n -> n * n end) == [1, 4, 9]
end

@tag :pending
test "accumulate upcased strings" do
fun = fn(w) -> String.upcase(w) end
fun = fn w -> String.upcase(w) end
assert Accumulate.accumulate(["hello", "world"], fun) == ["HELLO", "WORLD"]
end

@tag :pending
test "accumulate reversed strings" do
fun = fn(w) -> String.reverse(w) end
fun = fn w -> String.reverse(w) end
words = ~w(the quick brown fox etc)
expected = ["eht", "kciuq", "nworb", "xof", "cte"]
assert Accumulate.accumulate(words, fun) == expected
Expand All @@ -34,8 +34,8 @@ defmodule AccumulateTest do
@tag :pending
test "nested accumulate" do
chars = ~w(a b c)
nums = ~w(1 2 3)
fun = fn(c) -> Accumulate.accumulate(nums, &(c <> &1)) end
nums = ~w(1 2 3)
fun = fn c -> Accumulate.accumulate(nums, &(c <> &1)) end
expected = [["a1", "a2", "a3"], ["b1", "b2", "b3"], ["c1", "c2", "c3"]]
assert Accumulate.accumulate(chars, fun) == expected
end
Expand Down
4 changes: 2 additions & 2 deletions exercises/acronym/acronym_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
Code.load_file("acronym.exs", __DIR__)
end

ExUnit.start
ExUnit.configure exclude: :pending, trace: true
ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)

defmodule AcronymTest do
use ExUnit.Case
Expand Down
7 changes: 3 additions & 4 deletions exercises/acronym/example.exs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
defmodule Acronym do

@spec abbreviate(String.t()) :: String.t()
def abbreviate(string) do
Regex.scan(~r/[A-Z]+[a-z]*|[a-z]+/, string)
|> List.flatten
|> Enum.map(fn(x) -> String.first(x) end)
|> List.flatten()
|> Enum.map(fn x -> String.first(x) end)
|> Enum.join("")
|> String.upcase
|> String.upcase()
end
end
4 changes: 2 additions & 2 deletions exercises/all-your-base/all-your-base-test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
Code.load_file("all-your-base.exs", __DIR__)
end

ExUnit.start
ExUnit.configure exclude: :pending, trace: true
ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)

defmodule AllYourBaseTest do
use ExUnit.Case
Expand Down
21 changes: 14 additions & 7 deletions exercises/all-your-base/example.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule AllYourBase do

@doc """
Given a number in base a, represented as a sequence of digits, converts it to base b,
or returns nil if either of the bases are less than 2
Expand All @@ -8,27 +7,35 @@ defmodule AllYourBase do
@spec convert(list, integer, integer) :: list
def convert(digits, base_a, base_b) do
cond do
base_a > 1 and base_b > 1 and digits !=[] ->
base_a > 1 and base_b > 1 and digits != [] ->
do_convert(digits, base_a, base_b)

true ->
nil
end
end

defp do_convert(digits, base_a, base_b) do
num = convert_to_num(digits, base_a, 0)

case num do
nil -> nil
0 -> [0]
num -> convert_to_digits(num, base_b, [])
|> Enum.reverse
nil ->
nil

0 ->
[0]

num ->
convert_to_digits(num, base_b, [])
|> Enum.reverse()
end
end

defp convert_to_num([head | tail], base_a, accumulator) do
cond do
head < base_a and head >= 0 ->
convert_to_num(tail, base_a, accumulator * base_a + head)
convert_to_num(tail, base_a, accumulator * base_a + head)

true ->
nil
end
Expand Down
6 changes: 2 additions & 4 deletions exercises/allergies/allergies.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ defmodule Allergies do
@doc """
List the allergies for which the corresponding flag bit is true.
"""
@spec list(non_neg_integer) :: [String.t]
@spec list(non_neg_integer) :: [String.t()]
def list(flags) do

end

@doc """
Returns whether the corresponding flag bit in 'flags' is set for the item.
"""
@spec allergic_to?(non_neg_integer, String.t) :: boolean
@spec allergic_to?(non_neg_integer, String.t()) :: boolean
def allergic_to?(flags, item) do

end
end
28 changes: 17 additions & 11 deletions exercises/allergies/allergies_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
Code.load_file("allergies.exs", __DIR__)
end


ExUnit.start
ExUnit.configure exclude: :pending, trace: true
ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)

defmodule AllergiesTest do
use ExUnit.Case
Expand Down Expand Up @@ -41,12 +40,16 @@ defmodule AllergiesTest do

@tag :pending
test "allergic_to_lots_of_stuff" do
Allergies.list(248) |> assert_is_a_set_containing(~w[strawberries tomatoes chocolate pollen cats])
Allergies.list(248)
|> assert_is_a_set_containing(~w[strawberries tomatoes chocolate pollen cats])
end

@tag :pending
test "allergic_to_everything" do
Allergies.list(255) |> assert_is_a_set_containing(~w[eggs peanuts shellfish strawberries tomatoes chocolate pollen cats])
Allergies.list(255)
|> assert_is_a_set_containing(
~w[eggs peanuts shellfish strawberries tomatoes chocolate pollen cats]
)
end

@tag :pending
Expand All @@ -68,16 +71,19 @@ defmodule AllergiesTest do

@tag :pending
test "ignore_non_allergen_score_parts" do
Allergies.list(509) |> assert_is_a_set_containing(~w[eggs shellfish strawberries tomatoes chocolate pollen cats])
Allergies.list(509)
|> assert_is_a_set_containing(~w[eggs shellfish strawberries tomatoes chocolate pollen cats])
end

defp assert_is_a_set_containing(list, to_contain) do
set = Enum.into(list, MapSet.new)
same_contents = to_contain
|> Enum.into(MapSet.new)
set = Enum.into(list, MapSet.new())

same_contents =
to_contain
|> Enum.into(MapSet.new())
|> MapSet.equal?(set)

assert same_contents,
"Expected a set with: #{inspect to_contain} got #{inspect set |> MapSet.to_list}"
"Expected a set with: #{inspect(to_contain)} got #{inspect(set |> MapSet.to_list())}"
end

end
3 changes: 1 addition & 2 deletions exercises/anagram/anagram.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ defmodule Anagram do
@doc """
Returns all candidates that are anagrams of, but not equal to, 'base'.
"""
@spec match(String.t, [String.t]) :: [String.t]
@spec match(String.t(), [String.t()]) :: [String.t()]
def match(base, candidates) do

end
end
26 changes: 13 additions & 13 deletions exercises/anagram/anagram_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,75 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
Code.load_file("anagram.exs", __DIR__)
end

ExUnit.start
ExUnit.configure exclude: :pending, trace: true
ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)

defmodule AnagramTest do
use ExUnit.Case

# @tag :pending
test "no matches" do
matches = Anagram.match "diaper", ["hello", "world", "zombies", "pants"]
matches = Anagram.match("diaper", ["hello", "world", "zombies", "pants"])
assert matches == []
end

@tag :pending
test "detect simple anagram" do
matches = Anagram.match "ant", ["tan", "stand", "at"]
matches = Anagram.match("ant", ["tan", "stand", "at"])
assert matches == ["tan"]
end

@tag :pending
test "detect multiple anagrams" do
matches = Anagram.match "master", ["stream", "pigeon", "maters"]
matches = Anagram.match("master", ["stream", "pigeon", "maters"])
assert matches == ["stream", "maters"]
end

@tag :pending
test "do not detect anagram subsets" do
matches = Anagram.match "good", ~w(dog goody)
matches = Anagram.match("good", ~w(dog goody))
assert matches == []
end

@tag :pending
test "detect anagram" do
matches = Anagram.match "listen", ~w(enlists google inlets banana)
matches = Anagram.match("listen", ~w(enlists google inlets banana))
assert matches == ["inlets"]
end

@tag :pending
test "multiple anagrams" do
matches = Anagram.match "allergy", ~w(gallery ballerina regally clergy largely leading)
matches = Anagram.match("allergy", ~w(gallery ballerina regally clergy largely leading))
assert matches == ["gallery", "regally", "largely"]
end

@tag :pending
test "anagrams must use all letters exactly once" do
matches = Anagram.match "patter", ["tapper"]
matches = Anagram.match("patter", ["tapper"])
assert matches == []
end

@tag :pending
test "detect anagrams with case-insensitive subject" do
matches = Anagram.match "Orchestra", ~w(cashregister carthorse radishes)
matches = Anagram.match("Orchestra", ~w(cashregister carthorse radishes))
assert matches == ["carthorse"]
end

@tag :pending
test "detect anagrams with case-insensitive candidate" do
matches = Anagram.match "orchestra", ~w(cashregister Carthorse radishes)
matches = Anagram.match("orchestra", ~w(cashregister Carthorse radishes))
assert matches == ["Carthorse"]
end

@tag :pending
test "anagrams must not be the source word" do
matches = Anagram.match "corn", ["corn", "dark", "Corn", "rank", "CORN", "cron", "park"]
matches = Anagram.match("corn", ["corn", "dark", "Corn", "rank", "CORN", "cron", "park"])
assert matches == ["cron"]
end

@tag :pending
test "do not detect words based on checksum" do
matches = Anagram.match "mass", ["last"]
matches = Anagram.match("mass", ["last"])
assert matches == []
end
end
3 changes: 2 additions & 1 deletion exercises/anagram/example.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ defmodule Anagram do
Comparison is case insensitive.
"""
@spec match(String.t, [String.t]) :: [String.t]
@spec match(String.t(), [String.t()]) :: [String.t()]
def match(target, words) do
lc_target = String.downcase(target)
sorted_target = sort(lc_target)

Enum.filter(words, fn word ->
lc_word = String.downcase(word)
# `and` is shortcutting
Expand Down
4 changes: 2 additions & 2 deletions exercises/atbash-cipher/atbash_cipher.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ defmodule Atbash do
iex> Atbash.encode("completely insecure")
"xlnko vgvob rmhvx fiv"
"""
@spec encode(String.t) :: String.t
@spec encode(String.t()) :: String.t()
def encode(plaintext) do
end

@spec decode(String.t) :: String.t
@spec decode(String.t()) :: String.t()
def decode(cipher) do
end
end
4 changes: 2 additions & 2 deletions exercises/atbash-cipher/atbash_cipher_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
Code.load_file("atbash_cipher.exs", __DIR__)
end

ExUnit.start
ExUnit.configure exclude: :pending, trace: true
ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)

defmodule AtbashTest do
use ExUnit.Case
Expand Down
15 changes: 10 additions & 5 deletions exercises/bank-account/bank_account_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
Code.load_file("account.exs", __DIR__)
end

ExUnit.start
ExUnit.configure exclude: :pending, trace: true
ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)

# The BankAccount module should support four calls:
#
Expand All @@ -26,8 +26,8 @@ defmodule BankAccountTest do
use ExUnit.Case

setup do
account = BankAccount.open_bank
{ :ok, account: account }
account = BankAccount.open_bank()
{:ok, account: account}
end

# @tag :pending
Expand Down Expand Up @@ -59,18 +59,23 @@ defmodule BankAccountTest do
end

@tag :pending
test "incrementing balance from another process then checking it from test process", %{account: account} do
test "incrementing balance from another process then checking it from test process", %{
account: account
} do
assert BankAccount.balance(account) == 0
this = self()

spawn(fn ->
BankAccount.update(account, 20)
send(this, :continue)
end)

receive do
:continue -> :ok
after
1000 -> flunk("Timeout")
end

assert BankAccount.balance(account) == 20
end
end
Loading

0 comments on commit 771a49c

Please sign in to comment.