Пример #1
0
 def test_user_defined_words_are_case_insensitive(self):
     input_data = [
         ": foo dup ;",
         "1 FOO Foo foo"
     ]
     expected = [1, 1, 1, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #2
0
 def test_definitions_are_case_insensitive(self):
     input_data = [
         ": SWAP DUP Dup dup ;",
         "1 swap"
     ]
     expected = [1, 1, 1, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #3
0
 def test_can_consist_of_built_in_words(self):
     input_data = [
         ": dup-twice dup dup ;",
         "1 dup-twice"
     ]
     expected = [1, 1, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #4
0
 def test_can_override_built_in_words(self):
     input_data = [
         ": swap dup ;",
         "1 swap"
     ]
     expected = [1, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #5
0
 def test_can_override_built_in_operators(self):
     input_data = [
         ": + * ;",
         "3 4 +"
     ]
     expected = [12]
     self.assertEqual(evaluate(input_data), expected)
Пример #6
0
 def test_execute_in_the_right_order(self):
     input_data = [
         ": countup 1 2 3 ;",
         "countup"
     ]
     expected = [1, 2, 3]
     self.assertEqual(evaluate(input_data), expected)
Пример #7
0
 def test_can_override_other_user_defined_words(self):
     input_data = [
         ": foo dup ;",
         ": foo dup dup ;",
         "1 foo"
     ]
     expected = [1, 1, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #8
0
 def test_can_define_word_that_uses_word_with_same_name(self):
     input_data = [
         ": foo 10 ;",
         ": foo foo 1 + ;",
         "foo"
     ]
     expected = [11]
     self.assertEqual(evaluate(input_data), expected)
Пример #9
0
 def test_can_use_different_words_with_same_name(self):
     input_data = [
         ": foo 5 ;",
         ": bar foo ;",
         ": foo 6 ;",
         "bar foo"
     ]
     expected = [5, 6]
     self.assertEqual(evaluate(input_data), expected)
Пример #10
0
 def test_cannot_redefine_numbers(self):
     input_data = [": 1 2 ;"]
     with self.assertRaisesWithMessage(ValueError):
         evaluate(input_data)
Пример #11
0
 def test_removes_the_top_value_on_the_stack_if_it_not_the_only_one(self):
     input_data = ["3 4 drop"]
     expected = [3]
     self.assertEqual(evaluate(input_data), expected)
Пример #12
0
 def test_execute_in_the_right_order(self):
     input_data = [": countup 1 2 3 ;", "countup"]
     expected = [1, 2, 3]
     self.assertEqual(evaluate(input_data), expected)
Пример #13
0
 def test_can_override_built_in_words(self):
     input_data = [": swap dup ;", "1 swap"]
     expected = [1, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #14
0
 def test_swaps_two_two_values_on_stack(self):
     input_data = ["1 2 3 SWAP"]
     expected = [1, 3, 2]
     self.assertEqual(evaluate(input_data), expected)
Пример #15
0
 def test_errors_if_there_is_nothing_on_the_stack(self):
     input_data = ["over"]
     with self.assertRaisesWithMessage(StackUnderflowError):
         evaluate(input_data)
Пример #16
0
 def test_multiplication_and_division(self):
     input_data = ["2 4 * 3 /"]
     expected = [2]
     self.assertEqual(evaluate(input_data), expected)
Пример #17
0
 def test_can_add_two_numbers(self):
     input_data = ["1 2 +"]
     expected = [3]
     self.assertEqual(evaluate(input_data), expected)
Пример #18
0
 def test_errors_if_there_is_only_one_value_on_the_stack(self):
     input_data = ["1 *"]
     with self.assertRaisesWithMessage(StackUnderflowError):
         evaluate(input_data)
Пример #19
0
 def test_errors_if_there_is_nothing_on_the_stack(self):
     with self.assertRaisesWithMessage(StackUnderflowError):
         evaluate(["drop"])
Пример #20
0
 def test_user_defined_words_are_case_insensitive(self):
     input_data = [": foo dup ;", "1 FOO Foo foo"]
     expected = [1, 1, 1, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #21
0
 def test_swaps_two_two_values_on_stack(self):
     input_data = ["1 2 3 swap"]
     expected = [1, 3, 2]
     self.assertEqual(evaluate(input_data), expected)
Пример #22
0
 def test_copies_the_second_element_if_there_are_more_than_two(self):
     input_data = ["1 2 3 over"]
     expected = [1, 2, 3, 2]
     self.assertEqual(evaluate(input_data), expected)
Пример #23
0
 def test_errors_if_there_is_nothing_on_the_stack(self):
     input_data = ["over"]
     with self.assertRaisesWithMessage(StackUnderflowError):
         evaluate(input_data)
Пример #24
0
 def test_numbers_just_get_pushed_to_stack(self):
     input_data = ["1 2 3 4 5"]
     expected = [1, 2, 3, 4, 5]
     self.assertEqual(evaluate(input_data), expected)
Пример #25
0
 def test_can_subtract_two_numbers(self):
     input_data = ["3 4 -"]
     expected = [-1]
     self.assertEqual(evaluate(input_data), expected)
Пример #26
0
 def test_cannot_redefine_numbers(self):
     input_data = [": 1 2 ;"]
     with self.assertRaisesWithMessage(ValueError):
         evaluate(input_data)
Пример #27
0
 def test_can_divide_two_numbers(self):
     input_data = ["12 3 /"]
     expected = [4]
     self.assertEqual(evaluate(input_data), expected)
Пример #28
0
 def test_errors_if_executing_a_non_existent_word(self):
     input_data = ["foo"]
     with self.assertRaisesWithMessage(ValueError):
         evaluate(input_data)
Пример #29
0
 def test_errors_if_there_is_only_one_value_on_the_stack(self):
     with self.assertRaisesWithMessage(StackUnderflowError):
         evaluate(["1 swap"])
Пример #30
0
 def test_dup_is_case_insensitive(self):
     input_data = ["1 DUP Dup dup"]
     expected = [1, 1, 1, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #31
0
 def test_copies_the_top_value_on_the_stack(self):
     input_data = ["1 2 dup"]
     expected = [1, 2, 2]
     self.assertEqual(evaluate(input_data), expected)
Пример #32
0
 def test_can_add_two_numbers(self):
     input_data = ["1 2 +"]
     expected = [3]
     self.assertEqual(evaluate(input_data), expected)
Пример #33
0
 def test_removes_the_top_value_on_the_stack_if_it_not_the_only_one(self):
     input_data = ["3 4 DROP"]
     expected = [3]
     self.assertEqual(evaluate(input_data), expected)
Пример #34
0
 def test_drop_is_case_insensitive(self):
     input_data = ["1 2 3 4 DROP Drop drop"]
     expected = [1]
     self.assertEqual(evaluate(input_data), expected)
Пример #35
0
 def test_copies_the_second_element_if_there_are_more_than_two(self):
     input_data = ["1 2 3 OVER"]
     expected = [1, 2, 3, 2]
     self.assertEqual(evaluate(input_data), expected)
Пример #36
0
 def test_swap_is_case_insensitive(self):
     input_data = ["1 2 SWAP 3 Swap 4 swap"]
     expected = [2, 3, 4, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #37
0
 def test_can_consist_of_built_in_words(self):
     input_data = [": dup-twice dup dup ;", "1 dup-twice"]
     expected = [1, 1, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #38
0
 def test_over_is_case_insensitive(self):
     input_data = ["1 2 OVER Over over"]
     expected = [1, 2, 1, 2, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #39
0
 def test_can_override_other_user_defined_words(self):
     input_data = [": foo dup ;", ": foo dup dup ;", "1 foo"]
     expected = [1, 1, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #40
0
 def test_dup_is_case_insensitive(self):
     input_data = ["1 DUP Dup dup"]
     expected = [1, 1, 1, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #41
0
 def test_can_override_built_in_operators(self):
     input_data = [": + * ;", "3 4 +"]
     expected = [12]
     self.assertEqual(evaluate(input_data), expected)
Пример #42
0
 def test_swap_is_case_insensitive(self):
     input_data = ["1 2 SWAP 3 Swap 4 swap"]
     expected = [2, 3, 4, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #43
0
 def test_errors_if_executing_a_non_existent_word(self):
     input_data = ["foo"]
     with self.assertRaisesWithMessage(ValueError):
         evaluate(input_data)
Пример #44
0
 def test_copies_the_top_value_on_the_stack(self):
     input_data = ["1 2 dup"]
     expected = [1, 2, 2]
     self.assertEqual(evaluate(input_data), expected)
Пример #45
0
 def test_drop_is_case_insensitive(self):
     input_data = ["1 2 3 4 DROP Drop drop"]
     expected = [1]
     self.assertEqual(evaluate(input_data), expected)
Пример #46
0
 def test_can_subtract_two_numbers(self):
     input_data = ["3 4 -"]
     expected = [-1]
     self.assertEqual(evaluate(input_data), expected)
Пример #47
0
 def test_over_is_case_insensitive(self):
     input_data = ["1 2 OVER Over over"]
     expected = [1, 2, 1, 2, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #48
0
 def test_can_multiply_two_numbers(self):
     input_data = ["2 4 *"]
     expected = [8]
     self.assertEqual(evaluate(input_data), expected)
Пример #49
0
 def test_definitions_are_case_insensitive(self):
     input_data = [": SWAP DUP Dup dup ;", "1 swap"]
     expected = [1, 1, 1, 1]
     self.assertEqual(evaluate(input_data), expected)
Пример #50
0
 def test_can_divide_two_numbers(self):
     input_data = ["12 3 /"]
     expected = [4]
     self.assertEqual(evaluate(input_data), expected)
Пример #51
0
 def test_can_multiply_two_numbers(self):
     input_data = ["2 4 *"]
     expected = [8]
     self.assertEqual(evaluate(input_data), expected)
Пример #52
0
 def test_performs_integer_division(self):
     input_data = ["8 3 /"]
     expected = [2]
     self.assertEqual(evaluate(input_data), expected)
Пример #53
0
 def test_numbers_just_get_pushed_to_stack(self):
     input_data = ["1 2 3 4 5"]
     expected = [1, 2, 3, 4, 5]
     self.assertEqual(evaluate(input_data), expected)
Пример #54
0
 def test_errors_if_dividing_by_zero(self):
     input_data = ["4 0 /"]
     with self.assertRaisesWithMessage(ZeroDivisionError):
         evaluate(input_data)
Пример #55
0
 def test_removes_the_top_value_on_the_stack_if_it_is_not_the_only_one(
         self):
     self.assertEqual(evaluate(["1 2 drop"]), [1])
Пример #56
0
 def test_errors_if_there_is_only_one_value_on_the_stack(self):
     input_data = ["1 /"]
     with self.assertRaisesWithMessage(StackUnderflowError):
         evaluate(input_data)
Пример #57
0
 def test_swaps_the_top_two_values_on_the_stack_if_they_are_not_the_only_ones(
         self):
     self.assertEqual(evaluate(["1 2 3 swap"]), [1, 3, 2])
Пример #58
0
 def test_multiplication_and_division(self):
     input_data = ["2 4 * 3 /"]
     expected = [2]
     self.assertEqual(evaluate(input_data), expected)
Пример #59
0
 def test_copies_the_second_element_if_there_are_only_two(self):
     self.assertEqual(evaluate(["1 2 over"]), [1, 2, 1])
Пример #60
0
 def test_addition_and_subtraction(self):
     input_data = ["1 2 + 4 -"]
     expected = [-1]
     self.assertEqual(evaluate(input_data), expected)