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.
const wordCount = x => x.trim().split(/[^\w-]+/).filter(s => s!== "").length
const wordCount = x => x.trim().split` `.length- const wordCount = x => x.trim().split(/[^\w-]+/).filter(s => s!== "").length
// 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(); Test.assertEquals(wordCount(" v"), 1); Test.assertEquals(wordCount("Word"), 1); Test.assertEquals(wordCount("Wo r d"), 3); Test.assertEquals(wordCount("Bob the t-rex"), 3); Test.assertEquals(wordCount("More spaces"), 2); Test.assertEquals(wordCount("Fish&Chips"), 2); Test.assertEquals(wordCount("Ending non word char!"), 4); Test.assertEquals(wordCount("'starting non word char"), 4); Test.assertEquals(wordCount("Punctuation signs: they must work. I say!"), 7);
- // 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();
- Test.assertEquals(wordCount(" v"), 1);
- Test.assertEquals(wordCount("Word"), 1);
- Test.assertEquals(wordCount("Wo r d"), 3);
- Test.assertEquals(wordCount("Bob the t-rex"), 3);
- Test.assertEquals(wordCount("More spaces"), 2);
- Test.assertEquals(wordCount("Fish&Chips"), 2);
- Test.assertEquals(wordCount("Ending non word char!"), 4);
- Test.assertEquals(wordCount("'starting non word char"), 4);
- Test.assertEquals(wordCount("Punctuation signs: they must work. I say!"), 7);
function sumOfMultiplesUnder(n) { return sumAll(--n,3) + sumAll(n,5) - sumAll(n,15); } function sumAll(n,m){ return m * (Math.floor(n/m) + 1) * Math.floor(n/m)/2; }
- function sumOfMultiplesUnder(n) {
return sumAll(--n,3)+sumAll(n,5)-sumAll(n,15)- return sumAll(--n,3) + sumAll(n,5) - sumAll(n,15);
- }
- function sumAll(n,m){
return m*(Math.floor(n/m)+1)*Math.floor(n/m)/2- return m * (Math.floor(n/m) + 1) * Math.floor(n/m)/2;
- }
describe("Basic Tests", function(){ it("It should works for basic tests.", function(){ Test.assertEquals(sumOfMultiplesUnder(10),23); Test.assertEquals(sumOfMultiplesUnder(100),2318); Test.assertEquals(sumOfMultiplesUnder(1000),233168); Test.assertEquals(sumOfMultiplesUnder(10000),23331668); Test.assertEquals(sumOfMultiplesUnder(100000),2333316668); Test.assertEquals(sumOfMultiplesUnder(1000000),233333166668); Test.assertEquals(sumOfMultiplesUnder(10000000),23333331666668); }); });
- describe("Basic Tests", function(){
it("It should works for basic tests.", function(){Test.assertEquals(sumOfMultiplesUnder(10),23)Test.assertEquals(sumOfMultiplesUnder(100),2318)Test.assertEquals(sumOfMultiplesUnder(1000),233168)Test.assertEquals(sumOfMultiplesUnder(10000),23331668)Test.assertEquals(sumOfMultiplesUnder(100000),2333316668)Test.assertEquals(sumOfMultiplesUnder(1000000),233333166668)Test.assertEquals(sumOfMultiplesUnder(10000000),23333331666668)})})- it("It should works for basic tests.", function(){
- Test.assertEquals(sumOfMultiplesUnder(10),23);
- Test.assertEquals(sumOfMultiplesUnder(100),2318);
- Test.assertEquals(sumOfMultiplesUnder(1000),233168);
- Test.assertEquals(sumOfMultiplesUnder(10000),23331668);
- Test.assertEquals(sumOfMultiplesUnder(100000),2333316668);
- Test.assertEquals(sumOfMultiplesUnder(1000000),233333166668);
- Test.assertEquals(sumOfMultiplesUnder(10000000),23333331666668);
- });
- });
Added asserts for input validation.
Changed all int types to double
Reduced complexity by using floor() instead... test cases are still passing. (but there is some floating-point voodoo happening)
Added cout for future use.
#include <cmath> #include <cassert> #include <iomanip> double custom_sqrt( double a, int accuracy=20 ) { assert( 0 <= a ); assert( 0 <= accuracy ); assert( 307 >= accuracy ); // evidently, values larger than 307 cause overflow const double ACC = std::pow( 10.0, accuracy ); double result = sqrt( a ); result *= ACC; result = std::floor( result ); result /= ACC; //std::cout << std::setprecision(21) << result << std::endl; assert( 0 <= result ); return result; }
#include <math.h>- #include <cmath>
- #include <cassert>
- #include <iomanip>
double custom_sqrt (int a,int accuracy=20) {double fIntegerPart;double fFloatingPart = modf((double)sqrt(a), &fIntegerPart);double fTempFloat = fFloatingPart * pow(10, accuracy);double fTempInt;fTempFloat = modf(fTempFloat, &fTempInt);fTempFloat /= pow(10, accuracy);fFloatingPart -= fTempFloat;return fIntegerPart+fFloatingPart;- double custom_sqrt( double a, int accuracy=20 ) {
- assert( 0 <= a );
- assert( 0 <= accuracy );
- assert( 307 >= accuracy ); // evidently, values larger than 307 cause overflow
- const double ACC = std::pow( 10.0, accuracy );
- double result = sqrt( a );
- result *= ACC;
- result = std::floor( result );
- result /= ACC;
- //std::cout << std::setprecision(21) << result << std::endl;
- assert( 0 <= result );
- return result;
- }
// TODO: Replace examples and use TDD development by writing your own tests Describe(square_root) { It(should_take_square_root) { Assert::That(custom_sqrt(4), Equals(2)); Assert::That(custom_sqrt(16), Equals(4)); Assert::That(custom_sqrt(169), Equals(13)); Assert::That(custom_sqrt(8, 2), Equals(2.82)); Assert::That(custom_sqrt(8, 5), Equals(2.82842)); Assert::That(custom_sqrt(2, 11), Equals(1.41421356237)); Assert::That(custom_sqrt(2), Equals(1.41421356237309514547)); } };
- // TODO: Replace examples and use TDD development by writing your own tests
- Describe(square_root)
- {
- It(should_take_square_root)
- {
- Assert::That(custom_sqrt(4), Equals(2));
- Assert::That(custom_sqrt(16), Equals(4));
- Assert::That(custom_sqrt(169), Equals(13));
- Assert::That(custom_sqrt(8, 2), Equals(2.82));
- Assert::That(custom_sqrt(8, 5), Equals(2.82842));
- Assert::That(custom_sqrt(2, 11), Equals(1.41421356237));
- Assert::That(custom_sqrt(2), Equals(1.41421356237309514547));
- }
- };
public class CountTheDigit { public static int count(int num, int digit) { int result = 0; do { if (num % 10 == digit) ++result; num /= 10; } while (num != 0); return result; } public static int nbDig(int n, int d) { int result = 0; for(int i = 0; i < n; ++i) result += count(i * i, d); return result; } }
- public class CountTheDigit {
- public static int count(int num, int digit) {
- int result = 0;
- do {
- if (num % 10 == digit)
- ++result;
- num /= 10;
- } while (num != 0);
- return result;
- }
- public static int nbDig(int n, int d) {
int count=0;for(int i=0; i<n; i++) {String number=(i*i)+"";count += number.length() - number.replace(d+"", "").length();}return count;- int result = 0;
- for(int i = 0; i < n; ++i)
- result += count(i * i, d);
- return result;
- }
- }
C# 7.0+ features allow for syntatic sugar to reduce coding length. As well, the tests were using Is.Equal when Is.True and Is.False exist.
namespace Solution { using System; public static class logic { public static bool Or(bool i, bool j) => i.i() + j.i() >= 1; public static bool And(bool i, bool j) => i.i() + j.i() == 2; public static bool Xor(bool i, bool j) => i.i() + j.i() == 1; } public static class BoolExtensions { public static int i(this bool val) => Convert.ToInt32(val); } }
- 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 bool Or(bool i, bool j) => i.i() + j.i() >= 1;
- public static bool And(bool i, bool j) => i.i() + j.i() == 2;
- public static bool Xor(bool i, bool j) => i.i() + j.i() == 1;
- }
- public static class BoolExtensions
- {
public static int i(this bool val){return Convert.ToInt32(val);}- public static int i(this bool val) => 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.False); Assert.That(logic.And(false, true), Is.False); Assert.That(logic.And(true, true), Is.True); Assert.That(logic.And(false, false), Is.False); } [Test] public void OR() { Assert.That(logic.Or(true, false), Is.True); Assert.That(logic.Or(false, true), Is.True); Assert.That(logic.Or(true, true), Is.True); Assert.That(logic.Or(false, false), Is.False); } [Test] public void XOR() { Assert.That(logic.Xor(true, false), Is.True); Assert.That(logic.Xor(false, true), Is.True); Assert.That(logic.Xor(true, true), Is.False); Assert.That(logic.Xor(false, false), Is.False); } } }
- 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.False);
- Assert.That(logic.And(false, true), Is.False);
- Assert.That(logic.And(true, true), Is.True);
- Assert.That(logic.And(false, false), Is.False);
- }
[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));}- [Test]
- public void OR()
- {
- Assert.That(logic.Or(true, false), Is.True);
- Assert.That(logic.Or(false, true), Is.True);
- Assert.That(logic.Or(true, true), Is.True);
- Assert.That(logic.Or(false, false), Is.False);
- }
- [Test]
- public void XOR()
- {
- Assert.That(logic.Xor(true, false), Is.True);
- Assert.That(logic.Xor(false, true), Is.True);
- Assert.That(logic.Xor(true, true), Is.False);
- Assert.That(logic.Xor(false, false), Is.False);
- }
- }
}- }