about summary refs log tree commit diff
path: root/assessments
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-12-12T02·41+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-12-12T02·43+0000
commit45877a8b9cbe728e2dd66c361b3d6625810b31a0 (patch)
tree5815e41b9ca6b20e7e2a3733fe479d1c5307ccde /assessments
parent1a404a58de82fd73b22df57857bf29fb44ce40b3 (diff)
Include cache hit/miss info in return type
This can be useful downstream for diagnostics.
Diffstat (limited to 'assessments')
-rw-r--r--assessments/semiprimes/server/lib/server.ex4
-rw-r--r--assessments/semiprimes/server/test/server_test.exs3
2 files changed, 4 insertions, 3 deletions
diff --git a/assessments/semiprimes/server/lib/server.ex b/assessments/semiprimes/server/lib/server.ex
index c4088fb20ab5..7ab5e905b5a0 100644
--- a/assessments/semiprimes/server/lib/server.ex
+++ b/assessments/semiprimes/server/lib/server.ex
@@ -16,11 +16,11 @@ defmodule Server do
 
           res ->
             Cache.put(n, res)
-            res
+            {:miss, res}
         end
 
       hit ->
-        hit
+        {:hit, hit}
     end
   end
 
diff --git a/assessments/semiprimes/server/test/server_test.exs b/assessments/semiprimes/server/test/server_test.exs
index f327efb33abb..08d559734b5a 100644
--- a/assessments/semiprimes/server/test/server_test.exs
+++ b/assessments/semiprimes/server/test/server_test.exs
@@ -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