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.
That's my first kumite... don't really know what all this is about...
using System;
using System.Linq;
public class Kata
{
public static int DuplicateCount(string str)
{
var orderedLowercase = str.ToLower().OrderBy(c => c);
var countDuplicates = 0;
var countOccurrenciesCurrentCharacter = 1;
char? previousElement = null;
var firstElement = true;
foreach(var currentElement in orderedLowercase)
{
if (firstElement)
{
firstElement = false;
}
else
{
if (currentElement == previousElement.Value)
{
countOccurrenciesCurrentCharacter ++;
if (countOccurrenciesCurrentCharacter == 2)
{
countDuplicates ++;
}
}
else
{
countOccurrenciesCurrentCharacter = 1;
}
}
previousElement = currentElement;
}
return countDuplicates;
}
}
namespace Solution {
using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
[TestFixture]
public class KataTest
{
[Test]
public void KataTests()
{
Assert.AreEqual(0, Kata.DuplicateCount(""));
Assert.AreEqual(0, Kata.DuplicateCount("abcde"));
Assert.AreEqual(2, Kata.DuplicateCount("aabbcde"));
Assert.AreEqual(0, Kata.DuplicateCount("a"));
Assert.AreEqual(1, Kata.DuplicateCount("aa"));
Assert.AreEqual(2, Kata.DuplicateCount("aabBcde"), "should ignore case");
Assert.AreEqual(1, Kata.DuplicateCount("Indivisibility"));
Assert.AreEqual(2, Kata.DuplicateCount("Indivisibilities"), "characters may not be adjacent");
}
}
}
const convert = (num) => {
return parseFloat(num.toFixed(2));
};
describe('it works', () => {
assert.strictEqual(convert(1.0899999), 1.09);
assert.strictEqual(convert(2.348), 2.35);
assert.strictEqual(convert(0.111), .11);
});
There can only be one bulbul!
def sayHello(say):
l = ["bulbul", "8===D"]
return l
# 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(actual, expected, [optional] message)
# test.assert_not_equals(actual, expected, [optional] message)
# You can use Test.describe and Test.it to write BDD style test groupings
say = 3
Test.assert_equals(sayHello(say), ["bulbul", "8===D"])
Could be done better?
package main
import "fmt"
func swap(dataset []int, a, b int) {
var x int = dataset[a]
dataset[a] = dataset[b]
dataset[b] = x
}
func bubble_sort(dataset []int, amout_of_integers int){
for i := 0; i <= amout_of_integers; i++ {
for j := amout_of_integers; j >= i + 1; j-- {
if dataset[j] < dataset[j-1] {
swap(dataset, j, j - 1)
}
}
}
}
func main(){
dataset := []int{5, 2, 4, 6, 1, 3};
fmt.Println(dataset)
bubble_sort(dataset, 5);
fmt.Println(dataset)
}
Provide a positive integer (0 < n
).
Returns an array of all factors of n
.
If there are no factors, returns an empty array.
Based on user boo1ean's solution here: https://www.codewars.com/kata/reviews/55aa0d71c1eba8a65a000132/groups/5787db6eba5c4b1c8c0016ae
function getFactors (n) {
if (n < 1 || ! Number.isInteger(n)) return [];
let divisors = [];
// Only iterates up to n/2, since no divisor will be greater than that
for (let i = 1; i <= n / 2; ++i) {
if (n % i) continue;
else divisors.push(i);
}
// Push the original number n to array
return divisors.concat([n]);
}
describe("Solution", function(){
it("sBasic tests", function(){
Test.assertSimilar(getFactors(0), [], "Should return empty array");
Test.assertSimilar(getFactors('string'), [], "Is not a number so should return an empty array");
Test.assertSimilar(getFactors(1), [1], "'1' should be the only divisor of '1'");
Test.assertSimilar(getFactors(13), [1, 13], "'13' is a prime number, so '1, 13' should be its divisors");
Test.assertSimilar(getFactors(50), [1, 2, 5, 10, 25, 50]);
});
});
A little help for claculate the distances between two points in a plane(2D case) and in the space (3D case)
from math import sqrt
def distance2D(pA, pB):
if pA == pB: return 0
xA, yA = tuple(pA); xB, yB = tuple(pB)
return sqrt((xA - xB)**2 + (yA - yB)**2)
def distance3D(pA, pB):
if pA == pB: return 0
xA, yA, zA = tuple(pA); xB, yB, zB = tuple(pB)
return sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)
def distance2D_check(pA, pB):
if pA == pB: return 0
xA, yA = tuple(pA); xB, yB = tuple(pB)
return sqrt((xA - xB)**2 + (yA - yB)**2)
def distance3D_check(pA, pB):
if pA == pB: return 0
xA, yA, zA = tuple(pA); xB, yB, zB = tuple(pB)
return sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)
def assertFuzzyEquals(actual, expected, msg=""):
merr = 1e-10
inrange = abs(actual - expected) <= merr
if (inrange == False):
msg = "At 1e-10: Expected value must be {:.10f} but got {:.10f}"
msg = msg.format(expected, actual)
return Test.expect(inrange, msg)
test.describe("Basic Tests for 2D")
pA = [1, 1]; pB = [2, 2]
assertFuzzyEquals(distance2D(pA, pB), 1.41421356237)
pA = [0, 0]; pB = [5, 6]
assertFuzzyEquals(distance2D(pA, pB), 7.81024967591)
pA = [-5, 4]; pB = [-10, 6]
assertFuzzyEquals(distance2D(pA, pB), 5.38516480713)
pA = [-5.1, 4.0]; pB = [10.2, -6.3]
assertFuzzyEquals(distance2D(pA, pB), 18.4439692041)
test.describe("Basic Tests for 3D")
pA = [1, 1, 1]; pB = [2, 2, 2]
assertFuzzyEquals(distance3D(pA, pB), 1.73205080757)
pA = [0, 0, 0]; pB = [7, 8, 9]
assertFuzzyEquals(distance3D(pA, pB), 13.9283882772)
pA = [-5, 4, 7]; pB = [-10, 6, -18]
assertFuzzyEquals(distance3D(pA, pB), 25.5734237051)
pA = [-5.1, 4.0, 1]; pB = [10.2, -6.3, -1]
assertFuzzyEquals(distance3D(pA, pB), 18.5520888312)
test.describe("Random Tests for 2D")
test.describe("Integer coordinates")
import random
from random import randint
for h in range(20):
pA = [randint(-100, 100), randint(-100, 100)]
pB = [randint(-100, 100), randint(-100, 100)]
result = distance2D_check(pA, pB)
res = distance2D(pA, pB)
assertFuzzyEquals(res, result)
test.it("Distance from " + str(pA) + " to " + str(pB) + " : " + str(result))
test.describe("Random Tests for 2D")
test.describe("Decimal coordinates")
for h in range(20):
pA = [randint(-100, 100) + random.random(), randint(-100, 100) + random.random() ]
pB = [randint(-100, 100) + random.random() , randint(-100, 100) + random.random()]
result = distance2D_check(pA, pB)
res = distance2D(pA, pB)
assertFuzzyEquals(res, result)
test.it("Distance from " + str(pA) + " to " + str(pB) + " : " + str(result))
test.describe("Random Tests for 3D")
test.describe("Integer coordinates")
for h in range(20):
pA = [randint(-100, 100), randint(-100, 100), randint(-100, 100)]
pB = [randint(-100, 100), randint(-100, 100), randint(-100, 100)]
result = distance3D_check(pA, pB)
res = distance3D(pA, pB)
assertFuzzyEquals(res, result)
test.it("Distance from " + str(pA) + " to " + str(pB) + " : " + str(result))
test.describe("Random Tests for 3D")
test.describe("Decimal coordinates")
for h in range(10):
pA = [randint(-100, 100) + random.random(), randint(-100, 100) + random.random(), randint(-100, 100) + random.random() ]
pB = [randint(-100, 100) + random.random() , randint(-100, 100) + random.random(), randint(-100, 100) + random.random()]
result = distance3D_check(pA, pB)
res = distance3D(pA, pB)
assertFuzzyEquals(res, result)
test.it("Distance from " + str(pA) + " to " + str(pB) + " : " + str(result))
A little help for claculate the distances between two points in a plane(2D cases) and in the space (3D cases)
def distance2D(pA, pB)
return 0 if pA == pB
xA = pA[0]; yA = pA[1]; xB= pB[0]; yB = pB[1]
return Math.sqrt((xA - xB)**2 + (yA - yB)**2)
end
def distance3D(pA, pB)
return 0 if pA == pB
xA = pA[0]; yA = pA[1]; zA = pA[2]; xB= pB[0]; yB = pB[1]; zB = pB[2]
return Math.sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)
end
def range (min, max)
rand * (max-min) + min
end
def distance2D_check(pA, pB)
return 0 if pA == pB
xA = pA[0]; yA = pA[1]; xB= pB[0]; yB = pB[1]
return Math.sqrt((xA - xB)**2 + (yA - yB)**2)
end
def distance3D_check(pA, pB)
return 0 if pA == pB
xA = pA[0]; yA = pA[1]; zA = pA[2]; xB= pB[0]; yB = pB[1]; zB = pB[2]
return Math.sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)
end
def assertFuzzyEquals(actual, expected)
merr = 1e-10
inrange = (actual - expected).abs <= merr
if (inrange == false) then
msg = "At 1e-10: Expected value must be %.10f but was %.10f" % [expected, actual]
end
return Test.expect(inrange, msg)
end
describe "Basic Tests for 2D Cases" do
it "Low Values of x, y" do
pA = [1, 1]; pB = [2, 2]
assertFuzzyEquals(distance2D(pA, pB), 1.41421356237)
pA = [0, 0]; pB = [5, 6]
assertFuzzyEquals(distance2D(pA, pB), 7.81024967591)
pA = [-5, 4]; pB = [-10, 6]
assertFuzzyEquals(distance2D(pA, pB), 5.38516480713)
pA = [-5.1, 4.0]; pB = [10.2, -6.3]
assertFuzzyEquals(distance2D(pA, pB), 18.4439692041)
end
end
describe "Basic Tests for 3D Cases" do
it "Low Values of x, y, z" do
pA = [1, 1, 1]; pB = [2, 2, 2]
assertFuzzyEquals(distance3D(pA, pB), 1.73205080757)
pA = [0, 0, 0]; pB = [7, 8, 9]
assertFuzzyEquals(distance3D(pA, pB), 13.9283882772)
pA = [-5, 4, 7]; pB = [-10, 6, -18]
assertFuzzyEquals(distance3D(pA, pB), 25.5734237051)
pA = [-5.1, 4.0, 1]; pB = [10.2, -6.3, -1]
assertFuzzyEquals(distance3D(pA, pB), 18.5520888312)
end
end
describe "Random Tests for 2D Cases" do
it "Integer Values for x, y" do
for h in 1..20
pA = [rand(-100..100), rand(-100..100)]
pB = [rand(-100..100), rand(-100..100)]
result = distance2D_check(pA, pB)
res = distance2D(pA, pB)
it "Testing for: pA: " + pA.to_s + ", pB: " + pB.to_s + " , distance = " + result.to_s do
assertFuzzyEquals(res, result)
end
end
end
end
describe "Random Tests for 2D Cases" do
it "Decimal Values for x, y" do
for h in 1..20
pA = [rand(-100..100) + range(0, 1) , rand(-100..100) + range(0, 1)]
pB = [rand(-100..100) + range(0, 1), rand(-100..100) + range(0, 1)]
result = distance2D_check(pA, pB)
res = distance2D(pA, pB)
it "Testing for: pA: " + pA.to_s + ", pB: " + pB.to_s + " , distance = " + result.to_s do
assertFuzzyEquals(res, result)
end
end
end
end
describe "Random Tests for 3D Cases" do
it "Integer Values for x, y, z" do
for h in 1..20
pA = [rand(-100..100), rand(-100..100), rand(-100..100)]
pB = [rand(-100..100), rand(-100..100), rand(-100..100)]
result = distance3D_check(pA, pB)
res = distance3D(pA, pB)
it "Testing for: pA: " + pA.to_s + ", pB: " + pB.to_s + " , distance = " + result.to_s do
assertFuzzyEquals(res, result)
end
end
end
end
describe "Random Tests for 3D Cases" do
it "Decimal Values for x, y" do
for h in 1..20
pA = [rand(-100..100) + range(0, 1) , rand(-100..100) + range(0, 1), rand(-100..100) + range(0, 1)]
pB = [rand(-100..100) + range(0, 1), rand(-100..100) + range(0, 1), rand(-100..100) + range(0, 1)]
result = distance3D_check(pA, pB)
res = distance3D(pA, pB)
it "Testing for: pA: " + pA.to_s + ", pB: " + pB.to_s + " , distance = " + result.to_s do
assertFuzzyEquals(res, result)
end
end
end
end
A little help to calculate the distances between two points in a plane(2D cases) and in the space (3D cases)
function distance2D(pA, pB) {
if (pA == pB) return 0;
var xA = pA[0], yA = pA[1], xB= pB[0], yB = pB[1];
return Math.sqrt((xA - xB)**2 + (yA - yB)**2)
}
function distance3D(pA, pB) {
if (pA == pB) return 0;
var xA = pA[0], yA = pA[1], zA = pA[2], xB= pB[0], yB = pB[1], zB = pB[2];
return Math.sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2);
}
function distance2DCheck(pA, pB) {
if (pA == pB) return 0;
var xA = pA[0], yA = pA[1], xB= pB[0], yB = pB[1];
return Math.sqrt((xA - xB)**2 + (yA - yB)**2)
}
function distance3DCheck(pA, pB) {
if (pA == pB) return 0;
var xA = pA[0], yA = pA[1], zA = pA[2], xB= pB[0], yB = pB[1], zB = pB[2];
return Math.sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2);
}
function assertFuzzyEquals(actual, expected, msg){
var inrange = Math.abs(actual - expected) <= 1e-10;
Test.expect(inrange, msg || "At 1e-10: Expected value must be " + expected.toExponential(10) +", but got " + actual.toExponential(10));
}
function randint(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
describe("Basic Tests for 2D Cases", function(){
it("Low Values of x, y", function(){
var pA = [1, 1], pB = [2, 2];
assertFuzzyEquals(distance2D(pA, pB), 1.41421356237);
pA = [0, 0], pB = [5, 6];
assertFuzzyEquals(distance2D(pA, pB), 7.81024967591);
pA = [-5, 4], pB = [-10, 6];
assertFuzzyEquals(distance2D(pA, pB), 5.38516480713);
pA = [-5.1, 4.0], pB = [10.2, -6.3];
assertFuzzyEquals(distance2D(pA, pB), 18.4439692041);
});
});
describe("Basic Tests for 3D Cases", function(){
it("Low Values of x, y, z", function(){
var pA = [1, 1, 1], pB = [2, 2, 2];
assertFuzzyEquals(distance3D(pA, pB), 1.73205080757);
pA = [0, 0, 0], pB = [7, 8, 9];
assertFuzzyEquals(distance3D(pA, pB), 13.9283882772);
pA = [-5, 4, 7], pB = [-10, 6, -18];
assertFuzzyEquals(distance3D(pA, pB), 25.5734237051);
pA = [-5.1, 4.0, 1], pB = [10.2, -6.3, -1];
assertFuzzyEquals(distance3D(pA, pB), 18.5520888312);
});
});
describe ("Random Tests for 2D Cases", function(){
it ("Integer Values for x, y", function(){
for (var h = 0; h <= 20; h++) {
var pA = [randint(-100, 100), randint(-100,100)];
var pB = [randint(-100, 100), randint(-100,100)];
var result = distance2DCheck(pA, pB);
var res = distance2D(pA, pB);
it ("Testing for: pA: " + "[" + pA.toString() + "]" + ", pB: " + "[" + pB.toString() + "]"+ " , distance = " + result.toString(), function() {
assertFuzzyEquals(res, result);
});
}
});
});
describe ("Random Tests for 2D Cases", function(){
it ("Decimal Values for x, y", function(){
for (var h = 0; h <= 20; h++) {
var pA = [randint(-100, 100) + Math.random(), randint(-100,100) + Math.random()];
var pB = [randint(-100, 100) + Math.random(), randint(-100,100) + Math.random()];
var result = distance2DCheck(pA, pB);
var res = distance2D(pA, pB);
it ("Testing for: pA: " + "[" + pA.toString() + "]" + ", pB: " + "[" + pB.toString() + "]"+ " , distance = " + result.toString(), function() {
assertFuzzyEquals(res, result);
});
}
});
});
describe ("Random Tests for 3D Cases", function(){
it ("Integer Values for x, y, z", function(){
for (var h = 0; h <= 20; h++) {
var pA = [randint(-100, 100), randint(-100,100), randint(-100,100)];
var pB = [randint(-100, 100), randint(-100,100), randint(-100,100)];
var result = distance3DCheck(pA, pB);
var res = distance3D(pA, pB);
it ("Testing for: pA: " + "[" + pA.toString() + "]" + ", pB: " + "[" + pB.toString() + "]"+ " , distance = " + result.toString(), function() {
assertFuzzyEquals(res, result);
});
}
});
});
describe ("Random Tests for 3D Cases", function(){
it ("Decimal Values for x, y, z", function(){
for (var h = 0; h <= 20; h++) {
var pA = [randint(-100, 100) + Math.random(), randint(-100,100) + Math.random(), randint(-100,100) + Math.random()];
var pB = [randint(-100, 100) + Math.random() , randint(-100,100) + Math.random() , randint(-100,100) + Math.random()];
var result = distance3DCheck(pA, pB);
var res = distance3D(pA, pB);
it ("Testing for: pA: " + "[" + pA.toString() + "]" + ", pB: " + "[" + pB.toString() + "]"+ " , distance = " + result.toString(), function() {
assertFuzzyEquals(res, result);
});
}
});
});
String.split Demo:
'123456'.split('');
// [ '1', '2', '3', '4', '5', '6' ]
How about:
'123456'.spliter(2);
// [ '12', '34', '56' ]
?
console.log(
'123456'.split('')
);
// 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", "actual", "This is just an example of how you can write your own TDD tests");
});
});
Let's try to grab the last character from a string.
def last_char(str):
return str[-1]
# 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(actual, expected, [optional] message)
# test.assert_not_equals(actual, expected, [optional] message)
# You can use Test.describe and Test.it to write BDD style test groupings
test.describe("Basic Test: ")
test.assert_equals(last_char('python'), 'n', 'results not equal to n')
test.describe("Random Test: ")
test.assert_equals(last_char('nhptyo'), 'o', 'results not equal to o')