Esempio n. 1
0
 def test_unique(self):
     s1 = pyscm.make_boolean(True)
     s2 = pyscm.make_boolean(2 > 1)
     s3 = pyscm.make_boolean(False)
     s4 = pyscm.make_boolean(len('hello') == 1)
     self.assertTrue(s1 is s2)
     self.assertTrue(s3 is s4)
     self.assertFalse(s1 is s3)
     self.assertFalse(s2 is s4)
Esempio n. 2
0
 def test_if(self):
     t = pyscm.make_boolean(True) 
     f = pyscm.make_boolean(False) 
     ast = pyscm.parse('(if (> 2 1) 9 10)')[1]
     self.assertEqual(9, pyscm.evaluate(ast, pyscm.make_base()))
     ast = pyscm.parse('(if (> 1 2) 9 10)')[1]
     self.assertEqual(10, pyscm.evaluate(ast, pyscm.make_base()))
     ast = pyscm.parse('(if (> 2 3) 10)')[1]
     self.assertEqual(None, pyscm.evaluate(ast, pyscm.make_base()))
     ast = pyscm.parse('(if (< 2 3) 10)')[1]
     self.assertEqual(10, pyscm.evaluate(ast, pyscm.make_base()))
Esempio n. 3
0
 def test_compare(self):
     t = pyscm.make_boolean(True)
     f = pyscm.make_boolean(False)
     self.assertTrue(t is pyscm.lt([2, 4]))
     self.assertTrue(f is pyscm.lt([4, 2]))
     self.assertTrue(t is pyscm.le([2, 4]))
     self.assertTrue(t is pyscm.le([2, 2]))
     self.assertTrue(t is pyscm.ge([2, 2]))
     self.assertTrue(t is pyscm.ge([4, 2]))
     self.assertTrue(f is pyscm.ge([2, 4]))
     self.assertTrue(t is pyscm.gt([3, 1]))
Esempio n. 4
0
    def test_equal(self):
        t = pyscm.make_boolean(True)
        f = pyscm.make_boolean(False)
        self.assertTrue(t is pyscm.eq([2, 2]))
        self.assertTrue(t is pyscm.eq_question_mark([2, 2]))
        self.assertTrue(f is pyscm.eq_question_mark([2, 2.0]))
        self.assertTrue(t is pyscm.eq([2, 2.0]))
        self.assertTrue(t is pyscm.eq_question_mark([t,\
            pyscm.make_boolean(True)]))
        self.assertTrue(t is pyscm.eq_question_mark([
                pyscm.make_symbol('foo'),
                pyscm.make_symbol('foo')
            ]))

        self.assertTrue(t is pyscm.eq_question_mark([
                pyscm.evaluate(['quote', []], {}),
                pyscm.evaluate(['quote', []], {})
            ]))
Esempio n. 5
0
 def test_cond(self):
     t = pyscm.make_boolean(True) 
     f = pyscm.make_boolean(False) 
     code = """
     (define (f x)
         (cond
             ((< x 3) 1)
             ((< x 5) 44)
             (else 99)
             )) 
     (define a (f 2))
     (define b (f 4))
     (define c (f 33))
     """
     ast = pyscm.parse(code)
     base = pyscm.make_base()
     pyscm.evaluate(ast, base)
     self.assertEqual(1, base['a'])
     self.assertEqual(44, base['b'])
     self.assertEqual(99, base['c'])
Esempio n. 6
0
 def test_str(self):
     s = pyscm.make_boolean(True)
     self.assertEqual('#t', str(s))
     s = pyscm.make_boolean(False)
     self.assertEqual('#f', str(s))