Commit 292339b

mo khan <mo@mokhan.ca>
2014-04-26 15:44:20
always sort the operands for grade two level.
1 parent d8f8838
Changed files (2)
lib
mathy
difficulties
operations
lib/mathy/difficulties/grade_two.rb
@@ -2,7 +2,7 @@ module Mathy
   module Difficulties
     class GradeTwo
       def next_operands
-        [rand(20), rand(10)]
+        [rand(20), rand(20)].sort.reverse
       end
     end
   end
lib/mathy/operations/subtraction.rb
@@ -8,14 +8,21 @@ module Mathy
         @key = "-"
       end
 
-      def play_turn(difficulty)
-        operands = difficulty.next_operands
-        @verifier.check_answer("#{operands.join(" - ")} = ", operands.inject() { |result, x| result - x })
+      def play_turn(operands)
+        @verifier.check_answer("#{operands.join(" #{key} ")} = ", calculate(operands))
       end
 
       def matches?(other_key)
         key == other_key
       end
+
+      private
+
+      def calculate(operands)
+        operands.inject(0) do |result, x|
+          result + x
+        end
+      end
     end
   end
 end