├── requirements.txt ├── test_add.py ├── test_square.py ├── test_multiply.py ├── test_subtract.py ├── test_power.py ├── tests_sqrt.py ├── test_divide.py ├── calculator.py ├── .travis.yml ├── README.md └── .gitignore /requirements.txt: -------------------------------------------------------------------------------- 1 | pytest>=5.0.0 -------------------------------------------------------------------------------- /test_add.py: -------------------------------------------------------------------------------- 1 | from calculator import add 2 | 3 | 4 | def test_add(): 5 | results = add(1, 2) 6 | assert results == 3 7 | -------------------------------------------------------------------------------- /test_square.py: -------------------------------------------------------------------------------- 1 | from calculator import square 2 | 3 | 4 | def test_square(): 5 | results = square(3) 6 | assert results == 9 -------------------------------------------------------------------------------- /test_multiply.py: -------------------------------------------------------------------------------- 1 | from calculator import multiply 2 | 3 | 4 | def test_multiply(): 5 | results = multiply(2, 3) 6 | assert results == 6 -------------------------------------------------------------------------------- /test_subtract.py: -------------------------------------------------------------------------------- 1 | from calculator import subtract 2 | 3 | 4 | def test_subtract(): 5 | results = subtract(10, 7) 6 | assert results == 3 -------------------------------------------------------------------------------- /test_power.py: -------------------------------------------------------------------------------- 1 | from calculator import power 2 | 3 | 4 | def test_power(): 5 | results = power(3, 2) 6 | assert results == 9 7 | 8 | results = power(3, 3) 9 | assert results == 27 -------------------------------------------------------------------------------- /tests_sqrt.py: -------------------------------------------------------------------------------- 1 | from calculator import sqrt 2 | 3 | def test_sqrt(): 4 | results = sqrt(9) 5 | assert results == 3 6 | 7 | results = sqrt(16) 8 | assert results == 4 9 | 10 | -------------------------------------------------------------------------------- /test_divide.py: -------------------------------------------------------------------------------- 1 | from calculator import divide 2 | 3 | 4 | def test_divide(): 5 | results = divide(6, 2) 6 | assert results == 3 7 | 8 | 9 | def test_divide_by_zero(): 10 | results = divide(99, 0) 11 | assert type(results) == str 12 | -------------------------------------------------------------------------------- /calculator.py: -------------------------------------------------------------------------------- 1 | def add(x, y): 2 | return x + y 3 | 4 | 5 | def subtract(x, y): 6 | pass 7 | 8 | 9 | def divide(x, y): 10 | pass 11 | 12 | 13 | def multiply(x, y): 14 | pass 15 | 16 | 17 | def square(x): 18 | pass 19 | 20 | 21 | def power(x, y): 22 | pass 23 | 24 | 25 | def sqrt(x): 26 | pass 27 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | sudo: false 3 | os: 4 | - linux 5 | 6 | python: 7 | - "3.6" 8 | - "3.7" 9 | 10 | install: 11 | - pip install -r requirements.txt 12 | 13 | script: 14 | - "py.test test*" 15 | 16 | notifications: 17 | webhooks: 18 | urls: 19 | - https://rmotr.com/api/v1/webhooks/travis/build-project 20 | on_success: always 21 | on_failure: always 22 | on_start: never -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple Calculator 2 | 3 | Welcome to your first big project! The goal is to make a simple calculator using everything you've learned up to this point! 4 | 5 | Your job is to implement the code under `calculator.py`; note that we've left only placeholders for the functions. Your job is to write the body of those functions. 6 | 7 | ### Step 1: 8 | 9 | * Add 10 | * Subtract 11 | * Multiply 12 | 13 | We've set up 3 functions here that you need to finish. These are fairly straight-forward and shouldn't give you too much trouble, think back to your lesson on operators! 14 | ##### To run tests, use these commands in the command line: 15 | 16 | ```bash 17 | # For the add() function 18 | $ py.test test_add.py 19 | 20 | # For the subtract() function 21 | $ py.test test_subtract.py 22 | 23 | # For the mulitply() function 24 | $ py.test test_multiply.py 25 | ``` 26 | 27 | ### Step 2 28 | 29 | * Divide 30 | 31 | You'll notice here that divide is the only function that has two tests for it - that's because you'll need to program some exceptional behavior in case the user tries to divide by 0! 32 | 33 | If 0 is passed as a denominator when using this function, instead of an integer, return a string warning the user not to divide by 0. You can chose any message you want, for example `return "Invalid value for denominator, cant't divide by 0!"` 34 | 35 | ```bash 36 | $ py.test test_divide.py 37 | ``` 38 | 39 | ### Step 3 40 | 41 | * Square 42 | * Power 43 | * Square Root 44 | 45 | Rounding out the last three tests are functions dealing with powers. They can be kind of tricky (especially finding the square root!) but you shouldn't have any problem if you review your lesson on operators. 46 | 47 | ```bash 48 | $ py.test test_square.py 49 | $ py.test test_power.py 50 | $ py.test test_sqrt.py 51 | ``` 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | 53 | # Translations 54 | *.mo 55 | *.pot 56 | 57 | # Django stuff: 58 | *.log 59 | local_settings.py 60 | db.sqlite3 61 | db.sqlite3-journal 62 | 63 | # Flask stuff: 64 | instance/ 65 | .webassets-cache 66 | 67 | # Scrapy stuff: 68 | .scrapy 69 | 70 | # Sphinx documentation 71 | docs/_build/ 72 | 73 | # PyBuilder 74 | target/ 75 | 76 | # Jupyter Notebook 77 | .ipynb_checkpoints 78 | 79 | # IPython 80 | profile_default/ 81 | ipython_config.py 82 | 83 | # pyenv 84 | .python-version 85 | 86 | # pipenv 87 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 88 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 89 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 90 | # install all needed dependencies. 91 | #Pipfile.lock 92 | 93 | # celery beat schedule file 94 | celerybeat-schedule 95 | 96 | # SageMath parsed files 97 | *.sage.py 98 | 99 | # Environments 100 | .env 101 | .venv 102 | env/ 103 | venv/ 104 | ENV/ 105 | env.bak/ 106 | venv.bak/ 107 | 108 | # Spyder project settings 109 | .spyderproject 110 | .spyproject 111 | 112 | # Rope project settings 113 | .ropeproject 114 | 115 | # mkdocs documentation 116 | /site 117 | 118 | # mypy 119 | .mypy_cache/ 120 | .dmypy.json 121 | dmypy.json 122 | 123 | # Pyre type checker 124 | .pyre/ 125 | --------------------------------------------------------------------------------