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