Skip to content

Commit 771a49c

Browse files
sotojuandevonestes
authored andcommitted
Run mix format (exercism#391)
Closes exercism#387.
1 parent 74e2383 commit 771a49c

File tree

247 files changed

+2619
-2355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+2619
-2355
lines changed

.formatter.exs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
inputs: ["mix.exs", "{exercises}/**/*.{ex,exs}"]
3+
]

exercises/accumulate/accumulate_test.exs

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
22
Code.load_file("accumulate.exs", __DIR__)
33
end
44

5-
ExUnit.start
6-
ExUnit.configure exclude: :pending, trace: true
5+
ExUnit.start()
6+
ExUnit.configure(exclude: :pending, trace: true)
77

88
defmodule AccumulateTest do
99
use ExUnit.Case
1010

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

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

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

2626
@tag :pending
2727
test "accumulate reversed strings" do
28-
fun = fn(w) -> String.reverse(w) end
28+
fun = fn w -> String.reverse(w) end
2929
words = ~w(the quick brown fox etc)
3030
expected = ["eht", "kciuq", "nworb", "xof", "cte"]
3131
assert Accumulate.accumulate(words, fun) == expected
@@ -34,8 +34,8 @@ defmodule AccumulateTest do
3434
@tag :pending
3535
test "nested accumulate" do
3636
chars = ~w(a b c)
37-
nums = ~w(1 2 3)
38-
fun = fn(c) -> Accumulate.accumulate(nums, &(c <> &1)) end
37+
nums = ~w(1 2 3)
38+
fun = fn c -> Accumulate.accumulate(nums, &(c <> &1)) end
3939
expected = [["a1", "a2", "a3"], ["b1", "b2", "b3"], ["c1", "c2", "c3"]]
4040
assert Accumulate.accumulate(chars, fun) == expected
4141
end

exercises/acronym/acronym_test.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
22
Code.load_file("acronym.exs", __DIR__)
33
end
44

5-
ExUnit.start
6-
ExUnit.configure exclude: :pending, trace: true
5+
ExUnit.start()
6+
ExUnit.configure(exclude: :pending, trace: true)
77

88
defmodule AcronymTest do
99
use ExUnit.Case

exercises/acronym/example.exs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
defmodule Acronym do
2-
32
@spec abbreviate(String.t()) :: String.t()
43
def abbreviate(string) do
54
Regex.scan(~r/[A-Z]+[a-z]*|[a-z]+/, string)
6-
|> List.flatten
7-
|> Enum.map(fn(x) -> String.first(x) end)
5+
|> List.flatten()
6+
|> Enum.map(fn x -> String.first(x) end)
87
|> Enum.join("")
9-
|> String.upcase
8+
|> String.upcase()
109
end
1110
end

exercises/all-your-base/all-your-base-test.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
22
Code.load_file("all-your-base.exs", __DIR__)
33
end
44

5-
ExUnit.start
6-
ExUnit.configure exclude: :pending, trace: true
5+
ExUnit.start()
6+
ExUnit.configure(exclude: :pending, trace: true)
77

88
defmodule AllYourBaseTest do
99
use ExUnit.Case

