Skip to content

Commit

Permalink
Updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NikosDelijohn committed Oct 18, 2024
1 parent fff2f88 commit 6364561
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 3 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,20 @@ jobs:
cd src/unit_tests
python3 -m unittest test_config
- name: (grammars/transformers.py) FaultListTransformer Tests Cases
- name: (grammars/transformers.py) FaultReportFaultListTransformer Tests Cases
run: |
cd src/unit_tests
python3 -m unittest test_transformers.FaultListTransformerTest
python3 -m unittest test_transformers.FaultReportFaultListTransformerTest
- name: (grammars/transformers.py) FaultReportStatusGroupsTransformer Tests Cases
run: |
cd src/unit_tests
python3 -m unittest test_transformers.FaultReportStatusGroupsTransformerTest
- name: (grammars/transformers.py) FaultReportCoverageTransformer Tests Cases
run: |
cd src/unit_tests
python3 -m unittest test_transformers.FaultReportCoverageTransformerTest
- name: (grammars/transformers.py) TraceTransformerCV32E40P Tests Cases
run: |
Expand Down
113 changes: 112 additions & 1 deletion src/unit_tests/test_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import lark


class FaultListTransformerTest(unittest.TestCase):
class FaultReportFaultListTransformerTest(unittest.TestCase):

def get_parser(self):

Expand Down Expand Up @@ -147,6 +147,117 @@ def test_small_delay_defects_fault_list(self):

self.assertEqual(fault_list, expected_faults)


class FaultReportStatusGroupsTransformerTest(unittest.TestCase):

def get_parser(self):

factory = transformers.FaultReportTransformerFactory()
transformer, grammar = factory("StatusGroups")
return lark.Lark(grammar=grammar, start="start", parser="lalr", transformer=transformer)

def test_no_leq_group_section(self):

parser = self.get_parser()

status_groups_sample = r"""
StatusGroups {
SA "Safe" (UT, UB, UR, UU);
SU "Safe Unobserved" (NN, NC, NO, NT);
DA "Dangerous Assumed" (HA, HM, HT, OA, OZ, IA, IP, IF, IX);
DN "Dangerous Not Diagnosed" (PN, ON, PP, OP, NP, AN, AP);
DD "Dangerous Diagnosed" (PD, OD, ND, AD);
}
"""

groups = parser.parse(status_groups_sample)
expected_groups = {'SA': ['UT', 'UB', 'UR', 'UU'],
'SU': ['NN', 'NC', 'NO', 'NT'],
'DA': ['HA', 'HM', 'HT', 'OA', 'OZ', 'IA', 'IP', 'IF', 'IX'],
'DN': ['PN', 'ON', 'PP', 'OP', 'NP', 'AN', 'AP'],
'DD': ['PD', 'OD', 'ND', 'AD']}

self.assertEqual(groups, expected_groups)

def test_leq_group_section(self):

parser = self.get_parser()

status_groups_sample = r"""
StatusGroups {
SA "Safe" (UT < UB < UR UU);
SU "Safe Unobserved" (NN < NC < NO < NT);
DA "Dangerous Assumed" (HA < HM < HT < OA < OZ < IA < IP < IF < IX);
DN "Dangerous Not Diagnosed" (PN < ON < PP < OP < NP < AN < AP);
DD "Dangerous Diagnosed" (PD < OD < ND < AD);
}
"""

groups = parser.parse(status_groups_sample)
expected_groups = {'SA': ['UT', 'UB', 'UR', 'UU'],
'SU': ['NN', 'NC', 'NO', 'NT'],
'DA': ['HA', 'HM', 'HT', 'OA', 'OZ', 'IA', 'IP', 'IF', 'IX'],
'DN': ['PN', 'ON', 'PP', 'OP', 'NP', 'AN', 'AP'],
'DD': ['PD', 'OD', 'ND', 'AD']}

self.assertEqual(groups, expected_groups)

class FaultReportCoverageTransformerTest(unittest.TestCase):

def get_parser(self):

factory = transformers.FaultReportTransformerFactory()
transformer, grammar = factory("Coverage")
return lark.Lark(grammar=grammar, start="start", parser="lalr", transformer=transformer)

def test_coverage_str_no_quotes_lhs(self):

parser = self.get_parser()

coverage_sample = r"""
Coverage {
Coverage_1 = "AA + BB + CC";
Coverage_2 = "(DD + DN)/(NA + DA + DN + DD + SU)";
}
"""

coverage = parser.parse(coverage_sample)
expected_coverage = {'Coverage_1': 'AA + BB + CC', 'Coverage_2': '(DD + DN)/(NA + DA + DN + DD + SU)'}
self.assertEqual(coverage, expected_coverage)

def test_coverage_str_with_quotes_lhs(self):

parser = self.get_parser()

coverage_sample = r"""
Coverage {
"Coverage_1" = "AA + BB + CC";
"Coverage_2" = "(DD + DN)/(NA + DA + DN + DD + SU)";
}
"""

coverage = parser.parse(coverage_sample)
expected_coverage = {'Coverage_1': 'AA + BB + CC', 'Coverage_2': '(DD + DN)/(NA + DA + DN + DD + SU)'}
self.assertEqual(coverage, expected_coverage)

def test_coverage_with_format_specifiers_rhs(self):

parser = self.get_parser()

coverage_sample = r"""
Coverage {
"Coverage_1" = "FLT(AA + BB + CC)";
Coverage_2 = "PCT((DD + DN)/(NA + DA + DN + DD + SU))";
Coverage_3 = "INT(FF+CC*2)";
}
"""

coverage = parser.parse(coverage_sample)
expected_coverage = {'Coverage_1': '(AA + BB + CC)',
'Coverage_2': '((DD + DN)/(NA + DA + DN + DD + SU))',
'Coverage_3': '(FF+CC*2)'}
self.assertEqual(coverage, expected_coverage)

class TraceTransformerCV32E40PTest(unittest.TestCase):

def get_parser(self):
Expand Down

0 comments on commit 6364561

Please sign in to comment.