Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/goodylabs/backend-dev-test
https://github.com/goodylabs/backend-dev-test
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/goodylabs/backend-dev-test
- Owner: goodylabs
- Created: 2016-12-14T14:17:25.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-18T08:17:56.000Z (almost 8 years ago)
- Last Synced: 2024-08-03T20:02:41.101Z (5 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 12
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-recruitment-tests - Goodylabs - Create a finite automaton that has three states. (Node.js)
README
# Finite State Machine Test
Description:
Create a finite automaton that has three states. Finite automatons are the same as finite state machines for our purposes.
Our simple automaton, accepts the language of A, defined as {0, 1} and should have three states,
q1, q2, and q3.q1 is our start state. We begin reading commands from here.
q2 is our accept state. We return true if this is our last state.q1 moves to q2 when given a 1, and stays at q1 when given a 0.
q2 moves to q3 when given a 0, and stays at q2 when given a 1.
q3 moves to q2 when given a 0 or 1.Our automaton should return whether we end in our accepted state, or not (true/false.)
Here's an example.
```javascript
var a = new Automaton();
// Do anything you need to set up this automaton's states.
var isAccepted = a.readCommands(["1", "0", "0", "1", "0"]);
```We make these transitions based on the input of ["1", "0", "0", "1", "0"],
1 q1 -> q2
0 q2 -> q3
0 q3 -> q2
1 q2 -> q2
0 q2 -> q3
We end in q3, which is not our accept state, so return false.The input of ["1", "0", "0", "1", "0"] would cause us to return false, as we would end in q3.
I have started you off with the bare bones of the Automaton class, as seen in ./src/Automaton. The task
is to complete the implementation.You will have to define how the Automaton stores it's state, and transitions between states based on the commands passed to readCommands.
As an aside, the automaton accepts an array of strings, rather than just numbers, or a number represented as a string, you may assume you will only be passed valid inputs.
Acceptance tests are included in the test file. Do not modify these. When all these tests pass this means your implementation is correct.
## setup
You will need node v4 installed.
Clone this repository.
Go into the fsm/ folder and run:
```bash
nvm use
npm install
```To run the tests do:
```bash
npm run test
```