Skip to content

apklinker/string-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

String Calculator

The goal of this project is to create two functions: Converter.toUnsignedInt() and Calculator.sum(). The development for these two functions will be done with TDD.

toUnsignedInt()

This function will take in a string that contains only not letters or special characters. Assume the frontend will limit the available input through a standard number input keyboard seen on the right in the below image.

Keyboard types

Business Requirements
  1. Input will limited on the front-end to contain only the following characters: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, _, -, ,
  2. A unique exception should be thrown when the input contains a decimal (.)
  3. A unique exception should be thrown when the input contains a dash (-)
  4. A unique exception should be thrown when the input contains a underscore (_)
  5. A unique exception should be thrown when the input contains a comma (,)
  6. A unique exception should be thrown when the input is longer than 3 digits

sum()

Should compute the sum of an array of numbers, each represented in a string.

Business Requirements
  1. When there are no inputs, return 0
    • sum([]) = 0
  2. When there is one input, return that number
    • sum(["2"]) = 2
    • sum(["17"]) = 17
  3. When there are two or more inputs, return the sum
    • sum(["1", "5"]) = 6
    • sum(["20", "3", "8"]) = 31
  4. If any exception occurs, throw a CalculationException
    • sum(["-1", "3", "8"]) = !!CalculationException
    • sum(["4", ".25", "9"]) = !!CalculationException
    • sum(["_", "7"]) = !!CalculationException
    • sum([","]) = !!CalculationException
    • sum(["20", "3", "9108"]) = !!CalculationException

About

Simple TDD workshop for interviews.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages