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.
function stripEnds(s, prefix, suffix) { return s.replace(new RegExp(`[${prefix}${suffix}]`, 'gi'), ''); }
- function stripEnds(s, prefix, suffix) {
return s.replace(prefix, '').replace(suffix, '');- return s.replace(new RegExp(`[${prefix}${suffix}]`, 'gi'), '');
- }
const chai = require("chai"); const assert = chai.assert; describe("Solution", function() { it("Test Case", function() { assert.strictEqual(stripEnds("$1.00/day", "$", "/day"), "1.00"); }); });
// 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("Test Case", function() {
// Test.assertEquals(1 + 1, 2);// assert.strictEqual(1 + 1, 2);- assert.strictEqual(stripEnds("$1.00/day", "$", "/day"), "1.00");
- });
- });
Unit Kata; interface function IsLeap(year: integer): boolean; implementation function IsLeap(year: integer): boolean; begin result := (year mod 400 = 0) or ((year mod 4 = 0) and (year mod 100 <> 0)); end; end.
bool isLeap(int year) {return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);}- Unit Kata;
- interface
- function IsLeap(year: integer): boolean;
- implementation
- function IsLeap(year: integer): boolean;
- begin
- result := (year mod 400 = 0) or ((year mod 4 = 0) and (year mod 100 <> 0));
- end;
- end.
unit KataTests; {$mode objfpc}{$H+} interface uses TestFramework; type TKataTests = class(TTestCase) private published procedure TestIsLeap; end; procedure RegisterTests; implementation uses Kata; procedure RegisterTests; begin TestFramework.RegisterTest(TKataTests.Suite); end; procedure TKataTests.TestIsLeap; begin CheckEquals(true, IsLeap(8), 'year 8'); CheckEquals(true, IsLeap(1600), 'year 1600'); CheckEquals(false, IsLeap(1700), 'year 1700'); CheckEquals(false, IsLeap(1927), 'year 1927'); end; end.
// TODO: Replace examples and use TDD development by writing your own tests- unit KataTests;
Describe(any_group_name_you_want){It(should_do_something){Assert::That(isLeap(8), Equals(true));Assert::That(isLeap(1600), Equals(true));Assert::That(isLeap(1700), Equals(false));Assert::That(isLeap(1927), Equals(false));}};- {$mode objfpc}{$H+}
- interface
- uses
- TestFramework;
- type
- TKataTests = class(TTestCase)
- private
- published
- procedure TestIsLeap;
- end;
- procedure RegisterTests;
- implementation
- uses
- Kata;
- procedure RegisterTests;
- begin
- TestFramework.RegisterTest(TKataTests.Suite);
- end;
- procedure TKataTests.TestIsLeap;
- begin
- CheckEquals(true, IsLeap(8), 'year 8');
- CheckEquals(true, IsLeap(1600), 'year 1600');
- CheckEquals(false, IsLeap(1700), 'year 1700');
- CheckEquals(false, IsLeap(1927), 'year 1927');
- end;
- end.
Which years are leap years?
To be a leap year, the year number must be divisible by four – except for end-of-century years, which must be divisible by 400. This means that the year 2000 was a leap year, although 1900 was not. 2020, 2024 and 2028 are all leap years.
using System; public class LeapYears { public static bool IsLeapYear(int year) { // End of a century must be divisible by 400 if(year.ToString().EndsWith("00") && year % 400 == 0) return true; // Not the end of a century must be divisible by 4 else if(!year.ToString().EndsWith("00") && year % 4 == 0) return true; else return false; } }
- using System;
- public class LeapYears
- {
// Works but hurtspublic static bool IsLeapYear(int y) => (y % 400 == 0) ? true : (y % 100 == 0 && y % 400 != 0) ? false : (y % 4 == 0 && y % 100 != 0) ? true : false;- public static bool IsLeapYear(int year)
- {
- // End of a century must be divisible by 400
- if(year.ToString().EndsWith("00") && year % 400 == 0)
- return true;
- // Not the end of a century must be divisible by 4
- else if(!year.ToString().EndsWith("00") && year % 4 == 0)
- return true;
- else
- return false;
- }
- }
namespace Solution { using NUnit.Framework; using System; [TestFixture] public class LeapTests { [Test] public void Test1() { Assert.AreEqual(true, LeapYears.IsLeapYear(2000)); } [Test] public void Test2() { Assert.AreEqual(true, LeapYears.IsLeapYear(2004)); } [Test] public void Test3() { Assert.AreEqual(true, LeapYears.IsLeapYear(2008)); } [Test] public void Test4() { Assert.AreEqual(false, LeapYears.IsLeapYear(1913)); } [Test] public void Test5() { Assert.AreEqual(true, LeapYears.IsLeapYear(1848)); } [Test] public void Test6() { Assert.AreEqual(false, LeapYears.IsLeapYear(2397)); } [Test] public void Test7() { Assert.AreEqual(false, LeapYears.IsLeapYear(1900)); } } }
- namespace Solution {
- using NUnit.Framework;
- using System;
- [TestFixture]
- public class LeapTests
- {
- [Test]
- public void Test1()
- {
- Assert.AreEqual(true, LeapYears.IsLeapYear(2000));
- }
- [Test]
- public void Test2()
- {
- Assert.AreEqual(true, LeapYears.IsLeapYear(2004));
- }
- [Test]
- public void Test3()
- {
- Assert.AreEqual(true, LeapYears.IsLeapYear(2008));
- }
- [Test]
- public void Test4()
- {
- Assert.AreEqual(false, LeapYears.IsLeapYear(1913));
- }
- [Test]
- public void Test5()
- {
- Assert.AreEqual(true, LeapYears.IsLeapYear(1848));
- }
- [Test]
- public void Test6()
- {
- Assert.AreEqual(false, LeapYears.IsLeapYear(2397));
- }
- [Test]
- public void Test7()
- {
- Assert.AreEqual(false, LeapYears.IsLeapYear(1900));
- }
- }
- }
Fork from Python BMI calculator made via typescript.
export default class BMI { private _height: number; private _weight: number; constructor(weight: number, height: number) { this._height = height; this._weight = weight; } set height(height: number) { if (height <= 0) { const invalidValueError = new Error('Invalid value'); console.error(invalidValueError); } this._height = height; } set width(weight: number) { if (weight <= 0) { const invalidValueError = new Error('Invalid value'); console.error(invalidValueError); } this._weight = weight; } get bmi(): number { return Number((this._weight / Math.pow(this._height, 2)).toFixed(2)); } calculateBMI(): string { return `there is ${this.bmi < 25 ? 'no ' : ''}excess weight`; } }
from dataclasses import dataclass- export default class BMI {
- private _height: number;
- private _weight: number;
- constructor(weight: number, height: number) {
- this._height = height;
- this._weight = weight;
- }
- set height(height: number) {
- if (height <= 0) {
- const invalidValueError = new Error('Invalid value');
- console.error(invalidValueError);
- }
- this._height = height;
- }
- set width(weight: number) {
- if (weight <= 0) {
- const invalidValueError = new Error('Invalid value');
- console.error(invalidValueError);
- }
@dataclassclass BMI:height: floatweight: float@propertydef bmi(self) -> float:return self.weight / (self.height ** 2)def calculate_bmi(self) -> str:return f"there {'is no' if self.bmi < 25 else 'is'} excess weight"- this._weight = weight;
- }
- get bmi(): number {
- return Number((this._weight / Math.pow(this._height, 2)).toFixed(2));
- }
- calculateBMI(): string {
- return `there is ${this.bmi < 25 ? 'no ' : ''}excess weight`;
- }
- }
// See https://www.chaijs.com for how to use Chai. import { assert } from "chai"; import BMI from "./solution"; const BMI_OK = "there is no excess weight"; const BMI_NOT_OK = "there is excess weight"; describe('BMI Calculator', function() { it('BMI is ok testing', function() { assert.strictEqual(new BMI(55, 1.60).calculateBMI(), BMI_OK); assert.strictEqual(new BMI(50, 1.75).calculateBMI(), BMI_OK); assert.strictEqual(new BMI(77, 1.76).calculateBMI(), BMI_OK); }); it('BMI is not ok testing', function() { assert.strictEqual(new BMI(75, 1.70).calculateBMI(), BMI_NOT_OK); assert.strictEqual(new BMI(100, 1.70).calculateBMI(), BMI_NOT_OK); }); });
import unittestfrom solution import BMI- // See https://www.chaijs.com for how to use Chai.
- import { assert } from "chai";
- import BMI from "./solution";
class TestBMICalculator(unittest.TestCase):def setUp(self) -> None:self.samples = [(75, 1.70, "there is excess weight"),(55, 1.60, "there is no excess weight"),(50, 1.75, "there is no excess weight"),(100, 1.70, "there is excess weight"),(77, 1.76, "there is no excess weight"),]- const BMI_OK = "there is no excess weight";
- const BMI_NOT_OK = "there is excess weight";
def test_bmi_results(self):for h, w, e in self.samples:self.assertEqual(BMI(w, h).calculate_bmi(), e)if __name__ == '__main__':unittest.main()- describe('BMI Calculator', function() {
- it('BMI is ok testing', function() {
- assert.strictEqual(new BMI(55, 1.60).calculateBMI(), BMI_OK);
- assert.strictEqual(new BMI(50, 1.75).calculateBMI(), BMI_OK);
- assert.strictEqual(new BMI(77, 1.76).calculateBMI(), BMI_OK);
- });
- it('BMI is not ok testing', function() {
- assert.strictEqual(new BMI(75, 1.70).calculateBMI(), BMI_NOT_OK);
- assert.strictEqual(new BMI(100, 1.70).calculateBMI(), BMI_NOT_OK);
- });
- });