Created
June 1, 2020 20:28
-
-
Save josefrichter/da3e93fcf6d77c509d06b9eba305aa5d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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