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.
Task 2: "FizzBuzz"
Write a function fizzBuzz (n) that takes an integer as argument.
The function should output numbers from 1 to n to the console, replacing the numbers:
• multiples of three - on fizz;
• multiples of five - on buzz;
• multiples of three and five at the same time - on fizzbuzz.
function fizzBuzz(num) {
for (let i=1;i <= (num); i++) {
let fb = '';
if (i%3===0) {fb = fb + 'fizz'};
if (i%5===0) {fb = fb + 'buzz'};
if (fb==='') { console.log(i); } else { console.log(fb); };
}
};
fizzBuzz(15); //
// TODO: Add your tests here
// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
// are still available for now.
//
// For new tests, using [Chai](https://chaijs.com/) is recommended.
// You can use it by requiring:
// const assert = require("chai").assert;
// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});
Task: “Expand words in a sentence”
Write a reverseWords (str) function that accepts a string as input. The function should return a new line, putting the words in reverse order. If the line has punctuation marks, you can delete or leave them - at your discretion.
function reverseWords(str) {
return str.split(" ").reverse().join(" ")
}
// TODO: Add your tests here
// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
// are still available for now.
//
// For new tests, using [Chai](https://chaijs.com/) is recommended.
// You can use it by requiring:
// const assert = require("chai").assert;
// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});
Very simple Kata, simply print out every int in the Array.
Like if you solved :D
public class myWorld{
public void printArray(int[] arr){
for(int i = 0; i < arr.length; i++){
System.out.println(arr[i]);
}
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
public class SolutionTest {
public void printArray(int[] arr) {
int pass1 = arr[0];
int pass2 = arr[1];
System.out.println(pass1);
System.out.println(pass2);
// etc.......
//
}
}
char * fanis (char * input, int value) {
int length = strlen (input);
char * output = (char *) malloc (sizeof(char) * (length + 1));
memcpy (output, input, length + 1);
return output;
}
#include <criterion/criterion.h>
Test(the_multiply_function, should_pass_all_the_tests_provided) {
cr_assert_eq(fanis("123", 2), "345");
}
Create a function that returns the sum of the ASCI-value of each char in the given string.
using System;
namespace Solution{
public class ToAsci
{
public static int getAsciSum(string s)
{
int returner = 0;
foreach (var el in s)
returner += (int)el;
return returner;
}
}
}
namespace Solution {
using NUnit.Framework;
using System;
// TODO: Replace examples and use TDD development by writing your own tests
[TestFixture]
public class SolutionTest
{
[Test]
public void MyTest()
{
Assert.AreEqual(448, ToAsci.getAsciSum("test"));
Assert.AreEqual(97, ToAsci.getAsciSum("a"));
Assert.AreEqual(2286, ToAsci.getAsciSum("Some Words and numbers 453"));
Assert.AreEqual(730, ToAsci.getAsciSum("&@Sp15, R@m"));
}
}
}
Suppose you have a software, that will distribute invoices to different billing service providers.
You have a user interface, where you can set the ratio in which the bills are to be distributed to the providers. Back in the software, all bills run in a shuffle function. This function is called with the config from the user interface, that contains the providers and the ratio in which the providers should be chosen.
The Function is generic, so you can send any type you want in the function. This is a very easy way to implement a dynamic load distribution.
If you call the function 1000 times or more, the distribution is very close by your configuration.
using System;
using System.Collections.Generic;
using System.Linq;
namespace Solution
{
public class ObjectShuffler
{
private Random rnd = new Random();
public T Shuffle<T>(Dictionary<T, int> parameterDict)
{
//Remove wrong configuration.
parameterDict = (from i in parameterDict
where i.Value > 0
select i).ToDictionary(x => x.Key, x => x.Value);
//Error Handling
if (parameterDict.Count == 0)
{
throw new Exception("Can't shuffle an empty list.");
}
//Do Work
var sumItemsValue = (from x in parameterDict select x.Value).Sum();
var randNr = this.rnd.Next(1, sumItemsValue + 1);
var stepSum = 0;
foreach (var item in parameterDict)
{
stepSum = stepSum + item.Value;
if (randNr <= stepSum)
{
return item.Key;
}
}
// This can't happen.
throw new Exception("Run to far.");
}
}
}
using NUnit.Framework;
using System;
using System.Collections.Generic;
namespace Solution {
[TestFixture]
public class SolutionTest
{
[Test]
public void Test1()
{
// This test is a usage example.
var results = new Dictionary<String, int>();
results.Add("Provider1", 0);
results.Add("Provider2", 0);
results.Add("Provider3", 0);
var config = new Dictionary<String, int>();
config.Add("Provider1", 10);
config.Add("Provider2", 30);
config.Add("Provider3", 50);
var shuffler = new ObjectShuffler();
for (int i = 0; i < 9000; i++)
{
var key = shuffler.Shuffle(config);
results[key]++;
}
foreach (var r in results)
{
Console.WriteLine($"{r.Key} {r.Value}");
}
}
}
}
I've done a 7kyu kata. The task was to return the same table, but with one column changed.
Say they want to to upper one column, but other columns should remain the same.
In that kata there were only 4 columns.
And all top soulutions was like this:
SELECT column1, column2, column3, UPPER(column4)
But i came with an idea and soulution for the case when there are say 10 columns.
Instead of making a big selecet statement we can do like this:
SELECT *, UPPER(column5) as column5
FROM test_table
results = run_sql.select(:column5)
describe :test_table do
it "column5 should be uppercase" do
expect(results[:column5][:column5]).to eq "TEXT5"
end
end
just trying how this works
public func holabro(){
a=1
return ""
}
import XCTest
// XCTest Spec Example:
// TODO: replace with your own tests (TDD), these are just how-to examples to get you started
class SolutionTest: XCTestCase {
static var allTests = [
("Test Example", testExample),
]
func testExample() {
let actual = 1
XCTAssertEqual(actual, 1)
}
}
XCTMain([
testCase(SolutionTest.allTests)
])
public class ThirdAngle {
public static int otherAngle(int angle1, int angle2) {
return 180-(angle1+angle2);
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD development by writing your own tests
public class SolutionTest {
@Test
public void testSomething() {
// assertEquals("expected", "actual");
}
}
char* Hi (void)
{char* ans;
asprintf(&ans, "Hello World.");
return ans;}
#include <criterion/criterion.h>
const char* Hi ();
Test(the_hello_world_function, should_pass_all_the_tests_provided) {
cr_assert_eq(strcmp(Hi(),"Hello World."), 0);
char *p = Hi();
*p = 'X';
printf("%s\n",p);
}