Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
34 changes: 34 additions & 0 deletions tests/test_automata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@


class TestDFA(unittest.TestCase):
def setUp(self):
# DFA transitions table example
self.transitions = {
'q0': {'a': 'q1', 'b': None},
'q1': {'a': 'q1', 'b': 'q2'},
'q2': {'a': 'q1', 'b': 'q3'},
'q3': {'a': None, 'b': None}
}
self.start = 'q0'
self.final = ['q3']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Comments:
    • The 'setUp' method initializes 'self.transitions', 'self.start', and 'self.final' for a specific DFA configuration, which might not be reused effectively across different test methods if they require different DFA configurations.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Comments:
    • The 'setUp' method defines a DFA that does not match the tests. The tests use different transition tables.


def test_DFA(self):
transitions = {
'a': {'1': 'a', '0': 'b'},
Expand Down Expand Up @@ -43,6 +54,29 @@ def test_DFA(self):
self.assertEqual(False, DFA(transitions2, start2, final2, "aaabbb"))
self.assertEqual(True, DFA(transitions2, start2, final2, "baabba"))

def test_reject_string(self):
# Test case where DFA should reject the string
string = 'aaa'
result = DFA(self.transitions, self.start, self.final, string)
self.assertFalse(result)

def test_invalid_transition(self):
# Test case where DFA encounters an invalid transition
string = 'b'
result = DFA(self.transitions, self.start, self.final, string)
self.assertFalse(result)

def test_empty_string(self):
# Test case where the string is empty, start state is not a final state
string = ''
result = DFA(self.transitions, self.start, self.final, string)
self.assertFalse(result)

def test_empty_string_with_final_start(self):
# Test case where the string is empty and start state is a final state
start_final = ['q0']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Comments:
    • The test 'test_empty_string_with_final_start' modifies 'self.start' to 'q0' which is already the initial state. This test might not be testing a different scenario as intended.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Comments:
    • Incorrect setup for 'test_empty_string_with_final_start'. 'start_final' should be the final state, not the start state.
  • Suggestions:
    self.final = ['q0']
    

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Comments:
    • The 'setUp' method initializes 'self.final' as ['q3'], but 'test_empty_string_with_final_start' incorrectly attempts to use 'start_final' as the final states list.

result = DFA(self.transitions, self.start, start_final, '')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Comments:
    • Incorrect use of 'start_final' as both the start state and final states list in 'test_empty_string_with_final_start'.
  • Suggestions:
    result = DFA(self.transitions, 'q0', ['q0'], '')
    

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Comments:
    • The 'test_empty_string_with_final_start' method assigns 'start_final = ['q0']' but uses 'self.start' in the DFA call. This seems to be a logical mistake.
  • Suggestions:
    result = DFA(self.transitions, start_final, self.final, '')
    

self.assertTrue(result)

if __name__ == '__main__':
unittest.main()