File size: 1,623 Bytes
acd4009
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
from dataclasses import dataclass, field

from exec_outcome import ExecOutcome
from helper import convert_crlf_to_lf


@dataclass
class Unittest:
    input: str
    output: str
    result: str | None = None
    exec_outcome: ExecOutcome | None = None

    def __post_init__(self):
        self.input = convert_crlf_to_lf(self.input)
        self.output = convert_crlf_to_lf(self.output)

    def update_result(self, result):
        self.result = result

    def update_exec_outcome(self, exec_outcome):
        self.exec_outcome = exec_outcome

    def match_output(self):
        return self.result == self.output


@dataclass
class ExtendedUnittest:
    input: str
    output: list[str] = field(default_factory=list)
    result: str | None = None
    exec_outcome: ExecOutcome | None = None
    time_consumed: float | None = None
    peak_memory_consumed: str | None = None

    def __post_init__(self):
        self.input = convert_crlf_to_lf(self.input)
        self.output = [convert_crlf_to_lf(o) for o in self.output.copy()]

    def update_time_mem(self, tc, mc):
        self.time_consumed = tc
        self.peak_memory_consumed = mc

    def update_result(self, result):
        self.result = result

    def update_exec_outcome(self, exec_outcome):
        self.exec_outcome = exec_outcome

    def match_output(self, result=None):
        if result is None:
            result = self.result
        return result in self.output

    def json(self):
        _json = self.__dict__.copy()
        if self.exec_outcome is not None:
            _json["exec_outcome"] = self.exec_outcome.value

        return _json