Kumite (ko͞omiˌtā) is the practice of taking techniques learned from Kata and applying them through the act of freestyle sparring.
You can create a new kumite by providing some initial code and optionally some test cases. From there other warriors can spar with you, by enhancing, refactoring and translating your code. There is no limit to how many warriors you can spar with.
A great use for kumite is to begin an idea for a kata as one. You can collaborate with other code warriors until you have it right, then you can convert it to a kata.
// TODO: Replace examples and use TDD development by writing your own tests // These are some CW specific test methods available: // Test.expect(boolean, [optional] message) // Test.assertEquals(actual, expected, [optional] message) // Test.assertSimilar(actual, expected, [optional] message) // Test.assertNotEquals(actual, expected, [optional] message) // NodeJS assert is also automatically required for you. // assert(true) // assert.strictEqual({a: 1}, {a: 1}) // assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]}) // You can also use Chai (http://chaijs.com/) by requiring it yourself // var expect = require("chai").expect; // var assert = require("chai").assert; // require("chai").should(); describe("Solution", function(){ it("should test for something", function(){ Test.assertEquals(ronalado(), "expected", "This is just an example of how you can write your own TDD tests"); }); });
- // TODO: Replace examples and use TDD development by writing your own tests
- // These are some CW specific test methods available:
- // Test.expect(boolean, [optional] message)
- // Test.assertEquals(actual, expected, [optional] message)
- // Test.assertSimilar(actual, expected, [optional] message)
- // Test.assertNotEquals(actual, expected, [optional] message)
- // NodeJS assert is also automatically required for you.
- // assert(true)
- // assert.strictEqual({a: 1}, {a: 1})
- // assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]})
- // You can also use Chai (http://chaijs.com/) by requiring it yourself
- // var expect = require("chai").expect;
- // var assert = require("chai").assert;
- // require("chai").should();
- describe("Solution", function(){
- it("should test for something", function(){
Test.assertEquals("actual", "expected", "This is just an example of how you can write your own TDD tests");- Test.assertEquals(ronalado(), "expected", "This is just an example of how you can write your own TDD tests");
- });
- });
Make function negative-safe
def fibonacci(x): if x < 0: return None if x == 0 or x == 1: return x return fibonacci(x - 1) + fibonacci(x - 2)
- def fibonacci(x):
- if x < 0:
- return None
- if x == 0 or x == 1:
- return x
else :return fibonacci(x-1) + fibonacci(x-2)- return fibonacci(x - 1) + fibonacci(x - 2)
Test.describe('fibonacci(n)') Test.it('should calculate properly') test.assert_equals(fibonacci(8), 21) Test.it('should fail if n is negative') test.assert_equals(fibonacci(-1), None)
# TODO: Replace examples and use TDD development by writing your own tests# These are some of the methods available:# test.expect(boolean, [optional] message)test.assert_equals(fibonacci(8),21 )# test.assert_not_equals(actual, expected, [optional] message)- Test.describe('fibonacci(n)')
- Test.it('should calculate properly')
- test.assert_equals(fibonacci(8), 21)
# You can use Test.describe and Test.it to write BDD style test groupings- Test.it('should fail if n is negative')
- test.assert_equals(fibonacci(-1), None)
The original solution did not cover for empty string.
Also, you can remove completly the sum part from the reduce as to make it simpler to read.
const sum = (a,b) => a+b; const getSum = array => array.reduce(sum,0);
const getSum = array => array.reduce((acc, i) => acc + i)- const sum = (a,b) => a+b;
- const getSum = array => array.reduce(sum,0);
Test.assertEquals(getSum([5,9,4,1]), 19, "looks like its wrong."); Test.assertEquals(getSum([4,0,4,50,8]), 66, "looks like its wrong."); Test.assertEquals(getSum([5,9,4,1,9,1,1,1,4,10]), 45, "looks like its wrong."); Test.assertEquals(getSum([]),0, "Error on empty array");
- Test.assertEquals(getSum([5,9,4,1]), 19, "looks like its wrong.");
- Test.assertEquals(getSum([4,0,4,50,8]), 66, "looks like its wrong.");
- Test.assertEquals(getSum([5,9,4,1,9,1,1,1,4,10]), 45, "looks like its wrong.");
- Test.assertEquals(getSum([]),0, "Error on empty array");
Just another way... A ternary way.
public class BiggerNum{ /** * @param a integer of param1 * @param b integer of param2 * @return the bigger integer of a and b * If a equals b, return either one */ public static int compare(int a, int b) { return a > b ? a : a < b ? b : a; } }
- public class BiggerNum{
- /**
- * @param a integer of param1
- * @param b integer of param2
- * @return the bigger integer of a and b
- * If a equals b, return either one
- */
- public static int compare(int a, int b) {
return Math.max(a,b);- return a > b ? a : a < b ? b : a;
- }
- }
def decrypt(message): decode = '' modifier = -1 shift = int((len(message) -1) / 2) for i in range(len(message)): shift += i * modifier decode += message[shift] modifier *= -1 return decode
import math- def decrypt(message):
# JUST DO ITreturn message- decode = ''
- modifier = -1
- shift = int((len(message) -1) / 2)
- for i in range(len(message)):
- shift += i * modifier
- decode += message[shift]
- modifier *= -1
- return decode
import random def pi_estimate(n, seed=0): random.seed(seed) n_inside = 0 for i in range(n): if random.random()**2 + random.random()**2 < 1: n_inside += 1 return 4 * (n_inside / n)
- import random
def PiEstimate(runs):random.seed(0)inner = 0- def pi_estimate(n, seed=0):
- random.seed(seed)
- n_inside = 0
- for i in range(n):
- if random.random()**2 + random.random()**2 < 1:
inner += 1return 4 * (inner / n)- n_inside += 1
- return 4 * (n_inside / n)
# TODO: Replace examples and use TDD development by writing your own tests # These are some of the methods available: # test.expect(boolean, [optional] message) # test.assert_equals(100000, 3.14844) # test.assert_equals(1000000, 3.14244) test.assert_equals(pi_estimate(1000, seed=42), 3.128) test.assert_equals(pi_estimate(1000000, seed=42), 3.140592) # You can use Test.describe and Test.it to write BDD style test groupings
- # TODO: Replace examples and use TDD development by writing your own tests
- # These are some of the methods available:
- # test.expect(boolean, [optional] message)
- # test.assert_equals(100000, 3.14844)
- # test.assert_equals(1000000, 3.14244)
test.assert_not_equals(2000000, 3.141634)- test.assert_equals(pi_estimate(1000, seed=42), 3.128)
- test.assert_equals(pi_estimate(1000000, seed=42), 3.140592)
- # You can use Test.describe and Test.it to write BDD style test groupings