<commit_before>import unittest
import petit_lisp as pl

from src.parser import Parser

parse = Parser().parse


def evaluate(s):
    return pl.evaluate(parse(s))


class TestLists(unittest.TestCase):

    def setUp(self):  # noqa
        pl.global_env = pl.common_env(pl.Env())

    def test_cons(self):
        expr = "(define a (cons 1 (cons 2 (cons 3 (cons 4 '())))))"
        expr2 = "'(1 2 3 4)"
        evaluate(expr)
        self.assertEqual(evaluate(expr2), evaluate("a"))

    def test_cons_error(self):
        expr = "(define a (cons 1 '2))"
        self.assertRaises(ValueError, evaluate, expr)

    def test_car(self):
        expr = "(define a (cons 1 (cons 2 (cons 3 (cons 4 '())))))"
        expr2 = "(car a)"
        evaluate(expr)
        self.assertEqual(1, evaluate(expr2))

    def test_cdr(self):
        expr = "(define a (cons 1 (cons 2 (cons 3 (cons 4 '())))))"
        expr2 = "(cdr a)"
        evaluate(expr)
        self.assertEqual(evaluate("'(2 3 4)"), evaluate(expr2))<commit_msg>adding test for basic lisp construct<commit_after>import unittest
import petit_lisp as pl

from src.parser import Parser

parse = Parser().parse


def evaluate(s):
    return pl.evaluate(parse(s))


class TestBasicLisp(unittest.TestCase):

    def setUp(self):  # noqa
        pl.global_env = pl.common_env(pl.Env())
        self.assertEqual(True, evaluate("(undefined? a)"))

    def test_cons(self):
        expr = "(define a (cons 1 (cons 2 (cons 3 (cons 4 '())))))"
        expr2 = "'(1 2 3 4)"
        evaluate(expr)
        self.assertEqual(evaluate(expr2), evaluate("a"))
        self.assertEqual(False, evaluate("(undefined? a)"))

    def test_cons_error(self):
        expr = "(define a (cons 1 '2))"
        self.assertRaises(ValueError, evaluate, expr)

    def test_car(self):
        expr = "(define a (cons 1 (cons 2 (cons 3 (cons 4 '())))))"
        expr2 = "(car a)"
        evaluate(expr)
        self.assertEqual(1, evaluate(expr2))

    def test_cdr(self):
        expr = "(define a (cons 1 (cons 2 (cons 3 (cons 4 '())))))"
        expr2 = "(cdr a)"
        evaluate(expr)
        self.assertEqual(evaluate("'(2 3 4)"), evaluate(expr2))

    def test_is_atom(self):
        self.assertEqual(True, evaluate("(atom? 3)"))
        self.assertEqual(False, evaluate("(atom? '(1 2 3))"))
{'fraction_non_alphanumeric': 0.15650670125378296, 'fraction_numerical': 0.02594033722438392, 'mean_word_length': 2.7872340425531914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4592665', 'n_tokens_mistral': 805, 'n_tokens_neox': 745, 'n_words': 210}