Prototype of a tool for 1010 students to use for creating and testing their FA.
Repo: https://github.com/Geoc2022/finite-automaton-autograder
- Run a local server using
python -m http.serverin the terminal in this directory - Open your browser and go to
http://localhost:8000/fa_create.html - Create your FA using the instructions on the top of the page
- Click the "Export: JSON" button to download the FA as a JSON file
- Run
python dfa.pyand modify the main function to load your JSON file instead of dfa.json
Check out the example in grader.py bellow:
# Constructing a DFA that accepts binary strings that are multiples of 3
dfa = DFA(
states={'q0', 'q1', 'q2'},
alphabet={'1', '0'},
transitions={
'q0': {'0': 'q0', '1': 'q1'},
'q1': {'0': 'q2', '1': 'q0'},
'q2': {'0': 'q1', '1': 'q2'}
},
start_state='q0',
accept_states={'q0'}
)
wrong_dfa = DFA(
states={'q0', 'q1', 'q2'},
alphabet={'1', '0'},
transitions={
'q0': {'0': 'q0', '1': 'q1'},
'q1': {'0': 'q2', '1': 'q0'},
'q2': {'0': 'q1', '1': 'q3'}
},
start_state='q0',
accept_states={'q0', 'q2'} # Incorrectly accepts q2
)
autograder = Grader()
autograder.add_test(
lambda x: (bin(x * 3)[2:], True), 10
)
autograder.add_test(
lambda x: (bin(x * 3 + 1)[2:], False), 10
)
autograder.add_test(
lambda x: (bin(x)[2:], x % 3 == 0), 10
)
def random_test(_: int):
n = random.randint(0, 1000)
return (bin(n)[2:], n % 3 == 0)
autograder.add_test(
random_test, 2
)
print("Testing correct DFA:")
autograder.run(dfa)
print("\nTesting incorrect DFA:")
autograder.run(wrong_dfa)Which outputs:
Testing correct DFA:
Test 1: Passed
Test 2: Passed
Test 3: Passed
Test 4: Passed
Testing incorrect DFA:
Test 1: Failed
Test 2: Passed
Test 3: Failed
Test 4: Passed
- Run
python dfa.pyto create a DFA object as an example in the main function - Run a local server using
python -m http.serverin the terminal in this directory - Open your browser and go to
http://localhost:8000/dfa_render.html
This should be using the dfa.json file in the directory created by dfa.py.
You can edit the JSON file to get a different result or create your own DFA object in python and save it as a JSON file
-
Add a test file which would do the autograding
-
Add a FA library to hold the reused rendering functions
This uses a force graph library

