Giter VIP home page Giter VIP logo

tdd-basics-02's Introduction

Console based calculator

Description

You have to implement a console based calculator which can perform binary operations on decimal numbers. Your calculator will use the console as its display and the keyboard as its key pad. As the user presses keys on the keyboard, the display should update as per the keys pressed. The specifications for your implementation are -

Specifications

  • The calculator should ignore any keys other than the following keys (excluding commas) - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ., -, +, x, /, s, c, =
  • The calculator should support calculating 4 boolean operations - addition +, subtraction -, division / and multiplication x.
  • Pressing C should reset the calcuator and display 0.
  • On error the calculator should display -E-.
  • The calculator should support positive and negative decimal numbers.
  • On starting the calculator should display 0.
  • Pressing s should toggle the sign (positive or negative) of the number from.
  • The calcutor should support case insensitivity for keys x, c and s.

The basic starter code for your solution has been provided along with the wiring of the calcuator to the console. You can add your implementation accordingly. Your solution should contain the following -

  1. A clean object oriented implementation of the Calcuator. Create additional classes as required for your solution and object model.
  2. Unit tests for testing your implemention.
  3. Integration with Travis CI for continous integration.

Examples

The examples below show how the calculator display will update based on the sequence of key board inputs.

1.

Scenario is 10 + 2 = 12.

Keys Pressed Updated Display Remarks
1 1
0 10
+ 10
2 2
= 12

2.

Scenario is 10 / 0 = -E-

Keys Pressed Updated Display Remarks
1 1
0 10
/ 10
0 0
= -E- Calcuator displays error due to divide by zero.

3.

Keys Pressed Updated Display Remarks
0 0
0 0 Multiple zeros before a decimal point are ignored.
. 0.
. 0. Multiple decimal points are ignored.
0 0.0
0 0.00
1 0.001

4.

Keys Pressed Updated Display Remarks
1 1
2 12
+ 12
2 2
S -2 Sign is toggled.
S 2 Sign is toggled.
S -2 Sign is toggled.
= 10

5.

Keys Pressed Updated Display
1 1
+ 1
2 2
+ 3
3 3
+ 6
= 12

6.

Keys Pressed Updated Display
1 1
+ 1
2 2
+ 3
C 0

tdd-basics-02's People

Contributors

sirius17 avatar

Watchers

James Cloos avatar

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.