For this homework. what you need to do is to try to make the most complete calculator that can add, subtract, multiply, divide and store a history of calulations. The purpose of this assignment is to introduce you understand the principles of object oriented programming, unit testing, and design principles such as SOLID, DRY, GRASP, and Seperation of concerns. Its important to understand how to properly organize your code using the professional "grammer" of programming and not just the syntax of if statements and loops.
-
Make a new repo from scratch and set it up like last time, so you can run pytest, pylint, and coverage. You could even start with a copy of your last repo.
-
Submit a link to your repository to Canvas when your finished.
- Clone the repo
- CD into the repo directory
- Create the virtual environment
- Activate the virtual environment
- Install the requirements with pip or pip3 install requirements.txt
NOTE: YOU NEED TO CHECKOUT BRANCH "PART3" TO SEE THE DETAILED CODE COMMENTS
Basic tips:
- Don't repeat yourslf #1 rule
- Separate each thing the program needs to do, so its organized and your functions only do one thing
You should create new branches for each version of your progarm and work from the most simple, which is the first branch (main) and then keep upgrading your program until you have all of the requirements met. Please don't just copy and paste my final program, or you will not learn anything. Soon you will have to design your own program without any examples, which will be your mid-term. I have commented the code with explanations, so you can understand it better.
In this repository, you can see that there are 3 branches:
- Main - Basic Calculator with functions
- Part 2 - Intermediate Calculator with static methods on Calculator class and instance methods on Calculation class to perform operations on the data in the calculation instance.
- Part 3 - Advanced Calculator Has the detailed comments to read
The advanced calculator in part 3 contains static methods on the Calculator, instance methods on the Calculation, and class methods on the Calculations class. In addition, it has more advanced testing that uses parameterized test data and a fixture to make it easy to setup each test with consistent data. There are also modifciations to the .pylintrc file to control pylint's code analysis and I disable pylint errors in the calculator/calculation.py file by putting this code at the top of the file, which you can also use inside a specific function to disable a pylint check for a specific file. You sometimes need to disable pylint when you know you are doing the correct thing, but that for some reason pylint doesn't understand. It's better to disable it at the function or file level than the global level because you never know when you really do want it to tell you the style error.
"# pylint: disable=unnecessary-dunder-call, invalid-name"
Your goal in this homeowrk is to design your own calculator from scratch using the techniuqes that you can figure out based on my examples. Your calculator needs to do the following:
- Add, Subtract, Multiply, and Divide
- Throw exception for divide by zero and test that the exception is thrown
- Use at least one class, at least one static method, at least one class method.
- It needs to store a history of calculations, so that you can retrieve the last calculation, add a calculation,
- It needs to have 100% test coverage, pass pylint, and you need to do your best to not repeat any lines of code.
- You should use type hints for input parameter types and return types.
- Implement a pytest fixture to test the
- 20 Points for (add subtract, multiply, divide)
- 10 Points for exception throwing and testing on divide by zero
- 30 points each for using static, class, and instance methods correctly
- 5 Points for having a calculation class that stores the arthitmentic operation in a instance property.
- 15 Points for having a calculation history to store calculation instances
- 10 Points for having the convenience methods on the calculations class to manage the history
- 10 Points for using parameterized test data