File size: 1,051 Bytes
333a6de
376953f
333a6de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pytest

import eval_code

TYPICAL_ANSWER = """[
  {
    "criteria": "DRY",
    "explanation": "The memory allocation and initialization for ``p1``, ``p2``, and ``p3`` are repetitive. Consider creating a function like ``allocateAndInitializeMemory``."
  },
  {
    "criteria": "SRP",
    "explanation": "The ``main`` function handles memory allocation, initialization, and printing. You should separate these responsibilities into different functions like ``allocateMemory``, ``initializeData``, and ``printData``."
  },
  {
    "criteria": "NAME",
    "explanation": "``x1`` should be called ``title``, ``y1`` should be called ``author``, ``z1`` should be called ``year``, ``p1`` should be called ``titlePtr``, ``p2`` should be called ``authorPtr``, ``p3`` should be called ``yearPtr``."
  }
]"""


def test_parse_chatgpt_answer():
    ans = eval_code.parse_chatgpt_answer(TYPICAL_ANSWER)
    assert ans is not None
    assert len(ans) > 0
    an_eval = ans[0]
    assert "criteria" in an_eval.keys()
    assert "explanation" in an_eval.keys()