noahsettersten
commited on
Commit
•
29c5ebd
1
Parent(s):
3a052af
test: Add tests for MedicalTranscription.Utilities
Browse files
lib/medical_transcription/utilities.ex
CHANGED
@@ -14,6 +14,7 @@ defmodule MedicalTranscription.Utilities do
|
|
14 |
end)
|
15 |
end
|
16 |
|
|
|
17 |
def tally_to_string(tallied_enumerable) do
|
18 |
tallied_enumerable
|
19 |
|> Enum.map_join(", ", fn {key, value} -> "#{key} (#{value})" end)
|
|
|
14 |
end)
|
15 |
end
|
16 |
|
17 |
+
@doc "Takes the output of `tally/1` and returns a string representation."
|
18 |
def tally_to_string(tallied_enumerable) do
|
19 |
tallied_enumerable
|
20 |
|> Enum.map_join(", ", fn {key, value} -> "#{key} (#{value})" end)
|
test/medical_transcription/utilities_test.exs
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
defmodule MedicalTranscription.UtilitiesTest do
|
2 |
+
use ExUnit.Case, async: true
|
3 |
+
alias MedicalTranscription.Utilities
|
4 |
+
|
5 |
+
describe "tally/1" do
|
6 |
+
test "it counts elements in an enumerable of atoms" do
|
7 |
+
input = [:one, :two, :three, :two, :two, :one]
|
8 |
+
|
9 |
+
assert Utilities.tally(input) == %{
|
10 |
+
one: 2,
|
11 |
+
two: 3,
|
12 |
+
three: 1
|
13 |
+
}
|
14 |
+
end
|
15 |
+
end
|
16 |
+
|
17 |
+
describe "tally_to_string/1" do
|
18 |
+
test "it formats a string version of the output of `tally/1`" do
|
19 |
+
input = %{
|
20 |
+
one: 2,
|
21 |
+
two: 3,
|
22 |
+
three: 1
|
23 |
+
}
|
24 |
+
|
25 |
+
assert Utilities.tally_to_string(input) == "one (2), two (3), three (1)"
|
26 |
+
end
|
27 |
+
end
|
28 |
+
end
|