コード例 #1
0
 def test_visit_conditional_returns_FizzBuzz(self):
     interpreter = Interpreter("")
     ast_mod = ASTModulus(ASTInteger(30), ASTInteger(15))
     ast_equal = ASTEquals(ast_mod, ASTInteger(0))
     ast_echo = ASTEcho(ASTString("FizzBuzz"))
     ast_conditional = ASTConditional(ast_equal, ast_echo, "else...")
     self.assertEqual(interpreter.visit_ast_conditional(ast_conditional), "Forest says: FizzBuzz")
コード例 #2
0
 def test_interpreter_should_return_integer_when_user_enters_4(self):
     interpreter = Interpreter("echo^<<4>>")
     self.assertEqual(interpreter.response(), "Forest says: 4")
コード例 #3
0
 def test_interpreter_should_return_A_when_user_enters_A(self):
     interpreter = Interpreter("echo^<<A>>")
     self.assertEqual(interpreter.response(), "Forest says: A")
コード例 #4
0
 def test_intepreter_should_be_initialized_with_text(self):
     interpreter = Interpreter("echo")
     self.assertEqual(interpreter.text, "echo")
コード例 #5
0
 def test_boolean_non_equality_when_wrong(self):
     interpreter = Interpreter("true^XvX^true")
     self.assertEqual(interpreter.response(), False)
コード例 #6
0
 def test_boolean_non_equality(self):
     interpreter = Interpreter("true^XvX^false")
     self.assertEqual(interpreter.response(), True)
コード例 #7
0
 def test_integer_equality(self):
     interpreter = Interpreter("7^OvO^7")
     self.assertEqual(interpreter.response(), True)
コード例 #8
0
 def test_simple_fizz_feature(self):
    interpreter = Interpreter("WALK_PATH_IF_SEE^6^(*)>^3^OvO^0^echo^<<fizz>>")
    self.assertEqual(interpreter.response(), "Forest says: fizz")
コード例 #9
0
 def test_integer_non_equality(self):
     interpreter = Interpreter("7^XvX^3")
     self.assertEqual(interpreter.response(), True)
コード例 #10
0
 def test_visit_equal_two_different_strings_returns_false(self):
     interpreter = Interpreter("")
     ast_equal = ASTEquals(ASTString("hello"), ASTString("not hello"))
     self.assertEqual(interpreter.visit_ast_equals(ast_equal), False)
コード例 #11
0
 def test_visit_equal_two_same_strings_returns_true(self):
     interpreter = Interpreter("")
     ast_equal = ASTEquals(ASTString("hello"), ASTString("hello"))
     self.assertEqual(interpreter.visit_ast_equals(ast_equal), True)
コード例 #12
0
 def test_visit_equal_returns_false(self):
     interpreter = Interpreter("")
     ast_mod = ASTModulus(ASTInteger(16), ASTInteger(5))
     ast_equal = ASTEquals(ast_mod, ASTInteger(2))
     self.assertEqual(interpreter.visit_ast_equals(ast_equal), False)
コード例 #13
0
 def test_visit_modulus_returns_1(self):
     interpreter = Interpreter("")
     ast_mod = ASTModulus(ASTInteger(16), ASTInteger(5))
     self.assertEqual(interpreter.visit_ast_modulus(ast_mod), 1)
コード例 #14
0
 def test_interpreter_should_return_Hello_World(self):
     interpreter = Interpreter("echo^<<Hello World!>>")
     self.assertEqual(interpreter.response(), "Forest says: Hello World!")
コード例 #15
0
 def test_integer_non_equality_when_wrong(self):
     interpreter = Interpreter("7^XvX^7")
     self.assertEqual(interpreter.response(), False)
コード例 #16
0
 def test_interpreter_should_raise_exception_when_invalid_syntax(self):
     interpreter = Interpreter("Hello")
     self.assertRaises(Exception, interpreter.response)
コード例 #17
0
 def test_boolean_equality(self):
     interpreter = Interpreter("true^OvO^true")
     self.assertEqual(interpreter.response(), True)
コード例 #18
0
 def test_interpreter_visit_tree_should_return_more_user_output(self):
     interpreter = Interpreter("")
     tokens = [{"ECHO": "echo"}, {"STRSTART" : "<<"}, {"STRING_CONTENT" : "Hello Rangers!"}, {"STRSTOP" : ">>"}]
     parser = Parser(tokens)
     ast_output = parser.create_ast_for_rule_1()
     self.assertEqual(interpreter.visit_tree(ast_output), "Forest says: Hello Rangers!")
コード例 #19
0
 def test_integer_modulus(self):
     interpreter = Interpreter("10^(*)>^5")
     self.assertEqual(interpreter.response(), 0)