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.
- Adds a second argument to
generateComment
,seed
, which allows for deterministic strings - Adds a few tests (still bad coverage)
const generateComment = (array = [], seed) => (seed => array.map((each, ii) => each[seed[ii]]).join` `) (seed ? seed.split`.`.map(Number) : array.map(ii => Math.round(Math.random() * (ii.length - 1)))) const dictionary = [ ['hi,', 'hello,', 'hey,'], ['how are'], ['you', 'ya'], ['doing', 'going'], ['?', '?!', ''] ] console.log(generateComment(dictionary)) console.log(generateComment(dictionary, '2.0.1.0.1'))
const generateComment = array => array.map(x=>x[Math.floor(Math.random() * x.length)]).join` `- const generateComment = (array = [], seed) =>
- (seed => array.map((each, ii) => each[seed[ii]]).join` `)
- (seed
- ? seed.split`.`.map(Number)
- : array.map(ii => Math.round(Math.random() * (ii.length - 1))))
- const dictionary = [
- ['hi,', 'hello,', 'hey,'],
- ['how are'],
- ['you', 'ya'],
- ['doing', 'going'],
- ['?', '?!', '']
- ]
// console.log(generateComment([['hi,', 'hello,', 'hey,'], ['how are'], ['you', 'ya'], ['doing', 'going'], ['?', '?!', '']]));- console.log(generateComment(dictionary))
- console.log(generateComment(dictionary, '2.0.1.0.1'))
describe('generateComment', () => { it('should work with null values', () => { Test.assertEquals(typeof generateComment(), 'string') }) it('should return a string from any array', () => { Test.assertEquals( typeof generateComment([['sup', 'yo'], ['mate', 'buddy']]), 'string' ) }) it('should work deterministically if a second argument is provided', () => { Test.assertEquals( generateComment(dictionary, '2.0.1.0.1'), 'hey, how are ya doing ?!', 'Strings don\'t match' ) Test.assertEquals( generateComment(dictionary, '0.0.0.0.0'), 'hi, how are you doing ?', 'Strings don\'t match' ) }) })
// TODO: Replace examples and use TDD development by writing your own tests- describe('generateComment', () => {
- it('should work with null values', () => {
- Test.assertEquals(typeof generateComment(), 'string')
- })
- it('should return a string from any array', () => {
- Test.assertEquals(
- typeof generateComment([['sup', 'yo'], ['mate', 'buddy']]),
- 'string'
- )
- })
// 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("Test for the given arrays", function(){Test.assertEquals([['hi,', 'hello,', 'hey,'], ['how are'], ['you', 'ya'], ['doing', 'going'], ['?','?!', '']], 'hi, how are you doing?');});});*/- it('should work deterministically if a second argument is provided', () => {
- Test.assertEquals(
- generateComment(dictionary, '2.0.1.0.1'),
- 'hey, how are ya doing ?!',
- 'Strings don\'t match'
- )
- Test.assertEquals(
- generateComment(dictionary, '0.0.0.0.0'),
- 'hi, how are you doing ?',
- 'Strings don\'t match'
- )
- })
- })
const sum = array => array.reduce((total, n) => total + n, 0);
const getSum = array => array.reduce((acc, i) => acc + i)- const sum = array => array.reduce((total, n) => total + n, 0);
Test.assertEquals(sum([]), 0); Test.assertEquals(sum([5,9,4,1]), 19); Test.assertEquals(sum([4,0,4,50,8]), 66); Test.assertEquals(sum([5,9,4,1,9,1,1,1,4,10]), 45);
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(sum([]), 0);
- Test.assertEquals(sum([5,9,4,1]), 19);
- Test.assertEquals(sum([4,0,4,50,8]), 66);
- Test.assertEquals(sum([5,9,4,1,9,1,1,1,4,10]), 45);
function a(){ // We shall remove the following solution when publish as KATA static $poi = null; if ($poi) return $poi->create(); $poi = new class { public function create() { return new static(); } }; return $poi->create(); }
- function a(){
- // We shall remove the following solution when publish as KATA
- static $poi = null;
- if ($poi) return $poi->create();
- $poi = new class {
- public function create() {
- return new static();
- }
- };
- return $poi->create();
- }
// PHPUnit Test Examples: // TODO: Replace examples and use TDD development by writing your own tests class MyTestCases extends TestCase { // test function names should start with "test" public function testSameClassName() { $this->assertSame(get_class(a()), get_class(a())); } public function testAnonymous() { $this->assertSame(0, strpos(get_class(a()), "class@anonymous")); } public function testDifferentIns() { $this->assertSame(a() !== a(), true); } }
- // PHPUnit Test Examples:
- // TODO: Replace examples and use TDD development by writing your own tests
- class MyTestCases extends TestCase
- {
- // test function names should start with "test"
public function testThatSomethingShouldHappen() {- public function testSameClassName() {
- $this->assertSame(get_class(a()), get_class(a()));
- }
- public function testAnonymous() {
- $this->assertSame(0, strpos(get_class(a()), "class@anonymous"));
- }
- public function testDifferentIns() {
- $this->assertSame(a() !== a(), true);
- }
- }
One line version with error output as lambda (analog of arrow function in Python) looks like this.
div = lambda num1, num2 : print("Division failed: division by zero") if num2 == 0 else print("Division failed: integers and floats accepted only") if not(isinstance(num1, (int, float)) and isinstance(num2, (int, float))) else num1 / num2
let divide = (num1, num2) => num2 === 0 ? console.log("Division failed: division by zero") : !(num1 === +num1 && num2 === +num2) ? console.log("Division failed: integers and floats accepted only") : num1/num2- div = lambda num1, num2 : print("Division failed: division by zero") if num2 == 0 else print("Division failed: integers and floats accepted only") if not(isinstance(num1, (int, float)) and isinstance(num2, (int, float))) else num1 / num2