/*
String Calculator
taken from here:
https://codingdojo.org/kata/StringCalculator/
This classic kata guides you step by step through the implementation of a calculator that receives a String as input. It is a good exercise on refactoring and incremental implementation. It is also a good candidate for practising TDD.
First step
Create a function add that takes a String and returns a String:
String add(String number)
The method can take 0, 1 or 2 numbers separated by comma, and returns their sum.
An empty string will return “0”.
Example of inputs: "", "1", "1.1,2.2".
Many numbers
Allow the add method to handle an unknow number of arguments.
Newline as separator
Allow the add method to handle newlines as separators:
"1\n2,3" should return "6".
"175.2,\n35" is invalid and should return the message "Number expected but '\n' found at position 6."
Missing number in last position
Don’t allow the input to end in a separator.
"1,3," is invalid and should return the message Number expected but EOF found.
Custom separators
Allow the add method to handle a different delimiter. To change the delimiter, the beginning of the input will contain a separate line that looks like this:
//[delimiter]\n[numbers]
"//;\n1;2" should return "3"
"//|\n1|2|3" should return "6"
"//sep\n2sep3" should return "5"
"//|\n1|2,3" is invalid and should return the message "'|' expected but ',' found at position 3."
All existing scenarios should work as before.
Negative numbers
Calling add with negative numbers will return the message "Negative not allowed : " listing all negative numbers that were in the list of numbers.
"-1,2" is invalid and should return the message "Negative not allowed : -1"
"2,-4,-5" is invalid and should return the message "Negative not allowed : -4, -5"
Multiple errors
Calling add with multiple errors will return all error messages separated by newlines.
"-1,,2" is invalid and return the message "Negative not allowed : -1\nNumber expected but ',' found at position 3." "-1,,-2" is invalid and return the message "Negative not allowed : -1\nNumber expected but ',' found at position 3.\nNegative not allowed : -2"
Errors management
Introduce an internal add function returning a number instead of a String, and test many solutions for the error messages.
Exception
maybe and monad approch
POSIX return code with message managemement
tuple with error struct like in Go
etc.
Other operations
Write a function for multiply with same rules
*/
function add($s) {
return "";
}
<?php
use PHPUnit\Framework\TestCase;
// PHPUnit Test Examples:
// TODO: Replace examples and use TDD by writing your own tests
class ExampleTest extends TestCase
{
// test function names should start with "test"
public function testThatSomethingShouldHappen() {
$this->assertEquals("0", add(""));
}
}
/**
* String Calculator
* taken from here: https://codingdojo.org/kata/StringCalculator/
*
* This classic kata guides you step by step through the implementation of a
* calculator that receives a String as input. It is a good exercise on
* refactoring and incremental implementation. It is also a good candidate for
* practising TDD.
*
* Tasks:
* First step
* Create a function add that takes a String and returns a String:
*
* String add(String number)
* The method can take 0, 1 or 2 numbers separated by comma, and returns their
* sum.
* An empty string will return “0”.
* Example of inputs: "", "1", "1.1,2.2".
* Many numbers
* Allow the add method to handle an unknow number of arguments.
*
* Newline as separator
* Allow the add method to handle newlines as separators:
*
* "1\n2,3" should return "6".
* "175.2,\n35" is invalid and should return the message "Number expected but
* '\n' found at position 6."
* Missing number in last position
* Don’t allow the input to end in a separator.
*
* "1,3," is invalid and should return the message Number expected but EOF
* found.
*
* Custom separators
* Allow the add method to handle a different delimiter. To change the
* delimiter, the beginning of the input will contain a separate line that looks
* like this:
*
* //[delimiter]\n[numbers]
* "//;\n1;2" should return "3"
* "//|\n1|2|3" should return "6"
* "//sep\n2sep3" should return "5"
* "//|\n1|2,3" is invalid and should return the message "'|' expected but ','
* found at position 3."
* All existing scenarios should work as before.
*
* Negative numbers
* Calling add with negative numbers will return the message "Negative not
* allowed : " listing all negative numbers that were in the list of numbers.
*
* "-1,2" is invalid and should return the message "Negative not allowed : -1"
* "2,-4,-5" is invalid and should return the message "Negative not allowed :
* -4, -5"
* Multiple errors
* Calling add with multiple errors will return all error messages separated by
* newlines.
*
* "-1,,2" is invalid and return the message "Negative not allowed : -1\nNumber
* expected but ',' found at position 3." "-1,,-2" is invalid and return the
* message "Negative not allowed : -1\nNumber expected but ',' found at position
* 3.\nNegative not allowed : -2"
*
* Errors management
* Introduce an internal add function returning a number instead of a String,
* and test many solutions for the error messages.
*
* Exception
* maybe and monad approch
* POSIX return code with message managemement
* tuple with error struct like in Go
* etc.
* Other operations
* Write a function for multiply with same rules
**/
using System;
namespace Solution
{
public class Kata
{
public static string Add(string s)
{
return "10";
}
}
}
namespace Solution {
using NUnit.Framework;
using System;
// TODO: Replace examples and use TDD by writing your own tests
[TestFixture]
public class SolutionTest
{
[Test]
public void MyTest()
{
Assert.AreEqual("0", Kata.Add(""));
}
}
}
/**
* String Calculator
* taken from here: https://codingdojo.org/kata/StringCalculator/
*
* This classic kata guides you step by step through the implementation of a
* calculator that receives a String as input. It is a good exercise on
* refactoring and incremental implementation. It is also a good candidate for
* practising TDD.
*
* Tasks:
* First step
* Create a function add that takes a String and returns a String:
*
* String add(String number)
* The method can take 0, 1 or 2 numbers separated by comma, and returns their
* sum.
* An empty string will return “0”.
* Example of inputs: "", "1", "1.1,2.2".
* Many numbers
* Allow the add method to handle an unknow number of arguments.
*
* Newline as separator
* Allow the add method to handle newlines as separators:
*
* "1\n2,3" should return "6".
* "175.2,\n35" is invalid and should return the message "Number expected but
* '\n' found at position 6."
* Missing number in last position
* Don’t allow the input to end in a separator.
*
* "1,3," is invalid and should return the message Number expected but EOF
* found.
*
* Custom separators
* Allow the add method to handle a different delimiter. To change the
* delimiter, the beginning of the input will contain a separate line that looks
* like this:
*
* //[delimiter]\n[numbers]
* "//;\n1;2" should return "3"
* "//|\n1|2|3" should return "6"
* "//sep\n2sep3" should return "5"
* "//|\n1|2,3" is invalid and should return the message "'|' expected but ','
* found at position 3."
* All existing scenarios should work as before.
*
* Negative numbers
* Calling add with negative numbers will return the message "Negative not
* allowed : " listing all negative numbers that were in the list of numbers.
*
* "-1,2" is invalid and should return the message "Negative not allowed : -1"
* "2,-4,-5" is invalid and should return the message "Negative not allowed :
* -4, -5"
* Multiple errors
* Calling add with multiple errors will return all error messages separated by
* newlines.
*
* "-1,,2" is invalid and return the message "Negative not allowed : -1\nNumber
* expected but ',' found at position 3." "-1,,-2" is invalid and return the
* message "Negative not allowed : -1\nNumber expected but ',' found at position
* 3.\nNegative not allowed : -2"
*
* Errors management
* Introduce an internal add function returning a number instead of a String,
* and test many solutions for the error messages.
*
* Exception
* maybe and monad approch
* POSIX return code with message managemement
* tuple with error struct like in Go
* etc.
* Other operations
* Write a function for multiply with same rules
**/
function add(s) { return "" }
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
assert.strictEqual("0", add(""));
});
});
/**
* String Calculator
* taken from here: https://codingdojo.org/kata/StringCalculator/
*
* This classic kata guides you step by step through the implementation of a
* calculator that receives a String as input. It is a good exercise on
* refactoring and incremental implementation. It is also a good candidate for
* practising TDD.
*
* Tasks:
* First step
* Create a function add that takes a String and returns a String:
*
* String add(String number)
* The method can take 0, 1 or 2 numbers separated by comma, and returns their
* sum.
* An empty string will return “0”.
* Example of inputs: "", "1", "1.1,2.2".
* Many numbers
* Allow the add method to handle an unknow number of arguments.
*
* Newline as separator
* Allow the add method to handle newlines as separators:
*
* "1\n2,3" should return "6".
* "175.2,\n35" is invalid and should return the message "Number expected but
* '\n' found at position 6."
* Missing number in last position
* Don’t allow the input to end in a separator.
*
* "1,3," is invalid and should return the message Number expected but EOF
* found.
*
* Custom separators
* Allow the add method to handle a different delimiter. To change the
* delimiter, the beginning of the input will contain a separate line that looks
* like this:
*
* //[delimiter]\n[numbers]
* "//;\n1;2" should return "3"
* "//|\n1|2|3" should return "6"
* "//sep\n2sep3" should return "5"
* "//|\n1|2,3" is invalid and should return the message "'|' expected but ','
* found at position 3."
* All existing scenarios should work as before.
*
* Negative numbers
* Calling add with negative numbers will return the message "Negative not
* allowed : " listing all negative numbers that were in the list of numbers.
*
* "-1,2" is invalid and should return the message "Negative not allowed : -1"
* "2,-4,-5" is invalid and should return the message "Negative not allowed :
* -4, -5"
* Multiple errors
* Calling add with multiple errors will return all error messages separated by
* newlines.
*
* "-1,,2" is invalid and return the message "Negative not allowed : -1\nNumber
* expected but ',' found at position 3." "-1,,-2" is invalid and return the
* message "Negative not allowed : -1\nNumber expected but ',' found at position
* 3.\nNegative not allowed : -2"
*
* Errors management
* Introduce an internal add function returning a number instead of a String,
* and test many solutions for the error messages.
*
* Exception
* maybe and monad approch
* POSIX return code with message managemement
* tuple with error struct like in Go
* etc.
* Other operations
* Write a function for multiply with same rules
**/
class Main {
public static String add(String args) {
return "";
}
}
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
// TODO: Replace examples and use TDD by writing your own tests
class SolutionTest {
@Test
void testSomething() {
assertEquals("0", Main.add(""));
}
}
/**
The output of this kata is the number you need to create the metal sign
with your fingers, using these rules:
- You start with all fingers "up"
- You count from your thumb
- You put the finger where you end down
- You start again with your thumb (or the next finger which is up)
- If your number is not yet reached and you are out of fingers you count on with the "left" side
- The Metal Sign is Thumb down, Index up, Middle down, Ring down, Pinky up
- Have fun :-)
- If you are really fast you can also try with the "Double Metal" (Same with 10 Fingers)
**/
function calculate(){
console.log(0);
}
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
calculate();
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});
using System;
class Program {
public static void Calculate () {
Console.WriteLine ("Hello World");
}
}
/**
The output of this kata is the number you need to create the metal sign
with your fingers, using these rules:
- You start with all fingers "up"
- You count from your thumb
- You put the finger where you end down
- You start again with your thumb (or the next finger which is up)
- If your number is not yet reached and you are out of fingers you count on with the "left" side
- The Metal Sign is Thumb down, Index up, Middle down, Ring down, Pinky up
- Have fun :-)
- If you are really fast you can also try with the "Double Metal" (Same with 10 Fingers)
**/
namespace Solution {
using NUnit.Framework;
using System;
// TODO: Replace examples and use TDD by writing your own tests
[TestFixture]
public class SolutionTest
{
[Test]
public void MyTest()
{
Program.Calculate();
Assert.AreEqual("expected", "expected");
}
}
}
/**
The output of this kata is the number you need to create the metal sign
with your fingers, using these rules:
- You start with all fingers "up"
- You count from your thumb
- You put the finger where you end down
- You start again with your thumb (or the next finger which is up)
- If your number is not yet reached and you are out of fingers you count on with the "left" side
- The Metal Sign is Thumb down, Index up, Middle down, Ring down, Pinky up
- Have fun :-)
- If you are really fast you can also try with the "Double Metal" (Same with 10 Fingers)
*/
function calculate(): int {
return 0;
}
<?php
use PHPUnit\Framework\TestCase;
// PHPUnit Test Examples:
// TODO: Replace examples and use TDD by writing your own tests
class ExampleTest extends TestCase
{
// test function names should start with "test"
public function testRunMethod() {
print calculate();
$this->assertEquals("a", "a");
}
}
/**
The output of this kata is the number you need to create the metal sign
with your fingers, using these rules:
- You start with all fingers "up"
- You count from your thumb
- You put the finger where you end down
- You start again with your thumb (or the next finger which is up)
- If your number is not yet reached and you are out of fingers you count on with the "left" side
- The Metal Sign is Thumb down, Index up, Middle down, Ring down, Pinky up
- Have fun :-)
- If you are really fast you can also try with the "Double Metal" (Same with 10 Fingers)
**/
class MetalSign {
public static int calculate() {
return 0;
}
}
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class SolutionTest {
@Test
void runMethod() {
// assertEquals("expected", "actual");
System.out.println(MetalSign.calculate());
}
}