Refactor Tracker get/0 and summarize/0
This commit is contained in:
@@ -23,7 +23,7 @@ defmodule Display do
|
||||
|
||||
def show_failure(failure, module, name) do
|
||||
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(name)
|
||||
IO.puts(format_failure(failure))
|
||||
|
@@ -10,7 +10,6 @@ defmodule Tracker do
|
||||
|
||||
def get do
|
||||
Agent.get(__MODULE__, &(&1))
|
||||
|> summarize
|
||||
end
|
||||
|
||||
def completed(koan) do
|
||||
@@ -20,11 +19,12 @@ defmodule Tracker do
|
||||
end
|
||||
|
||||
def complete? do
|
||||
{total, completed} = Agent.get(__MODULE__, &(&1))
|
||||
{total, completed} = get
|
||||
total == Enum.count(completed)
|
||||
end
|
||||
|
||||
def summarize({total, completed}) do
|
||||
def summarize, do: get |> summarize
|
||||
defp summarize({total, completed}) do
|
||||
%{total: total, current: MapSet.size(completed)}
|
||||
end
|
||||
end
|
||||
|
@@ -5,19 +5,19 @@ defmodule TrackerTest do
|
||||
|
||||
test "can start" do
|
||||
Tracker.start(@sample_modules)
|
||||
assert Tracker.get == %{total: 2, current: 0}
|
||||
assert Tracker.summarize == %{total: 2, current: 0}
|
||||
end
|
||||
|
||||
test "can be notified of completed koans" do
|
||||
Tracker.start(@sample_modules)
|
||||
Tracker.completed(:"Hi there")
|
||||
assert Tracker.get == %{total: 2, current: 1}
|
||||
assert Tracker.summarize == %{total: 2, current: 1}
|
||||
end
|
||||
|
||||
test "multiple comletions of the same koan count only once" do
|
||||
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
|
||||
|
Reference in New Issue
Block a user