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.
It is easy, for example: you have to change "Hello World" to "HeLlOwOrLd".
public class HeLlOwOrLddddd {
public static String convert(String input) {
String salida = "";
boolean mayus = true;
for (int i=0;i<input.length();i++){
if (Character.isLetter(input.charAt(i))){
if (mayus){
salida+=Character.toUpperCase(input.charAt(i));
mayus=false;
}else{
salida+=Character.toLowerCase(input.charAt(i));
mayus=true;
}
}
}
return salida;
}
}
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");
assertEquals("HeLlOwOrLd", HeLlOwOrLddddd.convert("Hello World"));
assertEquals("OlAqUeAsE", HeLlOwOrLddddd.convert(" Ola QueAse"));
}
}
Extremely bad distribution with rndSelect'
, needs fixing.
About the warning: https://github.com/idris-lang/Idris-dev/blob/master/docs/reference/erasure.rst
Also: https://github.com/idris-lang/Idris-dev/issues/4193
The effects library has been deprecated in favor of Control.ST, that is on contrib.
module Identity
%access export
%default total
idString : String -> String
idString = id
module IdentitySpec
import Data.Vect
import Effect.Random
import Effects
import System
import Specdris.SpecIO
import Identity
%default total
fixedTests : List (String, String)
fixedTests = [("abc", "abc")]
alphabet : Vect 3 Char
alphabet = ['a', 'b', 'c']
genArg : Eff String [RND]
genArg = pack <$> mapE (\_ => assert_total (rndSelect' alphabet)) [1..10]
genInput : Integer -> Eff (List String) [RND]
genInput seed = srand seed *> mapE (const genArg) [1..5]
testWith : (String, String) -> SpecResult
testWith (input, expected) =
let actual = idString input in
if actual == expected
then Success
else BinaryFailure actual expected $ "Input: \"" ++ input ++ "\""
testAll : List (String, String) -> SpecResult
testAll = foldl (>>=) Success . map (const . testWith)
idStringRefImpl : String -> String
idStringRefImpl = id
export
specSuite : IO ()
specSuite = specIO $ do
describe "idString" $ do
it "should pass fixed tests" $ do
pure $ testAll fixedTests
it "should pass random tests" $ do
testAll . map (\x => (x, idStringRefImpl x)) <$> run (genInput !time)
Given 2 lists, find if one is the scramble of the other. If it is, return True, else return False
module Scramble where
scramble :: String -> String -> Bool
scramble a b = "Scarmble this up"
module ScrambleSpec where
import Test.Hspec
import Scramble
spec :: Spec
spec = do
it "Test Cases" $ do
scramble "scramble" "scarmble" `shouldBe` True
scramble "scroomble" "scroomble" `shouldBe` False
scramble "ScrooMBle" "totally random thing jalkdfjlskfdjlksjdfldjs" `shouldBe` False
scramble "qwertyuiop" "QWERTYUIOP" `shouldBe False
Write the definition of a function max that has three int parameters and returns the largest.
def largest(num1,num2,num3):
max(num1,num2,num3)
# 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
console.log("Amirshoh's Kumite #2") ;
// 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);
});
});
module Foo
export
foo : Int -> Int
foo 0 = 0
module FooSpec
import Specdris.Spec
import Foo
export
specSuite : IO ()
specSuite = spec $
describe "foo 1" $
it "should be 1" $
foo 1 `shouldBe` 1
module Main
foo : Int -> Int
foo 0 = 0
bar : List Int -> Int
bar [] = 0
main : IO ()
main = do
putStrLn "==="
printLn (foo 1)
putStrLn "==="
printLn (bar [1])
putStrLn "==="
Find all the possible combinations for an arbitrary number of arrays.
Example:
const result = createCombinations([
['red', 'blue'],
['small', 'large']
]);
// Result:
[
['red', 'small'],
['red', 'large'],
['blue', 'small'],
['blue', 'large']
]
function createCombinations(input) {
}
const assert = require("chai").assert;
describe("Solution", function() {
it("should cross product three arrays", function() {
const input = [
[1, 2, 3],
['A', 'B', 'C'],
['X', 'Y', 'Z'],
];
const result = createCombinations(input);
assert.deepEqual(result, [
[1, 'A', 'X'],
[1, 'A', 'Y'],
[1, 'A', 'Z'],
[1, 'B', 'X'],
[1, 'B', 'Y'],
[1, 'B', 'Z'],
[1, 'C', 'X'],
[1, 'C', 'Y'],
[1, 'C', 'Z'],
[2, 'A', 'X'],
[2, 'A', 'Y'],
[2, 'A', 'Z'],
[2, 'B', 'X'],
[2, 'B', 'Y'],
[2, 'B', 'Z'],
[2, 'C', 'X'],
[2, 'C', 'Y'],
[2, 'C', 'Z'],
[3, 'A', 'X'],
[3, 'A', 'Y'],
[3, 'A', 'Z'],
[3, 'B', 'X'],
[3, 'B', 'Y'],
[3, 'B', 'Z'],
[3, 'C', 'X'],
[3, 'C', 'Y'],
[3, 'C', 'Z'],
]);
});
});
module IndexOf
import Data.List
%access export
total
elemIndex' : (x : Int) -> (ys : List Int) -> {auto ok : Elem x ys} -> Nat
elemIndex' x (z :: zs) {ok} with (decEq x z)
| Yes _ = 0
| No _ with (ok)
| Here impossible
| There _ = S (elemIndex' x zs)
-- partial
-- elemIndex' : (x : Int) -> (ys : List Int) -> Nat
-- elemIndex' x ys =
-- case elemIndex x ys of
-- Just n => n
module IndexOfSpec
import Data.List
import Specdris.Spec
import IndexOf
%default partial
Input : Type
ValidInput : Type
Output : Type
TestCase : Type
ValidTestCase : Type
Input = (Int, List Int)
ValidInput = (input : Input ** Elem (fst input) (snd input))
Output = Nat
TestCase = (Input, Output)
ValidTestCase = (ValidInput, Output)
fixedTests : List TestCase
fixedTests =
[ ((1, [1, 2, 3]), 0)
, ((5, [4, 5, 6]), 1)
, ((9, [7, 8, 9]), 2)
]
validateInput : Input -> Provider ValidInput
validateInput (x, ys) with (isElem x ys)
| Yes p = Provide ((x, ys) ** p)
| No _ = Error ("invalid test: " ++ show (x, ys))
validateFixedTests : IO (Provider (List ValidTestCase))
validateFixedTests =
pure $ for fixedTests $ \(input, output) => pure (!(validateInput input), output)
%language TypeProviders
%provide (validFixedTests : List ValidTestCase) with validateFixedTests
testWith : ValidTestCase -> SpecResult
testWith (((x, ys) ** ok), expected) =
let actual = elemIndex' x ys in
if actual == expected
then Success
else BinaryFailure actual expected $ "Input: " ++ show (x, ys)
testAll : List ValidTestCase -> SpecResult
testAll = foldl (>>=) Success . map (const . testWith)
export
specSuite : IO ()
specSuite = spec $ do
describe "elemIndex'" $ do
it "should pass fixed tests" $ do
testAll validFixedTests
Write a function caesar() that will return the input message with each character shifted to the right n times in the alphabet. Make sure the encoded message is in all caps since the Romans didn't use lowercase letters. Only punks use lowercase letters.
Example : 'James is the greatest at kumite!' => 'MDPHV LV WKH JUHDWHVW DW NXPLWH!'
Make sure to preserve the spaces and punctuation of the original message, you know, for clarity's sake.
// Description:
// Write a function caesar() that will return the input message with each character
// shifted to the right n times in the alphabet. Make sure the encoded message is in
// all caps since the Romans didn't use lowercase letters. Only punks use lowercase letters.
// Example : 'James is the greatest at kumite!' => 'MDPHV LV WKH JUHDWHVW DW NXPLWH!'
// Make sure to preserve the spaces and punctuation of the original message, you know, for clarity's sake.
const caesar = (shift, msg) => {
};
// 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.
const {expect} = require('chai');
describe('Caesar Function', () => {
it('should return the message with each letter of the alphabet shifted n times', () => {
let shift = 3;
let msg = 'James is the greatest at kumite!';
let exp = 'MDPHV LV WKH JUHDWHVW DW NXPLWH!'
const res = caesar(shift, msg);
expect(res).to.equal(exp);
});
it('should not eliminate spaces or punctuation', () => {
let shift = 13;
let msg = '! 3214 @!#$';
let exp = '! 3214 @!#$';
const res = caesar(shift, msg);
expect(res).to.equal(exp);
});
});