- python 3.6+
- pip install -r requirements.txt
/calc/<constant>
/calc/pi
/calc/tau
/calc/e
-H "Content-Type: application/json" -d '{"problem": "\<problem-expression\>"}' localhost:8080/calc
- addition: 1+2
- subtraction: 3-2
- multiplication: 4*5
- division: 6/2
- powers: 2^5
NOT YET IMPLEMENTED
- roots: (can use inverse power syntax or root<x>(y) to specify the x root of y)
- square-root root2(9) = 3 = 9^(1/2)
- cube-root root3(27) = 3 = 27^(1/3)
Use parens to group multiple operations according to standard mathematical grouping rules:
Examples:
Problem: ((1/2)*(2^5))/(10-8)^2
Answer: (.5)*(32)/4 = 16/4 = 4
$ git clone https://github.com/bfanselow/CaaS.git
$ virtualenv -p python3 venv
$ . venv/bin/activate
(venv) $ pip install -r requirements.txt
(venv) cd app/
(venv) $ python caas.py
(venv) $ ./gunicorn_start.sh
OR
(venv) $ cd app
(venv) $ gunicorn caas:api [-b <ip>:<port>]
$ docker build . -t docker-caas
$ docker run --name caas -d -p 8080:8080 docker-caas
TODO
(venv) $ curl localhost:8080/calc/
{"type": "info", "message": "GET a math constant (pi,tau,e) as a resource, or POST a math problem in json format - example: {'problem': '(3*3)+2'}"}
(venv) $ curl localhost:8080/calc/pi
{"constant": "pi", "value": 3.141592653589793}
(venv) $ curl -H "Content-Type: application/json" -d '{"problem": "bogus"}' localhost:8080/calc
{"type": "error", "message": "Request error: Invalid character in expression: [b]"}
(venv) $ curl -H "Content-Type: application/json" -d '{"problem": "2+3"}' localhost:8080/calc
{"problem": "2+3", "answer": 5.0}
(venv) $ curl -H "Content-Type: application/json" -d '{"problem": "((4+3)-5)^5"}' localhost:8080/calc
{"problem": "((4+3)-5)^5", "answer": 32.0}
(venv) $ curl -H "Content-Type: application/json" -d '{"problem": "3*((((4+3)-5)^5)/8)"}' localhost:8080/calc
{"problem": "(((4+3)-5)^5)/8", "answer": 4.0}
Unit-Testing
$ python -m pytest -v tests/unit/test_compute.py
$ python -m pytest -v tests/unit/test_compute_exc.py
OR simply
$ python -m pytest -v tests/unit/
Integration-Testing
$ python -m pytest -v tests/integration/test_service.py