def test_self_evaluation(self): self.assertEqual(visp.evaluate(visp.Exact(5), visp.Env()), visp.Exact(5)) self.assertEqual(visp.evaluate(visp.Inexact(6.0), visp.Env()), visp.Inexact(6.0)) self.assertEqual(visp.evaluate(visp.true, visp.Env()), visp.true) self.assertEqual(visp.evaluate(visp.false, visp.Env()), visp.false)
def test_self_evaluation(self): self.assertEqual( visp.evaluate(visp.Exact(5), visp.Env()), visp.Exact(5)) self.assertEqual( visp.evaluate(visp.Inexact(6.0), visp.Env()), visp.Inexact(6.0)) self.assertEqual( visp.evaluate(visp.true, visp.Env()), visp.true) self.assertEqual( visp.evaluate(visp.false, visp.Env()), visp.false)
def test_viral_inexactness(self): test_cases = { "(+ #e100 #e100)": Exact, "(+ #e100 #i100)": Inexact, "(+ #i100 #e100)": Inexact, "(+ #i100 #i100)": Inexact, } for input_string, expected_type in test_cases.items(): self.assertTrue(isinstance( visp.evaluate(visp.read(input_string), self.base_env), expected_type))
def test_debug_macro(self): self.assertEqual( visp.evaluate_many(visp.read_many( """(defmacro debug (a) (list 'let (list (list 'x a)) (list 'print 'x) 'x)) (debug "hello")"""), self.base_env), visp.evaluate(visp.read( """(let ((x "hello")) (print x) x)"""), self.base_env))
def test_viral_inexactness(self): test_cases = { "(+ #e100 #e100)": Exact, "(+ #e100 #i100)": Inexact, "(+ #i100 #e100)": Inexact, "(+ #i100 #i100)": Inexact, } for input_string, expected_type in test_cases.items(): self.assertTrue( isinstance( visp.evaluate(visp.read(input_string), self.base_env), expected_type))
def setUp(self): self.base_env = visp.Env() self.base_env.set( 'print', visp.evaluate(visp.read("(lambda x x)"), self.base_env)) visp.load_prelude(self.base_env)
def test_inexact(self): self.assertEqual(visp.evaluate(visp.read("#i10"), visp.Env()), 10.0)
def test_sub_mixed(self): self.assertEqual( visp.evaluate(visp.read("(- #i100 #e20 #e40 #e1)"), visp.Env()), 39.0)
def test_inexact_add(self): self.assertEqual( visp.evaluate(visp.read("""(+ #i100 #i100)"""), visp.Env()), 200.0)
def default(self, line, to_string=str): try: print(to_string(visp.evaluate(visp.read(line), self.env))) except Exception as exc: print(traceback.format_exc())
def assertEvalEqual(self, actual, expected): self.assertEqual( visp.evaluate(visp.read(actual), self.base_env), visp.evaluate(visp.read(expected), self.base_env))
def assertEvalEqual(self, actual, expected): self.assertEqual(visp.evaluate(visp.read(actual), self.base_env), visp.evaluate(visp.read(expected), self.base_env))
def test_symbol(self): self.assertEqual( visp.evaluate(visp.read("a"), visp.Env({ 'a': 2 })), 2)
def test_quote(self): self.assertEqual( visp.evaluate(visp.read( "'(1 2 3)"), visp.Env()).car, 1)
def test_inexact_add(self): self.assertEqual( visp.evaluate(visp.read( """(+ #i100 #i100)""" ), visp.Env()), 200.0)
def test_inexact(self): self.assertEqual( visp.evaluate(visp.read("#i10"), visp.Env()), 10.0)
def setUp(self): self.base_env = visp.Env() self.base_env.set('print', visp.evaluate(visp.read( "(lambda x x)"), self.base_env)) visp.load_prelude(self.base_env)
def test_symbol(self): self.assertEqual(visp.evaluate(visp.read("a"), visp.Env({'a': 2})), 2)
def test_exact(self): self.assertEqual( visp.evaluate(visp.read("1"), visp.Env()), 1)
def test_quote(self): self.assertEqual( visp.evaluate(visp.read("'(1 2 3)"), visp.Env()).car, 1)
def default(self, line, to_string=str): try: print(to_string(visp.evaluate(visp.read(line), self.env))) except Exception as exc: print(traceback.format_exc())
def test_exact(self): self.assertEqual(visp.evaluate(visp.read("1"), visp.Env()), 1)
def test_sub_mixed(self): self.assertEqual( visp.evaluate(visp.read( "(- #i100 #e20 #e40 #e1)" ), visp.Env()), 39.0)