Skip to content

Instantly share code, notes, and snippets.

@BrianZanti
Last active May 4, 2018 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrianZanti/9e31948e67481e3f462580fe42ad763d to your computer and use it in GitHub Desktop.
Save BrianZanti/9e31948e67481e3f462580fe42ad763d to your computer and use it in GitHub Desktop.

Iteration 1 - Calculator Class

Use TDD to drive out the creation of a Calculator Class the follows this interaction pattern:

 calc = Calculator.new
 #=> #<Calculator:0x007f9787335038>
 calc.total
 #=> 0

Iteration 2 - Adding

Use TDD to drive out the following behavior:

  calc = Calculator.new
  calc.total
  #=> 0
  calc.total.class
  #=> Integer
  calc.add(5)
  #=> 5
  calc.add 2
  #=> 7
  calc.total
  #=> 7

Iteration 3 - Subtraction and Clearing

Use TDD to drive out the following behavior:

  calc = Calculator.new
  calc.add(5)
  calc.subtract 2
  #=> 3
  calc.subtract 10
  calc.total
  #=> -7
  calc.clear
  calc.total
  #=> 0

Iteration 4 - Multiplication and Division

  calc = Calculator.new
  calc.multiply 5
  #=> 0
  calc.total
  #=> 0
  calc.add(5)
  calc.multiply 3
  #=> 15
  calc.divide 7 
  calc.total
  #=> 2.142857142857143
  calc.divide(0)
  #=> "Error: Cannot divide by 0"
  calc.clear
  calc.total
  #=> 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment