Include cache hit/miss info in return type

This can be useful downstream for diagnostics.
This commit is contained in:
William Carroll 2020-12-12 02:41:42 +00:00
parent 1a404a58de
commit 45877a8b9c
2 changed files with 4 additions and 3 deletions

View file

@ -16,11 +16,11 @@ defmodule Server do
res ->
Cache.put(n, res)
res
{:miss, res}
end
hit ->
hit
{:hit, hit}
end
end

View file

@ -4,6 +4,7 @@ defmodule ServerTest do
describe "semiprime" do
test "returns the factors when the number is semiprime" do
Cache.clear()
# Semiprimes below 30
[
{4, [2, 2]},
@ -18,7 +19,7 @@ defmodule ServerTest do
{26, [2, 13]}
]
|> Enum.each(fn {input, expected} ->
assert Server.semiprime(input) == expected
assert Server.semiprime(input) == {:miss, expected}
end)
end