Coder Social home page Coder Social logo

rspec-tdd-calculator's Introduction

TDD with RSpec: Let's Build a Calculator

Introduction

This will be a ping pong exercise, which means you'll be paired up with the person sitting next to you, and only one of you can have your computer open at a time - it is probabaly easiest to just share the machine.

For each task, one person (p1) will take 10 minutes to write somes tests before passing the laptop over to the other (p2) to write the code to pass the tests. After the tests have all been passed, the first person (p1) who will then write more tests. Repeat this process until the task is complete.

When moving onto each new task, you should swap roles. So p1 does even numbered tasks and p2 does odd numbered tasks.

##Getting Started

  • P1 should Fork and clone this repository
  • P2 should either share the same machine or be added as a collaborator on the forked repo, so they can clone, pull and push
  • Run bundle install to install dependencies
    • Run rspec to run tests
    • Run rubocop to lint code

A skeleton application is provided as starter code.

Objective

You are required to build a Calculator class (calculator.rb) and a test suite for it (calculator_spec.rb). Specifically, an instance of the Calculator class will store a single read_only instance variable that represents the result of any methods called on it. Your tasks will be to add various mathematical functions to the class through a TDD process. As the writer of tests your intention is to create tests that force a robust implementation. As the writer of the code to pass the test, you want to implement the bare minimum to pass the test.

Tasks

  1. *Initialize: my_calculator = Calculator.new(1) would assign 1 to the be the starting result of the new my_calculator instance.
  2. *Results: my_calculator.result would return the curent result - tt should be readonly. my_calculator.reset(x) would reset the calculator to x.
  3. Addition: my_calculator.add(x) would add x to the internal result value, if x can be a valid number
  4. Subtraction: my_calculator.subtract(x) would subtract x from the internal result value, if x can be a valid number
  5. Multiply: my_calculator.multiply(x) would multiply x by the internal result value and save the new value, if x can be a valid number
  6. Divide: my_calculator.divide(x) would divide the internal result value by x and save the new value, if x can be a valid number
  7. Chain: my_calculator.add(x).subtract(y) all methods should be chainable in any order
  8. Operation: my_calculator.operation('add', x) would apply the addition operation with the value of x. It should support all operations
  9. Undo: my_calculator.undo(x) should undo the previous operation, restoring the result value, if x can be a valid number
  10. Redo: my_calculator.redo(x) should redo the previously undone operation, restoring the result value. A new action should remove the ability to perform redos.

Additional Resources


Licensing

  1. All content is licensed under a CC-BY-NC-SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.