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.
#include <vector> #include <unordered_map> #include <numeric> int unique_sum(const std::vector<int>& n) { std::unordered_map<int,int> frequencies; for (auto i : n) ++frequencies[i]; return std::accumulate(begin(n), end(n), 0, [&](auto sum, auto i){ return frequencies[i] == 1 ? sum + i : sum; }); }
- #include <vector>
#include <map>- #include <unordered_map>
- #include <numeric>
int unique_sum(const std::vector<int>& n) {auto histogram=[&](){std::map<int,int> nums;for (auto i:n) ++nums[i];return nums;};- int unique_sum(const std::vector<int>& n)
- {
- std::unordered_map<int,int> frequencies;
- for (auto i : n)
- ++frequencies[i];
int sum=0;for (auto [k,c]:histogram()) if (c==1) sum+=k;return sum;- return std::accumulate(begin(n), end(n), 0, [&](auto sum, auto i){
- return frequencies[i] == 1 ? sum + i : sum;
- });
- }
#include <stdlib.h> #include <string.h> #include <ctype.h> char *fun(const char *input) { size_t len = strlen(input); char *result = malloc(len + 1); for (size_t i = 0; input[i]; i++) result[i] = toupper(input[i]); return result[len] = '\0', result; }
def fun(s): return s.upper()- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- char *fun(const char *input)
- {
- size_t len = strlen(input);
- char *result = malloc(len + 1);
- for (size_t i = 0; input[i]; i++)
- result[i] = toupper(input[i]);
- return result[len] = '\0', result;
- }
#include <criterion/criterion.h> #include <stdlib.h> char *fun(const char *input); void tester(const char *input, const char *expected) { char *result = fun(input); cr_assert_str_eq(result, expected); free(result); } Test(Example, test_case) { tester("Welcome", "WELCOME"); tester("hello", "HELLO"); tester("yellow", "YELLOW"); tester("blue", "BLUE"); }
import codewars_test as test# TODO Write testsimport solution # or from solution import example- #include <criterion/criterion.h>
- #include <stdlib.h>
# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")def test_group():@test.it("test case")def test_case():test.assert_equals(fun('Welcome'), 'WELCOME')test.assert_equals(fun('hello'), 'HELLO')test.assert_equals(fun('yellow'), 'YELLOW')test.assert_equals(fun('blue'), 'BLUE')- char *fun(const char *input);
- void tester(const char *input, const char *expected)
- {
- char *result = fun(input);
- cr_assert_str_eq(result, expected);
- free(result);
- }
- Test(Example, test_case)
- {
- tester("Welcome", "WELCOME");
- tester("hello", "HELLO");
- tester("yellow", "YELLOW");
- tester("blue", "BLUE");
- }
I created a single parameterized test to avoid redundant tests for the same output function without additional logic.
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; class SolutionTest { @ParameterizedTest @MethodSource("testCases") public void it_should_return_the_expected_value_for_test_case(String inputName, String expectedOutputValue) { assertThat(greet.greet(inputName)) .as("It should return the expected value for %s", inputName) .isEqualTo(expectedOutputValue); } public static Stream<Arguments> testCases() { return Stream.of( Arguments.of("Reemu", "hello my name is Reemu"), Arguments.of("Pepo", "hello my name is Pepo"), Arguments.of("Delacroix", "hello my name is Delacroix"), Arguments.of("Toto", "hello my name is Toto") ); } private final Greet greet = new Greet(); }
import org.junit.jupiter.api.Test;import static org.junit.jupiter.api.Assertions.assertEquals;- import org.junit.jupiter.params.ParameterizedTest;
- import org.junit.jupiter.params.provider.Arguments;
- import org.junit.jupiter.params.provider.MethodSource;
- import java.util.stream.Stream;
- import static org.assertj.core.api.Assertions.assertThat;
// TODO: Replace examples and use TDD by writing your own tests- class SolutionTest {
@Testvoid testSomething() {assertEquals("hello my name is Reemu", new Greet().greet("Reemu"));- @ParameterizedTest
- @MethodSource("testCases")
- public void it_should_return_the_expected_value_for_test_case(String inputName, String expectedOutputValue) {
- assertThat(greet.greet(inputName))
- .as("It should return the expected value for %s", inputName)
- .isEqualTo(expectedOutputValue);
- }
- public static Stream<Arguments> testCases() {
- return Stream.of(
- Arguments.of("Reemu", "hello my name is Reemu"),
- Arguments.of("Pepo", "hello my name is Pepo"),
- Arguments.of("Delacroix", "hello my name is Delacroix"),
- Arguments.of("Toto", "hello my name is Toto")
- );
- }
- private final Greet greet = new Greet();
- }