simple-calculator part 1

Story points 2
Tags tdd
Hard Prerequisites
  • PROJECTS: Assertive programming kata
  • TOPICS: Test Driven Development

  • The objective of this project is to build a calulator 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:

    1. RED: Write tests. It should fail initially because there isn’t any code that it is testing.
    2. GREEN: Write code to make the tests pass.
    3. REFACTOR: Make sure code is understandable and clean.

    Remember to make sure your tests still pass after refactoring it.

    Set up environment

    JavaScript:

    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:

    • A src folder that has a file called:

      • simple_calculator.js <—- this is where you will implement all your functionality.
    • A spec folder that has a file called:

      • simple_calculator_spec.js <—- this is where you will put your tests.

    Your directory structure should look like this:

        >node_modules    <---- make sure this is in your .gitignore
        >spec
            > support
                - jasmine.json
            - simple_calculator_spec.js
        >src
            - simple_calculator.js
        - package.json
    

    Python

    Your project is expected to be completed using pytest. You are expected to follow industry best practices in all things. This means that you need to have a directory structure that is in good shape. Please name your files and folders like this:

    ├── simple_calculator   the package under test
    │   └── calculator.py
    ├── requirements.txt    installation requiremnts
    ├── 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. : [TODO] Umuzi Tech Department

    Java

    You’ll be using IntelliJ, Gradle and JUnit to pull this off.

    Create a class named Calculator. All your methods should be static methods that return integers. Eg:

        public static int add(....
    

    Please make sure that you make proper use of gitignore. We don’t want your junk files. The git repo you give us should have a file hierarchy that looks like this:

    ├── build.gradle
    ├── gradle
    │   └── wrapper
    │       ├── gradle-wrapper.jar
    │       └── gradle-wrapper.properties
    ├── gradlew
    ├── gradlew.bat
    ├── settings.gradle
    └── src
        ├── main
        │   └── java
        │       └── Calculator.java       <-------- names are important
        └── test
            └── java
                └── CalculatorTest.java   <-------- names are important
    

    Please refer to the following to find out more: TOPICS: Gradle and IntelliJ project submission structure

    1. Create an add function that can add two integers

    Create a function called add that works like this:

    add(1,2)
    // should return 3
    add(-1,-1)
    // should return -2
    

    2. Modify the add function so that it can add multiple integers.

    The add function should now 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])
    

    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 for the multiply function you will build in the next section.

    3. Create a multiply function that can multiply two integers

    Create a function called multiply that works like this:

    multiply(1,3)
    // should return 3
    multiply(-1,3)
    // should return -3
    

    4. Modify the multiply function so that it can multiply multiple integers.

    The multiply function should now behave like this:

    mutilply(1,2,3,4,5)
    // should return 120
    multiply(1,3)
    // should still return 3
    multiply(-1,3)
    // should still return -3
    

    RAW CONTENT URL