Exemplo n.º 1
0
 def test_multiple_steps(self):
     operators = [AddOperator(1), MultiplyOperator(20), DivideOperator(3)]
     problem = Problem(start_number=2,
                       end_number=1,
                       move_count=2,
                       operators=operators)
     solution = random_solve(problem)
     self.assertEqual(solution, [AddOperator(1), DivideOperator(3)])
Exemplo n.º 2
0
 def test_divide_negative(self):
     state = State(current_number=24)
     state.apply(DivideOperator(-3))
     self.assertEqual(state.current_number, -8)
Exemplo n.º 3
0
 def test_positive_good_fraction(self):
     state = State(current_number=1)
     state.apply(DivideOperator(8))
     self.assertEqual(state.current_number, 0.125)
Exemplo n.º 4
0
 def test_divide_positive(self):
     state = State(current_number=50)
     state.apply(DivideOperator(5))
     self.assertEqual(state.current_number, 10)
Exemplo n.º 5
0
 def test_str_negative(self):
     string = str(DivideOperator(-7))
     self.assertEqual(string, "[ / -7 ]")
Exemplo n.º 6
0
 def test_str_positive(self):
     string = str(DivideOperator(2))
     self.assertEqual(string, "[ / 2 ]")
Exemplo n.º 7
0
 def test_negative_bad_fraction(self):
     state = State(current_number=-1)
     with self.assertRaises(ValueError):
         state.apply(DivideOperator(16))
Exemplo n.º 8
0
 def test_positive_bad_fraction(self):
     state = State(current_number=100)
     with self.assertRaises(ValueError):
         state.apply(DivideOperator(3))