def test_with(self): self.assertEqual(tarea3.run("(with (f (fun (y) (+ x y))) (+ 2 3))"), "5") self.assertEqual( tarea3.run( "(with (x 3) (with (f (fun (y) (+ x y))) (with (x 5) (f 4))))" ), "7")
def test_if0(self): self.assertEqual(tarea3.run("(if0 (> 5 0) 5 6)"), "5") self.assertEqual(tarea3.run("(if0 (< 5 0) 5 6)"), "6") self.assertEqual( tarea3.run( "(if0 (if0 0 2 (+ 0 0)) (+ (if0 1 450 900) 23) (+ 6 9))"), "15")
def test_seqn_set(self): self.assertEqual(tarea3.run("(with (x 3) (+ (seqn (set x 5) x) x))"), "10") self.assertEqual( tarea3.run( "(with (x 3) (with (f (fun (y) (- x y))) (seqn (set x 15) (f 10))))" ), "-7") self.assertEqual( tarea3.run( "(with (x 3) (seqn (set x 15) (with (f (fun (y) (- x y))) (f 10))))" ), "5")
def test_logic(self): self.assertEqual(tarea3.run("#true"), "True") self.assertEqual(tarea3.run("#false"), "False") self.assertEqual(tarea3.run("(not #true)"), "False") self.assertEqual(tarea3.run("(not #false)"), "True") self.assertEqual(tarea3.run("(and #true #true #true)"), "True") self.assertEqual(tarea3.run("(or #true #true #true)"), "True") self.assertEqual(tarea3.run("(and #true #false #true)"), "False") self.assertEqual(tarea3.run("(or #true #false #true)"), "True") self.assertEqual(tarea3.run("(or #false #false #false)"), "False")
def test_fun(self): self.assertEqual(tarea3.run("(((fun (x) x) (fun (x) (+ x 5))) 3)"), "8") self.assertEqual( run("""((fun (abs) (list (abs (- 5 7)) (abs (- 7 5)))) (fun (x) (if0 ( < x 0) (- 0 x) x)))"""), [2, 2])
def test_basics(self): self.assertEqual(tarea3.run("(+ 1 1)"), "2") self.assertEqual(tarea3.run("(- 3 2)"), "1") self.assertEqual(tarea3.run("(add1 5)"), "6") self.assertEqual(tarea3.run("(sub1 5)"), "4") self.assertEqual(tarea3.run("(modulo 11 2)"), "1") self.assertEqual(tarea3.run("(equal? 1 2)"), "False") self.assertEqual(tarea3.run("(equal? 1 1)"), "True") self.assertEqual(tarea3.run("(equal? (list 1 2) (list 1 2 3))"), "False") self.assertEqual(tarea3.run("(equal? (list 1 2) (list 1 2))"), "True") self.assertEqual(tarea3.run("(>= 3 2)"), "True") self.assertEqual(tarea3.run("(>= 3 3)"), "True") self.assertEqual(tarea3.run("(>= 3 4)"), "False") self.assertEqual(tarea3.run("(> 3 2)"), "True") self.assertEqual(tarea3.run("(< 3 3)"), "False") self.assertEqual(tarea3.run("(<= 3 3)"), "True")