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.
namespace Solution { using System; public static class logic { public static bool Or(bool i, bool j) { return i.i() + j.i() >= 1; } public static bool And(bool i, bool j) { return i.i() + j.i() == 2; } public static bool Xor(bool i, bool j) { return i.i() + j.i() == 1; } } public static class BoolExtensions { public static int i(this bool val) { return Convert.ToInt32(val); } } }
bool Or(bool i, bool j){ return (i+""+j).Contains("T");}bool And(bool i, bool j) {return !(i+""+j).Contains("F");}bool Xor(bool i, bool j){return i.CompareTo(j)*i.CompareTo(j)>0;}- namespace Solution
- {
- using System;
- public static class logic
- {
- public static bool Or(bool i, bool j) { return i.i() + j.i() >= 1; }
- public static bool And(bool i, bool j) { return i.i() + j.i() == 2; }
- public static bool Xor(bool i, bool j) { return i.i() + j.i() == 1; }
- }
- public static class BoolExtensions
- {
- public static int i(this bool val)
- {
- return Convert.ToInt32(val);
- }
- }
- }
namespace Solution { using NUnit.Framework; using System; using System.Collections.Generic; [TestFixture] public class Sample_Tests { [Test] public void AND() { Assert.That(logic.And(true, false), Is.EqualTo(false)); Assert.That(logic.And(false, true), Is.EqualTo(false)); Assert.That(logic.And(true, true), Is.EqualTo(true)); Assert.That(logic.And(false, false), Is.EqualTo(false)); } [Test] public void OR() { Assert.That(logic.Or(true, false), Is.EqualTo(true)); Assert.That(logic.Or(false, true), Is.EqualTo(true)); Assert.That(logic.Or(true, true), Is.EqualTo(true)); Assert.That(logic.Or(false, false), Is.EqualTo(false)); } [Test] public void XOR() { Assert.That(logic.Xor(true, false), Is.EqualTo(true)); Assert.That(logic.Xor(false, true), Is.EqualTo(true)); Assert.That(logic.Xor(true, true), Is.EqualTo(false)); Assert.That(logic.Xor(false, false), Is.EqualTo(false)); } } }
// TODO: Replace examples and use TDD development by writing your own testsDescribe(AND_OR_XOR)- namespace Solution
- {
It(AND){Assert::That(And(true, false), Equals(false));Assert::That(And(false, true), Equals(false));Assert::That(And(true, true), Equals(true));Assert::That(And(false, false), Equals(false));}It(OR){Assert::That(Or(true, false), Equals(true));Assert::That(Or(false, true), Equals(true));Assert::That(Or(true, true), Equals(true));Assert::That(Or(false, false), Equals(false));}It(XOR){Assert::That(Xor(true, false), Equals(true));Assert::That(Xor(false, true), Equals(true));Assert::That(Xor(true, true), Equals(false));Assert::That(Xor(false, false), Equals(false));}};- using NUnit.Framework;
- using System;
- using System.Collections.Generic;
- [TestFixture]
- public class Sample_Tests
- {
- [Test]
- public void AND()
- {
- Assert.That(logic.And(true, false), Is.EqualTo(false));
- Assert.That(logic.And(false, true), Is.EqualTo(false));
- Assert.That(logic.And(true, true), Is.EqualTo(true));
- Assert.That(logic.And(false, false), Is.EqualTo(false));
- }
- [Test]
- public void OR()
- {
- Assert.That(logic.Or(true, false), Is.EqualTo(true));
- Assert.That(logic.Or(false, true), Is.EqualTo(true));
- Assert.That(logic.Or(true, true), Is.EqualTo(true));
- Assert.That(logic.Or(false, false), Is.EqualTo(false));
- }
- [Test]
- public void XOR()
- {
- Assert.That(logic.Xor(true, false), Is.EqualTo(true));
- Assert.That(logic.Xor(false, true), Is.EqualTo(true));
- Assert.That(logic.Xor(true, true), Is.EqualTo(false));
- Assert.That(logic.Xor(false, false), Is.EqualTo(false));
- }
- }
- }
- Implemented addition-subtraction swap. Unlike the most obvious solution — XOR swap — it works with double.
- In Igloo, it's advisable to compare doubles using EqualsWithDelta in lieu of Equals.
#include <algorithm> #include <math.h> template< class T > void Swap( T& a, T& b ) { a = a + b; b = a - b; a = a - b; }
- #include <algorithm>
- #include <math.h>
- template< class T >
void Swap( T& a, T& b ) { std::swap( a, b ); }- void Swap( T& a, T& b )
- {
- a = a + b;
- b = a - b;
- a = a - b;
- }
Describe(Tests) { It(Swaps) { int a = 1, b = 2; bool c = true, d = false; double e = 3.14, f = 6.28; Swap( a, b ); Swap( c, d ); Swap( e, f ); Assert::That( a, Equals(2)); Assert::That( b, Equals(1)); Assert::That( c, Equals(false)); Assert::That( d, Equals(true)); Assert::That( e, EqualsWithDelta(6.28, 0.1)); Assert::That( f, EqualsWithDelta(3.14, 0.1)); } };
- Describe(Tests)
- {
- It(Swaps)
- {
- int a = 1, b = 2;
- bool c = true, d = false;
- double e = 3.14, f = 6.28;
- Swap( a, b );
- Swap( c, d );
- Swap( e, f );
- Assert::That( a, Equals(2));
- Assert::That( b, Equals(1));
- Assert::That( c, Equals(false));
- Assert::That( d, Equals(true));
Assert::That( e, Equals(6.28));Assert::That( f, Equals(3.14));- Assert::That( e, EqualsWithDelta(6.28, 0.1));
- Assert::That( f, EqualsWithDelta(3.14, 0.1));
- }
- };
const rp = require('request-promise'); async function getUserAllies(username) { const html = await rp(`https://www.codewars.com/users/${username}`); const [, allies] = html.match(/<div class=\"stat\"><b>Allies:<\/b>(\d+)<\/div>/); return +allies; }
// const request = require('request');// function getUserAllies(username){// return new Promise(function(resolve, reject){// request('https://www.codewars.com/users/'+username, function(err, res, body){// let html = body;// let allies = (html.match(/<div class=\"stat\"><b>Allies:<\/b>(\d+)<\/div>/) || [,'null match'])[1];// resolve(+allies);// });// });// }// using request-promise to avoid wrapping a Promise- const rp = require('request-promise');
function getUserAllies(username){return new Promise(() => {}); // never resolves}- async function getUserAllies(username) {
- const html = await rp(`https://www.codewars.com/users/${username}`);
- const [, allies] = html.match(/<div class=\"stat\"><b>Allies:<\/b>(\d+)<\/div>/);
- return +allies;
- }
// might fail because allies can change. const tests = [['myjinxin2015', 19], ['g964', 617], ['Voile', 206], ['SteffenVogel_79', 46], ['smile67', 20]]; describe('getUserAllies', 5000, () => { it('should return the number of allies', async (done) => { await Promise.all(tests.map(async ([user, allies]) => { const data = await (getUserAllies(user)); Test.assertEquals(data, allies, `Incorrect numbers of allies for ${user}!`); })); done(); }); });
- // might fail because allies can change.
- const tests = [['myjinxin2015', 19], ['g964', 617], ['Voile', 206], ['SteffenVogel_79', 46], ['smile67', 20]];
describe('getUserAllies', 5000, function(){it('should return the number of allies', function(done) {return Promise.all(tests.map(([user, allies]) =>getUserAllies(user).then(data => Test.assertEquals(data, allies, `Incorrect numbers of allies for ${user}!`)))).then(done); // never succeeds => fails- describe('getUserAllies', 5000, () => {
- it('should return the number of allies', async (done) => {
- await Promise.all(tests.map(async ([user, allies]) => {
- const data = await (getUserAllies(user));
- Test.assertEquals(data, allies, `Incorrect numbers of allies for ${user}!`);
- }));
- done();
- });
- });
const hello = () => 'world';
function hello() {return "world";}- const hello = () => 'world';
describe("Solution", function(){ it("should return world as a string", function(){ Test.assertEquals(hello(), "world"); }); });
- describe("Solution", function(){
it("should test for something", function(){- it("should return world as a string", function(){
- Test.assertEquals(hello(), "world");
- });
- });