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.
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)
Showing how sync events work in c#, not so pratical as in c# 6 and forward is a good practice writing async code.
using System;
namespace delegates
{
class Program
{
static void Main()
{
// Creates a new instance
Message hi = new Message();
/*
set the event of the class instance to a
lambda expression, beeing an event handler that has the same parameter
and return type of the delegate in the class instance.
equivalent of creating a new void method with the same
parameters and seting it to the event in the class instance
*/
hi.writed += (string hello) =>
{
Console.WriteLine(hello);
};
// executes the method to validate the event and add it to the delegate
hi.write = "write property";
}
}
public class Message
{
//creates the delegate that will handle the method/ lambda expression/ anonnymous method passed through it
public delegate void handler(string hello);
//creates the event with the delegate
public event handler writed;
//method that will check for the event while executing
private string _write;
public string write
{
get
{
return _write;
}
set
{
if(value == "write property")
{
writed?.Invoke("the event was thrown!!!");
}
Console.WriteLine(value);
_write = value;
}
}
//The same as:
// public void write(string text)
// {
// //you have to check if the event is not null becouse you can't execute a delegates method if it does not exist
// //(the event handler was not set yet)
// if(text == "write method" && writed != null)
// {
// writed("the event was thrown!!!");
// }
// Console.WriteLine(text);
}
}
list = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
for i in list :
if i % 15 == 0 :
print('Fizz Buzz')
elif i % 3 == 0 :
print('Fizz')
elif i % 5 ==0 :
print('Buzz')
else :
print(i)
# 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
function main()
{
return 12
}
// 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("Foo", function(){
it ("should be defined", function(){
Test.assertEquals(main(), 1)
});
});