Story points | 2 |
Tags | tdd skill/tdd |
Hard Prerequisites | |
IMPORTANT: Please review these prerequisites, they include important information that will help you with this content. | |
|
The objective of this project is to build a calculator that can perform multiplication and addition on multiple integers. Do not build a front-end (UI). Complete this project by using a TDD approach.
The basic TDD approach is as follows:
Remember to make sure your tests still pass after any refactoring.
Use Jasmine to test your code. Please do not use the SpecRunner html file to test your code. Run Jasmine on the terminal.
After setting up Jasmine on the terminal, please ensure that your directory has the following:
Your directory structure should look like this:
├── spec
| ├── support
| | └── jasmine.json
| └── simple_calculator_spec.js
├── src
| └── simple_calculator.js
└── package.json
Note: Please export your two functions using the following syntax at the end of the code:
module.exports = {firstFunctionName, secondFunctionName}
Your project is expected to be completed using pytest.
Please name your files and folders like this:
├── simple_calculator the package under test
│ └── calculator.py
├── requirements.txt installation requirements
├── setup.py installation script for the package under test
└── tests all package tests go in this directory
└── test_calculator.py
Please take a look at this topic to see an explanation of the required directory structure.
TOPIC: Automated Testing in PythonPlease make use of Gradle from the command line to set up your project. You can learn more about Gradle here:
TOPIC: Introduction to GradleWhen you use gradle to create your project, give your project the following name: calculator
Your directory structure should look like this:
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── app
├── build.gradle
└── src
├── main
│ └── java
│ └── calculator
│ └── Calculator.java <-------- names are important
└── test
└── java
└── calculator
└── CalculatorTest.java <-------- names are important
Create a class named Calculator
. All your methods should be static methods that have integer arguments and return integers. Eg:
public static int add(....
Write some unit tests for a function named add
that works like this:
add(1,2)
// should return 3
add(-1,-1)
// should return -2
When you run your tests, they should fail.
Now write enough code to make your tests pass.
Write some more tests that expect the add
function to behave like this:
add(1,2,3,4,5)
// should return 15
add(1,2)
// should still return 3
add(-1,-1)
// should still return -2
Please note that your function should NOT expect an array or list of numbers, for example:
add([1,2,3,4]) # incorrect
add({1,2,3,4}) # incorrect
add(1,2,3,4) # correct
This is NOT what we are looking for. If you have square brackets inside your round brackets, you are doing it wrong. The same will apply to the multiply function you will build in the next section.
Now make your tests pass.
Keep following a TDD approach for the rest of this project.
Create a function called multiply
that works like this:
multiply(1,3)
// should return 3
multiply(-1,3)
// should return -3
The multiply
function should now behave like this:
multiply(1,2,3,4,5)
// should return 120
multiply(1,3)
// should still return 3
multiply(-1,3)
// should still return -3
__init__.py
is not needed if the repo is set up properly (python).