Commit 8b91d4f

mo <mokha@cisco.com>
2017-07-05 01:30:30
try to figure out why the last hidden test is failing.
1 parent 4cb8af9
Changed files (1)
spec/is_crypt_solution_spec.rb
@@ -72,7 +72,9 @@ Return true if the solution represents the correct solution to the cryptarithm c
 DOC
 
 describe "#is_crypt_solution" do
-  def is_crypt_solution(crypt, solution)
+  def crypt_solution?(crypt, solution)
+    return false if solution.empty?
+
     mapping = solution.to_h
     decoded = crypt.map do |word|
       word.chars.map { |x| mapping[x] }.join
@@ -81,7 +83,8 @@ describe "#is_crypt_solution" do
         (decoded[1].size > 1 && decoded[1][0] == "0")
       return false
     end
-    decoded[0].to_i + decoded[1].to_i == decoded[2].to_i
+    sum = decoded[0].to_i + decoded[1].to_i
+    sum == decoded[2].to_i
   end
 
   [
@@ -95,9 +98,12 @@ describe "#is_crypt_solution" do
     { crypt: ["A", "A", "A"], solution: [["A","1"]], x: false },
     { crypt: ["AA", "AA", "BB"], solution: [["A","1"], ["B","2"]], x: true },
     { crypt: ["BAA", "CAB", "DAB"], solution: [["A","0"], ["B","1"], ["C","2"], ["D","4"]], x: false },
+    { crypt: ["A", "A", "A"], solution: [], x: false },
+    { crypt: ["A" * 13, "A" * 13, "Z" * 13], solution: [["A", "1"], ["Z", "2"]], x: true },
+    { crypt: ["A" * 13, "Z", "Z" + ("B" * 13)], solution: [["A", "9"], ["B", "0"], ["Z", "1"]], x: true },
   ].each do |x|
     it do
-      expect(is_crypt_solution(x[:crypt], x[:solution])).to eql(x[:x])
+      expect(crypt_solution?(x[:crypt], x[:solution])).to eql(x[:x])
     end
   end
 end