Refactor Tracker get/0 and summarize/0

This commit is contained in:
Jay Hayes
2016-04-26 18:16:17 -05:00
parent 93c41d6ced
commit 814d3db995
3 changed files with 7 additions and 7 deletions

View File

@@ -23,7 +23,7 @@ defmodule Display do
def show_failure(failure, module, name) do def show_failure(failure, module, name) do
IO.puts("Now meditate upon #{format_module(module)}") IO.puts("Now meditate upon #{format_module(module)}")
IO.puts(progress_bar(Tracker.get)) IO.puts(progress_bar(Tracker.summarize))
IO.puts(bar()) IO.puts(bar())
IO.puts(name) IO.puts(name)
IO.puts(format_failure(failure)) IO.puts(format_failure(failure))

View File

@@ -10,7 +10,6 @@ defmodule Tracker do
def get do def get do
Agent.get(__MODULE__, &(&1)) Agent.get(__MODULE__, &(&1))
|> summarize
end end
def completed(koan) do def completed(koan) do
@@ -20,11 +19,12 @@ defmodule Tracker do
end end
def complete? do def complete? do
{total, completed} = Agent.get(__MODULE__, &(&1)) {total, completed} = get
total == Enum.count(completed) total == Enum.count(completed)
end end
def summarize({total, completed}) do def summarize, do: get |> summarize
defp summarize({total, completed}) do
%{total: total, current: MapSet.size(completed)} %{total: total, current: MapSet.size(completed)}
end end
end end

View File

@@ -5,19 +5,19 @@ defmodule TrackerTest do
test "can start" do test "can start" do
Tracker.start(@sample_modules) Tracker.start(@sample_modules)
assert Tracker.get == %{total: 2, current: 0} assert Tracker.summarize == %{total: 2, current: 0}
end end
test "can be notified of completed koans" do test "can be notified of completed koans" do
Tracker.start(@sample_modules) Tracker.start(@sample_modules)
Tracker.completed(:"Hi there") Tracker.completed(:"Hi there")
assert Tracker.get == %{total: 2, current: 1} assert Tracker.summarize == %{total: 2, current: 1}
end end
test "multiple comletions of the same koan count only once" do test "multiple comletions of the same koan count only once" do
Tracker.start(@sample_modules) Tracker.start(@sample_modules)
Tracker.completed(:"Hi there") Tracker.completed(:"Hi there")
Tracker.completed(:"Hi there") Tracker.completed(:"Hi there")
assert Tracker.get == %{total: 2, current: 1} assert Tracker.summarize == %{total: 2, current: 1}
end end
end end