1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from evaluator import *


DESCRIPTION = "Test if the model can create a tree from a string."

TAGS = ['code', 'python']

code = """
class Node:
    def __init__(self, name, parent=None):
        self.name = name
        self.parent = parent
        self.children = []
        if parent:
            self.parent.children.append(self)
    def __repr__(self):
        if self.children == []:
            return self.name
        return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')'
"""

question = code + """

Write a complete python file that will print the tree

(1 (2 3) 4)

Call the root of the tree 'root'.
Then print out str(root).
DO NOT MODIFY THE Node CLASS.
"""

TestMakeTreeEasy = question >> LLMRun() >> ExtractCode(keep_main=True) >> PythonRun() >> SubstringEvaluator('(1 (2 3) 4)')

question2 = code + """

Write a complete python file that will print the tree

(1 (2 (3 4 5 6) (7 8)) (9 10 (11 12)))

Call the root of the tree 'root'.
Then print out str(root).
"""

TestMakeTree = question2 >> LLMRun() >> ExtractCode(keep_main=True) >> PythonRun() >> SubstringEvaluator('(1 (2 (3 4 5 6) (7 8)) (9 10 (11 12)))')


if __name__ == "__main__":
    print(run_test(TestMakeTreeEasy))