python_to_c_loop_update.py 605 B

123456789101112131415161718192021222324
  1. from evaluator import *
  2. DESCRIPTION = "Test if a model can convert a python program to c, with a loop that makes it difficult."
  3. TAGS = ['code', 'python', 'c']
  4. question = """
  5. Convert this to c
  6. def foo(x):
  7. sum = 0
  8. for i in range(x):
  9. x += i
  10. sum += x
  11. return sum
  12. """
  13. test_case, answer = make_c_test([("foo(10)", "265")])
  14. TestPythonToCLoopUpdate = question >> LLMRun() >> ExtractCode() >> CRun(test_case) >> SubstringEvaluator(answer)
  15. if __name__ == "__main__":
  16. print(run_test(TestPythonToCLoopUpdate))