make_tree_from_text.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from evaluator import *
  2. DESCRIPTION = "Test if the model can create a tree from a string."
  3. TAGS = ['code', 'python']
  4. code = """
  5. class Node:
  6. def __init__(self, name, parent=None):
  7. self.name = name
  8. self.parent = parent
  9. self.children = []
  10. if parent:
  11. self.parent.children.append(self)
  12. def __repr__(self):
  13. if self.children == []:
  14. return self.name
  15. return '('+self.name + ' ' + ' '.join(repr(c) for c in self.children)+')'
  16. """
  17. question = code + """
  18. Write a complete python file that will print the tree
  19. (1 (2 3) 4)
  20. Call the root of the tree 'root'.
  21. Then print out str(root).
  22. DO NOT MODIFY THE Node CLASS.
  23. """
  24. TestMakeTreeEasy = question >> LLMRun() >> ExtractCode(keep_main=True) >> PythonRun() >> SubstringEvaluator('(1 (2 3) 4)')
  25. question2 = code + """
  26. Write a complete python file that will print the tree
  27. (1 (2 (3 4 5 6) (7 8)) (9 10 (11 12)))
  28. Call the root of the tree 'root'.
  29. Then print out str(root).
  30. """
  31. TestMakeTree = question2 >> LLMRun() >> ExtractCode(keep_main=True) >> PythonRun() >> SubstringEvaluator('(1 (2 (3 4 5 6) (7 8)) (9 10 (11 12)))')
  32. if __name__ == "__main__":
  33. print(run_test(TestMakeTreeEasy))