exercises/all-your-base/example.exs

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
defmodule AllYourBase do
2-
32
@doc """
43
Given a number in base a, represented as a sequence of digits, converts it to base b,
54
or returns nil if either of the bases are less than 2
@@ -8,27 +7,35 @@ defmodule AllYourBase do
87
@spec convert(list, integer, integer) :: list
98
def convert(digits, base_a, base_b) do
109
cond do
11-
base_a > 1 and base_b > 1 and digits !=[] ->
10+
base_a > 1 and base_b > 1 and digits != [] ->
1211
do_convert(digits, base_a, base_b)
12+
1313
true ->
1414
nil
1515
end
1616
end
1717

1818
defp do_convert(digits, base_a, base_b) do
1919
num = convert_to_num(digits, base_a, 0)
20+
2021
case num do
21-
nil -> nil
22-
0 -> [0]
23-
num -> convert_to_digits(num, base_b, [])
24-
|> Enum.reverse
22+
nil ->
23+
nil
24+
25+
0 ->
26+
[0]
27+
28+
num ->
29+
convert_to_digits(num, base_b, [])
30+
|> Enum.reverse()
2531
end
2632
end
2733

2834
defp convert_to_num([head | tail], base_a, accumulator) do
2935
cond do
3036
head < base_a and head >= 0 ->
31-
convert_to_num(tail, base_a, accumulator * base_a + head)
37+
convert_to_num(tail, base_a, accumulator * base_a + head)
38+
3239
true ->
3340
nil
3441
end

exercises/allergies/allergies.exs

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ defmodule Allergies do
22
@doc """
33
List the allergies for which the corresponding flag bit is true.
44
"""
5-
@spec list(non_neg_integer) :: [String.t]
5+
@spec list(non_neg_integer) :: [String.t()]
66
def list(flags) do
7-
87
end
98

109
@doc """
1110
Returns whether the corresponding flag bit in 'flags' is set for the item.
1211
"""
13-
@spec allergic_to?(non_neg_integer, String.t) :: boolean
12+
@spec allergic_to?(non_neg_integer, String.t()) :: boolean
1413
def allergic_to?(flags, item) do
15-
1614
end
1715
end

exercises/allergies/allergies_test.exs

+17-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
22
Code.load_file("allergies.exs", __DIR__)
33
end
44

5-
6-
ExUnit.start
7-
ExUnit.configure exclude: :pending, trace: true
5+
ExUnit.start()
6+
ExUnit.configure(exclude: :pending, trace: true)
87

98
defmodule AllergiesTest do
109
use ExUnit.Case
@@ -41,12 +40,16 @@ defmodule AllergiesTest do
4140

4241
@tag :pending
4342
test "allergic_to_lots_of_stuff" do
44-
Allergies.list(248) |> assert_is_a_set_containing(~w[strawberries tomatoes chocolate pollen cats])
43+
Allergies.list(248)
44+
|> assert_is_a_set_containing(~w[strawberries tomatoes chocolate pollen cats])
4545
end
4646

4747
@tag :pending
4848
test "allergic_to_everything" do
49-
Allergies.list(255) |> assert_is_a_set_containing(~w[eggs peanuts shellfish strawberries tomatoes chocolate pollen cats])
49+
Allergies.list(255)
50+
|> assert_is_a_set_containing(
51+
~w[eggs peanuts shellfish strawberries tomatoes chocolate pollen cats]
52+
)
5053
end
5154

5255
@tag :pending
@@ -68,16 +71,19 @@ defmodule AllergiesTest do
6871

6972
@tag :pending
7073
test "ignore_non_allergen_score_parts" do
71-
Allergies.list(509) |> assert_is_a_set_containing(~w[eggs shellfish strawberries tomatoes chocolate pollen cats])
74+
Allergies.list(509)
75+
|> assert_is_a_set_containing(~w[eggs shellfish strawberries tomatoes chocolate pollen cats])
7276
end
7377

7478
defp assert_is_a_set_containing(list, to_contain) do
75-
set = Enum.into(list, MapSet.new)
76-
same_contents = to_contain
77-
|> Enum.into(MapSet.new)
79+
set = Enum.into(list, MapSet.new())
80+
81+
same_contents =
82+
to_contain
83+
|> Enum.into(MapSet.new())
7884
|> MapSet.equal?(set)
85+
7986
assert same_contents,
80-
"Expected a set with: #{inspect to_contain} got #{inspect set |> MapSet.to_list}"
87+
"Expected a set with: #{inspect(to_contain)} got #{inspect(set |> MapSet.to_list())}"
8188
end
82-
8389
end

exercises/anagram/anagram.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ defmodule Anagram do
22
@doc """
33
Returns all candidates that are anagrams of, but not equal to, 'base'.
44
"""
5-
@spec match(String.t, [String.t]) :: [String.t]
5+
@spec match(String.t(), [String.t()]) :: [String.t()]
66
def match(base, candidates) do
7-
87
end
98
end

exercises/anagram/anagram_test.exs

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,75 +2,75 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
22
Code.load_file("anagram.exs", __DIR__)
33
end
44

5-
ExUnit.start
6-
ExUnit.configure exclude: :pending, trace: true
5+
ExUnit.start()
6+
ExUnit.configure(exclude: :pending, trace: true)
77

88
defmodule AnagramTest do
99
use ExUnit.Case
1010

1111
# @tag :pending
1212
test "no matches" do
13-
matches = Anagram.match "diaper", ["hello", "world", "zombies", "pants"]
13+
matches = Anagram.match("diaper", ["hello", "world", "zombies", "pants"])
1414
assert matches == []
1515
end
1616

1717
@tag :pending
1818
test "detect simple anagram" do
19-
matches = Anagram.match "ant", ["tan", "stand", "at"]
19+
matches = Anagram.match("ant", ["tan", "stand", "at"])
2020
assert matches == ["tan"]
2121
end
2222

2323
@tag :pending
2424
test "detect multiple anagrams" do
25-
matches = Anagram.match "master", ["stream", "pigeon", "maters"]
25+
matches = Anagram.match("master", ["stream", "pigeon", "maters"])
2626
assert matches == ["stream", "maters"]
2727
end
2828

2929
@tag :pending
3030
test "do not detect anagram subsets" do
31-
matches = Anagram.match "good", ~w(dog goody)
31+
matches = Anagram.match("good", ~w(dog goody))
3232
assert matches == []
3333
end
3434

3535
@tag :pending
3636
test "detect anagram" do
37-
matches = Anagram.match "listen", ~w(enlists google inlets banana)
37+
matches = Anagram.match("listen", ~w(enlists google inlets banana))
3838
assert matches == ["inlets"]
3939
end
4040

4141
@tag :pending
4242
test "multiple anagrams" do
43-
matches = Anagram.match "allergy", ~w(gallery ballerina regally clergy largely leading)
43+
matches = Anagram.match("allergy", ~w(gallery ballerina regally clergy largely leading))
4444
assert matches == ["gallery", "regally", "largely"]
4545
end
4646

4747
@tag :pending
4848
test "anagrams must use all letters exactly once" do
49-
matches = Anagram.match "patter", ["tapper"]
49+
matches = Anagram.match("patter", ["tapper"])
5050
assert matches == []
5151
end
5252

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

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

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

7171
@tag :pending
7272
test "do not detect words based on checksum" do
73-
matches = Anagram.match "mass", ["last"]
73+
matches = Anagram.match("mass", ["last"])
7474
assert matches == []
7575
end
7676
end

exercises/anagram/example.exs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ defmodule Anagram do
44
55
Comparison is case insensitive.
66
"""
7-
@spec match(String.t, [String.t]) :: [String.t]
7+
@spec match(String.t(), [String.t()]) :: [String.t()]
88
def match(target, words) do
99
lc_target = String.downcase(target)
1010
sorted_target = sort(lc_target)
11+
1112
Enum.filter(words, fn word ->
1213
lc_word = String.downcase(word)
1314
# `and` is shortcutting

exercises/atbash-cipher/atbash_cipher.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ defmodule Atbash do
77
iex> Atbash.encode("completely insecure")
88
"xlnko vgvob rmhvx fiv"
99
"""
10-
@spec encode(String.t) :: String.t
10+
@spec encode(String.t()) :: String.t()
1111
def encode(plaintext) do
1212
end
1313

14-
@spec decode(String.t) :: String.t
14+
@spec decode(String.t()) :: String.t()
1515
def decode(cipher) do
1616
end
1717
end

exercises/atbash-cipher/atbash_cipher_test.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
22
Code.load_file("atbash_cipher.exs", __DIR__)
33
end
44

5-
ExUnit.start
6-
ExUnit.configure exclude: :pending, trace: true
5+
ExUnit.start()
6+
ExUnit.configure(exclude: :pending, trace: true)
77

88
defmodule AtbashTest do
99
use ExUnit.Case

exercises/bank-account/bank_account_test.exs

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
22
Code.load_file("account.exs", __DIR__)
33
end
44

5-
ExUnit.start
6-
ExUnit.configure exclude: :pending, trace: true
5+
ExUnit.start()
6+
ExUnit.configure(exclude: :pending, trace: true)
77

88
# The BankAccount module should support four calls:
99
#
@@ -26,8 +26,8 @@ defmodule BankAccountTest do
2626
use ExUnit.Case
2727

2828
setup do
29-
account = BankAccount.open_bank
30-
{ :ok, account: account }
29+
account = BankAccount.open_bank()
30+
{:ok, account: account}
3131
end
3232

3333
# @tag :pending
@@ -59,18 +59,23 @@ defmodule BankAccountTest do
5959
end
6060

6161
@tag :pending
62-
test "incrementing balance from another process then checking it from test process", %{account: account} do
62+
test "incrementing balance from another process then checking it from test process", %{
63+
account: account
64+
} do
6365
assert BankAccount.balance(account) == 0
6466
this = self()
67+
6568
spawn(fn ->
6669
BankAccount.update(account, 20)
6770
send(this, :continue)
6871
end)
72+
6973
receive do
7074
:continue -> :ok
7175
after
7276
1000 -> flunk("Timeout")
7377
end
78+
7479
assert BankAccount.balance(account) == 20
7580
end
7681
end

0 commit comments

Comments
 (0)