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.
A mistake they don't want to fix...
function describePhp() {
return 2 * 2 == 4 ? 'php is good' : 2 * 2 == 5 ? 'php is weird' : 'php has features';
}
class TestPhpQualities extends TestCase {
public function testPhpIsNice() {
$this->assertEquals('php is good', describePhp());
}
}
Don't know how this "kumite" stuff works yet, so i may be doing sth wrong.
This is about finding better/more efficient ways to permutate a list starting with my sorry attempt. The result requires types of the typeclass Ord, to get a common result for the test cases. Havent thought about a way to solve that differently yet.
module Permutation where
import Data.List (sort)
permu :: [a] ->[[a]]
permu [] = [[]]
permu [x] = [[x]]
permu x = fuzz (length x) 0 x
where fuzz l n (x:xs) |n == l = []
|otherwise = map ((:) x) (permu xs) ++ fuzz l (n+1) (xs ++ [x])
permutation :: Ord a => [a] -> [[a]]
permutation x = permu x
module PermuSpec where
import Test.Hspec
import Data.List (sort)
import Permutation
-- `spec` of type `Spec` must exist
spec :: Spec
spec = do
describe "Permutation" $ do
it "Basic Tests" $ do
shouldBe (sort $ permutation [1,2,3]) [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
shouldBe (sort $ permutation [1..4]) [[1,2,3,4],[1,2,4,3],[1,3,2,4],[1,3,4,2],[1,4,2,3],[1,4,3,2],[2,1,3,4],[2,1,4,3],[2,3,1,4],[2,3,4,1],[2,4,1,3],[2,4,3,1],[3,1,2,4],[3,1,4,2],[3,2,1,4],[3,2,4,1],[3,4,1,2],[3,4,2,1],[4,1,2,3],[4,1,3,2],[4,2,1,3],[4,2,3,1],[4,3,1,2],[4,3,2,1]]
shouldBe (sort $ permutation "wup") ["puw","pwu","upw","uwp","wpu","wup"]
Lets go back to grade school!
Solve for the hypotenuse of a triangle.
Round a float to 4 decimal places.
def hypotenuse(a,b):
import math
h = round(math.sqrt(a**2 + b**2),4)
#print(h)
return h
test.expect(hypotenuse(7,4) == 8.0623)
test.expect(hypotenuse(3,4) == 5)
test.expect(hypotenuse(56,87) == 103.465)
test.expect(hypotenuse(15,19) == 24.2074)
test.expect(hypotenuse(10,10) == 14.1421)
In this Kata you will need to write a function that returns whether a password is strong or not.
Your code should return a Boolean of true if the provided password meets the following conditions
- password must be no less than 8 characters long
- password must have at least 1 capital letter
- password must have at least 1 number
- password must have at least 1 special character
for this Kata special characters are considered ( ! " # $ % & ' ( ) * + ' - . / ; : < > = or ?)
if the password doesn't meet these requirements return false.
function testPassword(password){
var cap = false;
var spec = false;
var number = false;
var temp;
for(i=0;i<password.length;i++){
temp = password[i].charCodeAt();
if(temp > 32 && temp < 48){
spec = true;
} else if(temp > 57 && temp < 64){
spec = true;
}
}
//check each digit and see if any are capital letters
for(i=0;i<password.length;i++){
if(password.charCodeAt(i) > 64 && password.charCodeAt(i) < 91){
cap = true;
}
}
//see if the password is over 8 digits long
if(password.length > 7){
number = true;
}
//provide final answer
if(cap && number && spec){
return true;
} else {
return false;
}
}
Test.assertEquals(testPassword("password"), false);
Test.assertEquals(testPassword("Pas$word1"), true);
Test.assertEquals(testPassword("WodT$m1"), false);
yawn I need a cup of coffee...
class GroundCoffee { }
class Coffee { }
class Cupboard {
constructor() {
this.contents = {
"GroundCoffee": new GroundCoffee(),
};
}
}
class CoffeeMaker {
makeCoffee(groundCoffee) {
if(!(groundCoffee instanceof GroundCoffee)) {
throw new Error("Only GroundCoffee can be used to make Coffee");
}
return new Coffee();
}
}
// -----
const cupboard = new Cupboard();
const coffeeMaker = new CoffeeMaker();
function makeCoffee() {
let groundCoffee = cupboard.contents["GroundCoffee"];
return coffeeMaker.makeCoffee(groundCoffee);
}
var expect = require("chai").expect;
describe("makeCoffee", function(){
it("makes coffee", function(){
expect(makeCoffee()).to.be.an.instanceof(Coffee);
});
});
describe("CoffeeMaker", function() {
beforeEach(function() {
this.coffeeMaker = new CoffeeMaker();
});
describe("#makeCoffee", function() {
context("when passed GroundCoffee", function() {
beforeEach(function () {
this.groundCoffee = new GroundCoffee();
});
it("makes coffee", function(){
expect(this.coffeeMaker.makeCoffee(this.groundCoffee)).to.be.an.instanceof(Coffee);
});
});
context("when not passed GroundCoffee", function() {
beforeEach(function () {
this.groundCoffee = "I'm not coffee!";
});
it("throws an error", function(){
expect(() => this.coffeeMaker.makeCoffee(this.groundCoffee)).to.throw(
Error, "Only GroundCoffee can be used to make Coffee"
);
});
});
});
});
a function that takes a list of connections on the following format:
connections[n] is the list of connections from node n.
connections={
[1] ={ 1, 2, 6, 7 },
[2] ={ 1, 2, 4, 5, 6 },
[3] ={ 3, 4, 5, 6, 7 },
[4] ={ 2, 3, 4, 5, 6 },
[5] ={ 2, 3, 4, 5, 7 },
[6] ={ 1, 2, 3, 4, 6 },
[7] ={ 1, 3, 5, 7 },
[8] ={ 8, 9, 11, 12, 13, 15 },
[9] ={ 8, 9, 10, 12, 13, 15, 16 },
[10]={ 9, 10, 11, 12, 16 },
[11]={ 8, 10, 11, 12 },
[12]={ 8, 9, 10, 11, 12, 13, 15 },
[13]={ 8, 9, 12, 13, 14, 15 },
[14]={ 13, 14, 15, 16 },
[15]={ 8, 9, 12, 13, 14, 15, 16 },
[16]={ 9, 10, 14, 15, 16 },
[17]={ 17, 18, 19, 20, 21 },
[18]={ 17, 18, 19, 20 },
[19]={ 17, 18, 19, 21 },
[20]={ 17, 18, 20, 21 },
[21]={ 17, 19, 20, 21 },
}
The output should be a table of tables with nodes in a given net.
nets={
{1,2,6,7,4,5,3},
{8,9,11,12,13,15,10,16,14},
{17,18,19,20,21}
}
This solution assumes symmetrical connections between nodes.
solution={}
local isIn=function(list,item)
--simple function to find a vale in list
if type(list)~="table" or item==nil then
return false
end
local FoundAtIndex=""
local found=false
for index,value in pairs(list) do
if value==item then
found=true
FoundAtIndex=index
break
end
end
return found,FoundAtIndex
end
solution.findConnectedNets=function(connections)
local nets={}
for i=1,#connections do --traverses nodes to build the nets
local new=true
for k=1,#nets do --if it already is in a net, skip it
if isIn(nets[k],i) then
new=false
break
end
end
if new then
local net={}
local queue={i}
while #queue>0 do
local vertex=queue[1]
table.insert(net,vertex)
table.remove(queue,1)
for _,node in pairs(connections[vertex]) do
if not isIn(net,node) and not isIn(queue,node) then
table.insert(queue,node)
end
end
end
table.insert(nets,net)
end
end
return nets
end
return solution
local solution = require 'solution'
describe("solution", function()
it("test precalculated solutions", function()
assert.are.same(
{{1,2,6,7,4,5,3},{8,9,11,12,13,15,10,16,14},{17,18,19,20,21}},
solution.findConnectedNets(
{{1,2,6,7},{1,2,4,5,6},{3,4,5,6,7},{2,3,4,5,6},{2,3,4,5,7},{1,2,3,4,6},{1,3,5,7},{8,9,11,12,13,15},{8,9,10,12,13,15,16},{9,10,11,12,16},{8,10,11,12},{8,9,10,11,12,13,15},{8,9,12,13,14,15},{13,14,15,16},{8,9,12,13,14,15,16},{9,10,14,15,16},{17,18,19,20,21},{17,18,19,20},{17,18,19,21},{17,18,20,21},{17,19,20,21}}
)
)
end)
end)
Create a function that will return the average grade of a an array of students grades.
def average (grades)
grade.sum/grade.length
end
# 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)
Multiple the two attributes
def multiple(a,b):
return a*b
test.assert_equals(multiple(3,4), 12)
Add two values.
def add(a,b):
return a+b
# 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(add(4,3), 7)# test.assert_not_equals(actual, expected, [optional] message)
# You can use Test.describe and Test.it to write BDD style test groupings
add
def add(a,b):
return 1
test.assert_equals(add(1,2), 1)
#test.assert_equals(add(3,7),10)