The system should support the following :
- Given a transition, the system will know which status is the next one
- Given a transition , and bulk of statuses : the system will find the correct path to the next status of the given transition . a. For example : given a transition [R,A,S] with array of statuses [ 4 , 5 , 2 ]
Case 1:
exampleInput = {
"transition":"['S', 'A', 'S']",
"statuses":"['1', '2', '3']"
}
Given a transition and a bulk of statuses the system :
- The system assigns the current value as the last element of the statuses array.
- The destination is the first value in the statuses array.
- Keep track of the visited nodes and push to the visited array whenever we generate the next value
- If the next value is a single value:
- The next value of the status is retreived from the adjacency list
- The transition string is derived from joining the current and the next
- Current value is overwritten with next and the cycle continues until the next value is equal to the destination value
- If the next value is an array and is not yet visited
- Run a depth first search recursively and return the transition array of arrays and the visited set.
- Return the shortest transition from the step above since the system seeks to find the shortest path to the destination
- If the next value is visited continue with the loop
Case 2:
When given only a transition, the system should return the shortest path from the start of the transition
exampleInput = {
"transition":"['S', 'A', 'S']",
}
In this case:
- system returns all possible edges with the transition
- Performs all the steps in case one ablove
- Returns the edge with the shortest path
- Node.js v16.2.0 and NPM v8.3.1
To run this project ensure you have nodejs installed on your system Find instructions on the Node.js documentation
-
Clone the repo
git clone https://github.com/wamaithanyamu/graphTestProductiveSoftware.git
-
Navigate to the project foldler
cd graphTestProductiveSoftware
-
Install NPM packages
npm install
-
Run server
npm run start:dev
You can test the endpoint using postman as shown below
Distributed under the MIT License. See LICENSE.txt
for more information.