示例#1
0
    def test_null(self):
        program = "(null? 1)"
        self.assertEvaluatesTo(program, Boolean(False))

        program = "(null? '())"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(null? '(1 2))"
        self.assertEvaluatesTo(program, Boolean(False))
示例#2
0
def equality(arguments):

    for argument in arguments:
        if not isinstance(argument, Number):
            raise SchemeTypeError("Numerical equality test is only defined for numbers, "
                                  "you gave me %s." % argument.__class__)

        if argument != arguments[0]:
            return Boolean(False)

    return Boolean(True)
示例#3
0
def inexact(arguments):
    check_argument_number('inexact?', arguments, 1, 1)

    if isinstance(arguments[0], FloatingPoint):
        return Boolean(True)
    elif isinstance(arguments[0], Integer):
        return Boolean(False)
    else:
        raise SchemeTypeError("exact? only takes integers or floating point "
                              "numbers as arguments, you gave me ""%s." % \
                                  len(arguments))
示例#4
0
def char_less_than(arguments):
    check_argument_number('char<?', arguments, 2, 2)

    if not isinstance(arguments[0], Character) or not isinstance(
            arguments[1], Character):
        raise SchemeTypeError("char<? takes only character arguments, got a "
                              "%s and a %s." %
                              (arguments[0].__class__, arguments[1].__class__))

    if arguments[0].value < arguments[1].value:
        return Boolean(True)

    return Boolean(False)
示例#5
0
def test_equivalence(arguments):
    check_argument_number('eqv?', arguments, 2, 2)

    if isinstance(arguments[0], Atom):
        # __eq__ is defined on Atom
        return Boolean(arguments[0] == arguments[1])
    if isinstance(arguments[0], Cons):
        # __eq__ on Cons is deep equality
        return Boolean(arguments[0] is arguments[1])
    else:
        # __eq__ is defined on Nil
        # todo: test vectors
        return Boolean(arguments[0] == arguments[1])
示例#6
0
    def test_equality(self):
        program = "(=)"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(= 0)"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(= 0 0)"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(= 0 1)"
        self.assertEvaluatesTo(program, Boolean(False))

        program = "(= 1.0 1)"
        self.assertEvaluatesTo(program, Boolean(True))
示例#7
0
    def test_eqv(self):
        program = "(eqv? 1 1)"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(eqv? (quote foo) (quote foo))"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(eqv? car car)"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(eqv? (quote ()) (quote ()))"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(eqv? (cons 1 2) (cons 1 2))"
        self.assertEvaluatesTo(program, Boolean(False))
示例#8
0
def if_function(arguments, environment):
    check_argument_number('if', arguments, 2, 3)

    condition, environment = eval_s_expression(arguments[0], environment)

    # everything except an explicit false boolean is true
    if not condition == Boolean(False):
        then_expression = arguments[1]
        return eval_s_expression(then_expression, environment)
    else:
        if len(arguments) == 3:
            else_expression = arguments[2]
            return eval_s_expression(else_expression, environment)
示例#9
0
 def test_equality(self):
     program = "(char=? #\\  #\\space)"
     self.assertEvaluatesTo(program, Boolean(True))
示例#10
0
    def test_even_predicate(self):
        program = "(even? 6)"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(even? 7)"
        self.assertEvaluatesTo(program, Boolean(False))
示例#11
0
    def test_less_or_equal(self):
        program = "(<= 1 1)"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(<= 1 0)"
        self.assertEvaluatesTo(program, Boolean(False))
示例#12
0
    def test_and(self):
        program = "(and (= 2 2) (> 2 1))"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(and \"foo\" \"bar\")"
        self.assertEvaluatesTo(program, String("bar"))
示例#13
0
    def test_not(self):
        program = '(not #f)'
        self.assertEvaluatesTo(program, Boolean(True))

        program = '(not \'())'
        self.assertEvaluatesTo(program, Boolean(False))
示例#14
0
    def test_exact(self):
        program = "(exact? 1)"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(exact? 1.0)"
        self.assertEvaluatesTo(program, Boolean(False))
示例#15
0
 def test_real(self):
     program = "(real? 1.2)"
     self.assertEvaluatesTo(program, Boolean(True))
示例#16
0
 def test_rational(self):
     program = "(rational? 1.1)"
     self.assertEvaluatesTo(program, Boolean(True))
示例#17
0
 def test_complex(self):
     program = "(complex? 0)"
     self.assertEvaluatesTo(program, Boolean(True))
示例#18
0
    def test_greater_or_equal(self):
        program = "(>= 1 1)"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(>= 1 3 2)"
        self.assertEvaluatesTo(program, Boolean(False))
示例#19
0
    def test_greater_than(self):
        program = "(> 1 1)"
        self.assertEvaluatesTo(program, Boolean(False))

        program = "(> 11 10 0)"
        self.assertEvaluatesTo(program, Boolean(True))
示例#20
0
 def test_char_less_than(self):
     program = "(char<? #\\A #\\B)"
     self.assertEvaluatesTo(program, Boolean(True))
示例#21
0
    def test_string_predicate(self):
        program = '(string? "foo")'
        self.assertEvaluatesTo(program, Boolean(True))

        program = '(string? (quote ("foo")))'
        self.assertEvaluatesTo(program, Boolean(False))
示例#22
0
    def test_inexact(self):
        program = "(inexact? 0)"
        self.assertEvaluatesTo(program, Boolean(False))

        program = "(inexact? 0.0)"
        self.assertEvaluatesTo(program, Boolean(True))
示例#23
0
    def test_is_boolean(self):
        program = "(boolean? #t)"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(boolean? 1)"
        self.assertEvaluatesTo(program, Boolean(False))
示例#24
0
 def test_boolean(self):
     program = "#t"
     self.assertEvaluatesTo(program, Boolean(True))
示例#25
0
    def test_is_vector(self):
        program = "(vector? '())"
        self.assertEvaluatesTo(program, Boolean(False))

        program = "(vector? (make-vector 1))"
        self.assertEvaluatesTo(program, Boolean(True))
示例#26
0
    def test_negative_predicate(self):
        program = "(negative? -1)"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(negative? 3)"
        self.assertEvaluatesTo(program, Boolean(False))
示例#27
0
    def test_is_list(self):
        program = "(list? '())"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(list? 1)"
        self.assertEvaluatesTo(program, Boolean(False))
示例#28
0
    def test_odd_predicate(self):
        program = "(odd? 1)"
        self.assertEvaluatesTo(program, Boolean(True))

        program = "(odd? 0)"
        self.assertEvaluatesTo(program, Boolean(False))
示例#29
0
 def test_zero_predicate(self):
     program = "(zero? 0)"
     self.assertEvaluatesTo(program, Boolean(True))
示例#30
0
    def test_less_than(self):
        program = "(< 1 1)"
        self.assertEvaluatesTo(program, Boolean(False))

        program = "(< 1 2 4)"
        self.assertEvaluatesTo(program, Boolean(True))