Skip to content

Instantly share code, notes, and snippets.

@josefrichter
Created June 1, 2020 20:28
Show Gist options
  • Save josefrichter/da3e93fcf6d77c509d06b9eba305aa5d to your computer and use it in GitHub Desktop.
Save josefrichter/da3e93fcf6d77c509d06b9eba305aa5d to your computer and use it in GitHub Desktop.
defmodule Tester do
def start_run do
Agent.start(fn -> [total: 0, passed: 0, failed: 0] end, name: :test_stats)
end
def record_pass do
Agent.update(:test_stats, fn [total: t, passed: p, failed: f] ->
[total: t + 1, passed: p + 1, failed: f]
end)
end
def record_fail do
Agent.update(:test_stats, fn [total: t, passed: p, failed: f] ->
[total: t + 1, passed: p, failed: f + 1]
end)
end
def report_results do
stats = Agent.get(:test_stats, &(&1))
IO.inspect stats
Agent.stop(:test_stats)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment