For this online coding test I have solved task 1 and 2a) in Clojure.
To be able to run this code you will need to install Clojure version 1.10.1 or later. Lastly you will also need to install the Leiningen build tool.
- To start the REST API server you simply run
lein runwhich will open a server onlocalhost:3008. - The unit tests can be executed by simply running
lein test
The endpoint for sending a POST request is /calc. The body of the POST request must contain an application/json object with the key
"expression" and value string containing the mathematical expression to be calculated. For example:
{"expression": "-1 * (3 + 2)"}
In the mathematical expression string all infix operators must have spaces between them. On the other hand parethesis can either have or not have spaced between them. Any negative numbers must be written without spaces. The Rest Api will handle expressions with unbalanced parens or empty expressions.
// Valid
{"expression": "8 / (1 + 3)"}
// Valid
{"expression": "8 / ( 1 + 3 )"}
// Valid
{"expression": "-8 / (1 + 3)"}
// Invalid
{"expression": "8/(1+3)"}
// Invalid
{"expression": "8 / (1 + 3))"}
// Invalid
{"expression": "- 8 / (1 + 3)"}
- The solution for task 1 can be found in the
coding-test.productnamespace and the unit tests can be found incoding-test.product-test. - The solution for task 2 can be found under the
coding-test.calculator.*namespaces and the unit tests can be found undercoding-test.calculator.route-test