Giter Site home page Giter Site logo

kata-string-calculator's Introduction

String calculator kata

StringCalculator kataKata

Steps:

1. Create a String calculator with a method int Add(string numbers)

  1. The method can take 0, 1, or 2 numbers and will return their sum.
  2. Example inputs: "", "1", or "1,2"
  3. Start with the simplest test case of an empty string. Then 1 number. Then 2 numbers.
  4. Remember to refactor after each passing test.

2. Allow the Add method to handle an unknown number of arguments/numbers.

3. Allow the Add method to handle new lines between numbers (instead of commas)

  1. Example: “1\n2,3” should return 6
  2. Example: “1,\n” is invalid, but you don’t need a test for this case.
  3. Only test correct inputs – there is no need to deal with invalid inputs for this kata.

4. Allow the Add method to handle a different delimiter:

  1. To change the delimiter, the beginning of the string will contain a separate line that looks like this: "//[delimiter]\n[numbers]"
    • Example: "//;\n1;2" should return 3 (the delimiter is ;)
  2. This first line is optional; all existing scenarios (using , or \n) should work as before.

5.Calling Add with a negative number will throw an exception "Negatives not allowed: "listing all negative numbers that were in the list of numbers

  1. Example “-1,2” throws "Negatives not allowed: -1"
  2. Example “2,-4,3,-5” throws "Negatives not allowed: -4,-5"

6.Numbers bigger than 1000 should be ignored

  1. Example: “1001,2” returns 2

kata-string-calculator's People

Contributors

tpierrain avatar boucardbruno avatar

Watchers

 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.