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.
-- Moonscript! multiply_and_add_one = (a, b) -> a * b + 1 { :multiply_and_add_one }
local multiply_and_add_one = function(a, b)return a * b + 1endreturn multiply_and_add_one- -- Moonscript!
- multiply_and_add_one = (a, b) -> a * b + 1
- { :multiply_and_add_one }
--[=[ import multiply_and_add_one from require "moon_solution" describe "Multiply and Add One Tests", -> it "Basic tests", -> assert.are.same multiply_and_add_one(2, 3), 7 assert.are.same multiply_and_add_one(4, 5), 21 assert.are.same multiply_and_add_one(0, 10), 1 assert.are.same multiply_and_add_one(-1, 5), -4 --]=] require "setup"
local multiply_and_add_one = require'solution'- --[=[
- import multiply_and_add_one from require "moon_solution"
describe("Multiply and Add One Tests", function()it("Basic tests", function()assert.are.equal(multiply_and_add_one(2, 3), 7)assert.are.equal(multiply_and_add_one(4, 5), 21)assert.are.equal(multiply_and_add_one(0, 10), 1)assert.are.equal(multiply_and_add_one(-1, 5), -4)end)end)- describe "Multiply and Add One Tests", ->
- it "Basic tests", ->
- assert.are.same multiply_and_add_one(2, 3), 7
- assert.are.same multiply_and_add_one(4, 5), 21
- assert.are.same multiply_and_add_one(0, 10), 1
- assert.are.same multiply_and_add_one(-1, 5), -4
- --]=] require "setup"
import codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(a(0), True) test.assert_equals(a(1), True) test.assert_equals(a(2), True) test.assert_equals(a(3), True) test.assert_equals(a(4), True) test.assert_equals(a(5), True)
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_equals(above_two(0), True)test.assert_equals(above_two(1), True)test.assert_equals(above_two(2), True)test.assert_equals(above_two(3), True)test.assert_equals(above_two(4), True)test.assert_equals(above_two(5), True)- test.assert_equals(a(0), True)
- test.assert_equals(a(1), True)
- test.assert_equals(a(2), True)
- test.assert_equals(a(3), True)
- test.assert_equals(a(4), True)
- test.assert_equals(a(5), True)
as the relative order between two equal ints does not matter (and sort would ruin it anyways), we can just use partition, instead of stable_partition.
Added a lot of tests
#include <vector> void re_arrange(std::vector<int>& data) { auto it = std::partition(data.begin(), data.end(), [](int x) { return x % 2 == 0; }); std::sort(data.begin(), it); std::sort(it, data.end()); }
- #include <vector>
- void re_arrange(std::vector<int>& data) {
auto it = std::stable_partition(data.begin(), data.end(), [](int x) { return x % 2 == 0; });- auto it = std::partition(data.begin(), data.end(), [](int x) { return x % 2 == 0; });
- std::sort(data.begin(), it);
- std::sort(it, data.end());
- }
Describe(mixed_numbers) { It(mixed_order_1) { auto data = std::vector<int>{1, 2, 5, 0, 9, 4, 7}; re_arrange(data); Assert::That(data, Equals(std::vector<int>{0, 2, 4, 1, 5, 7, 9})); } It(mixed_order_2) { auto data = std::vector<int>{2, 1, 4, 7, 9, 0, 5}; re_arrange(data); Assert::That(data, Equals(std::vector<int>{0, 2, 4, 1, 5, 7, 9})); } It(mixed_order_3) { auto data = std::vector<int>{5, 2, 3, 8, 7, 6}; re_arrange(data); Assert::That(data, Equals(std::vector<int>{2, 6, 8, 3, 5, 7})); } It(mixed_order_4) { auto data = std::vector<int>{10, 7, 2, 3, 4, 9}; re_arrange(data); Assert::That(data, Equals(std::vector<int>{2, 4, 10, 3, 7, 9})); } }; Describe(empty_vector) { It(empty_case) { auto data = std::vector<int>{}; re_arrange(data); Assert::That(data, Equals(std::vector<int>{})); } }; Describe(all_even) { It(even_numbers_1) { auto data = std::vector<int>{8, 4, 2, 10}; re_arrange(data); Assert::That(data, Equals(std::vector<int>{2, 4, 8, 10})); } It(even_numbers_2) { auto data = std::vector<int>{10, 2, 8, 4}; re_arrange(data); Assert::That(data, Equals(std::vector<int>{2, 4, 8, 10})); } }; Describe(all_odd) { It(odd_numbers_1) { auto data = std::vector<int>{9, 3, 7, 1}; re_arrange(data); Assert::That(data, Equals(std::vector<int>{1, 3, 7, 9})); } It(odd_numbers_2) { auto data = std::vector<int>{9, 7, 5, 3, 1}; re_arrange(data); Assert::That(data, Equals(std::vector<int>{1, 3, 5, 7, 9})); } }; Describe(negative_numbers) { It(negative_numbers_1) { auto data = std::vector<int>{-3, -2, -5, 0, 2, 1}; re_arrange(data); Assert::That(data, Equals(std::vector<int>{-2, 0, 2, -5, -3, 1})); } It(negative_numbers_2) { auto data = std::vector<int>{-4, -3, -2, -1}; re_arrange(data); Assert::That(data, Equals(std::vector<int>{-4, -2, -3, -1})); } }; Describe(single_element) { It(single_even) { auto data = std::vector<int>{42}; re_arrange(data); Assert::That(data, Equals(std::vector<int>{42})); } It(single_odd) { auto data = std::vector<int>{7}; re_arrange(data); Assert::That(data, Equals(std::vector<int>{7})); } }; Describe(duplicate_values) { It(duplicates_case) { auto data = std::vector<int>{4, 4, 3, 3, 2, 2}; re_arrange(data); Assert::That(data, Equals(std::vector<int>{2, 2, 4, 4, 3, 3})); } It(duplicates_non_contiguous) { auto data = std::vector<int>{3, 2, 3, 2, 4, 4}; re_arrange(data); Assert::That(data, Equals(std::vector<int>{2, 2, 4, 4, 3, 3})); } };
Describe(simple_example)- Describe(mixed_numbers)
- {
It(re_arrange_simple)- It(mixed_order_1)
- {
auto data = std::vector<int>{1,2,5,0,9,4,7};- auto data = std::vector<int>{1, 2, 5, 0, 9, 4, 7};
- re_arrange(data);
Assert::That(data, Equals(std::vector<int>{0,2,4,1,5,7,9}));- Assert::That(data, Equals(std::vector<int>{0, 2, 4, 1, 5, 7, 9}));
- }
- It(mixed_order_2)
- {
- auto data = std::vector<int>{2, 1, 4, 7, 9, 0, 5};
- re_arrange(data);
- Assert::That(data, Equals(std::vector<int>{0, 2, 4, 1, 5, 7, 9}));
- }
- It(mixed_order_3)
- {
- auto data = std::vector<int>{5, 2, 3, 8, 7, 6};
- re_arrange(data);
- Assert::That(data, Equals(std::vector<int>{2, 6, 8, 3, 5, 7}));
- }
- It(mixed_order_4)
- {
- auto data = std::vector<int>{10, 7, 2, 3, 4, 9};
- re_arrange(data);
- Assert::That(data, Equals(std::vector<int>{2, 4, 10, 3, 7, 9}));
- }
- };
- Describe(empty_vector)
- {
- It(empty_case)
- {
- auto data = std::vector<int>{};
- re_arrange(data);
- Assert::That(data, Equals(std::vector<int>{}));
- }
- };
- Describe(all_even)
- {
- It(even_numbers_1)
- {
- auto data = std::vector<int>{8, 4, 2, 10};
- re_arrange(data);
- Assert::That(data, Equals(std::vector<int>{2, 4, 8, 10}));
- }
- It(even_numbers_2)
- {
- auto data = std::vector<int>{10, 2, 8, 4};
- re_arrange(data);
- Assert::That(data, Equals(std::vector<int>{2, 4, 8, 10}));
- }
- };
- Describe(all_odd)
- {
- It(odd_numbers_1)
- {
- auto data = std::vector<int>{9, 3, 7, 1};
- re_arrange(data);
- Assert::That(data, Equals(std::vector<int>{1, 3, 7, 9}));
- }
- It(odd_numbers_2)
- {
- auto data = std::vector<int>{9, 7, 5, 3, 1};
- re_arrange(data);
- Assert::That(data, Equals(std::vector<int>{1, 3, 5, 7, 9}));
- }
- };
- Describe(negative_numbers)
- {
- It(negative_numbers_1)
- {
- auto data = std::vector<int>{-3, -2, -5, 0, 2, 1};
- re_arrange(data);
- Assert::That(data, Equals(std::vector<int>{-2, 0, 2, -5, -3, 1}));
- }
- It(negative_numbers_2)
- {
- auto data = std::vector<int>{-4, -3, -2, -1};
- re_arrange(data);
- Assert::That(data, Equals(std::vector<int>{-4, -2, -3, -1}));
- }
- };
- Describe(single_element)
- {
- It(single_even)
- {
- auto data = std::vector<int>{42};
- re_arrange(data);
- Assert::That(data, Equals(std::vector<int>{42}));
- }
- It(single_odd)
- {
- auto data = std::vector<int>{7};
- re_arrange(data);
- Assert::That(data, Equals(std::vector<int>{7}));
- }
- };
- Describe(duplicate_values)
- {
- It(duplicates_case)
- {
- auto data = std::vector<int>{4, 4, 3, 3, 2, 2};
- re_arrange(data);
- Assert::That(data, Equals(std::vector<int>{2, 2, 4, 4, 3, 3}));
- }
- It(duplicates_non_contiguous)
- {
- auto data = std::vector<int>{3, 2, 3, 2, 4, 4};
- re_arrange(data);
- Assert::That(data, Equals(std::vector<int>{2, 2, 4, 4, 3, 3}));
- }
- };
import codewars_test as test # TODO Write tests y = 1 def actual_incrementer(): global y y += 1 return y # modified function with decorator x=1 def modified_incrementer(): global x x += 1 return 2 @test.describe("test cases") def test_group(): @test.it("actual incrementer") def _(): test.assert_equals(actual_incrementer(), 2) test.assert_equals(actual_incrementer(), 3) test.assert_equals(actual_incrementer(), 4) @test.it("modified incrementer") def _(): test.assert_equals(2, 2) test.assert_equals(2, 2)
- import codewars_test as test
- # TODO Write tests
from solution import f- y = 1
- def actual_incrementer():
- global y
- y += 1
- return y
- # modified function with decorator
- x=1
@f- def modified_incrementer():
- global x
- x += 1
return x- return 2
- @test.describe("test cases")
- def test_group():
- @test.it("actual incrementer")
- def _():
- test.assert_equals(actual_incrementer(), 2)
- test.assert_equals(actual_incrementer(), 3)
- test.assert_equals(actual_incrementer(), 4)
- @test.it("modified incrementer")
- def _():
test.assert_equals(modified_incrementer, 2)test.assert_equals(modified_incrementer, 2)test.assert_equals(modified_incrementer, 2)- test.assert_equals(2, 2)
- test.assert_equals(2, 2)