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.
where fastify
const fastify = require('fastify');
const chai = require("chai");
const assert = chai.assert;
describe("fastify", function() {
it("should be a function", function() {
assert.equal(typeof fastify, 'function');
});
});
USING: math arrays sequences quotations kernel ;
IN: kata
: foo1 ( -- x ) [ even? ] 1array first ;
: foo2 ( x -- r ) [ even? ] 1array first filter ;
USING: kata tools.testest sequences ;
IN: kata.tests
: run-tests ( -- )
"Example" describe#{
"Foo1" it#{
<{ { 1 2 3 4 5 } foo1 filter -> { 2 4 } }>
}#
"Foo2" it#{
<{ { 1 2 3 4 5 } foo2 -> { 2 4 } }>
}#
}#
;
MAIN: run-tests
------------------>>>>>>>
function func(one, two) {
return 0
}
// І цій задачці ти робиш свою умову
Python array select one of item and repeat it for selected ranges.
It's maded for some interesting things like evolution no anymore
Example:
<span class "cm-comment"># Create simple array with numbers
array =[0, 10, 20, 13]
<span class "cm-comment"># Call our function
spawn_to_range(array, 13, 4)
<span class "cm-comment">#=> Must be returned a [0, 10, 20, 13, 13, 13, 13]
def spawn_to_range(arr, val, ran):
return
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(spawn_to_range([0, 10, 20, 13], 13, 4), [0, 10, 20, 13, 13, 13, 13])
test.assert_equals(spawn_to_range([0, 10, 12, 14], 10, 3), [0, 10, 10, 10, 12, 14])
As can be seen, in the "Should all fail", only the first two assertion fails as expected. The other two assertions display the buggy behaviour.
USE: kernel
FROM: preloaded => custom-err ;
IN: foo
: throws-err ( -- * ) "Err" throw ;
: throws-custom ( -- * ) custom-err ;
: return-err ( -- err ) "Err" ;
: return-custom ( -- err ) \ custom-err new ;
USING: foo tools.testest kernel ;
FROM: preloaded => custom-err ;
IN: foo.tests
: run-tests ( -- )
"Should all pass" describe#{
"Should pass without err" it#{
<{ return-err -> "Err" }>
}#
"Should pass with error" it#{
<{ throws-err -> "Err" throw }>
}#
"Should pass with error object" it#{
<{ throws-custom -> custom-err }>
}#
"Should pass comparing err objects (not thrown)" it#{
<{ return-custom -> \ custom-err new }>
}#
}#
"Should all fail" describe#{
"Should fail with error" it#{
<{ throws-err -> "Err" }>
}#
"Should fail with error object" it#{
<{ throws-custom -> \ custom-err new }>
}#
"Should fail without err" it#{
<{ return-err -> "Err" throw }>
}#
"Should fail without err object" it#{
<{ return-custom -> custom-err }>
}#
}#
;
MAIN: run-tests
Given two Arrays a and b, Return True if arrays contain common item, else false
//Given 2 Arrays, Return True if arrays contain common item, else false.
//e.g a= ['a','b','g','c'] and b =['z','e','c'] returns true
// naive approach, loop through first array, with each item in a, loop through b and compare item to
//each item in b returning true if a match is found or false.
//input : 2 arrays
//output: bool
using System.Collections.Generic;
public class Kata{
public static bool ContainsCommonItem(char[] a, char[] b){ //naive O(a*b)
for(int i=0;i<a.Length;i++)
for(int j=0; j< b.Length; j++)
if(a[i]==b[j])
return true;
return false;
}
public static bool ContainsCommonItemBetter(char[] a,char[]b){
HashSet<char> items = new HashSet<char>();
foreach(char item in a)
items.Add(item);
for (int i =0; i< b.Length; i++)
if (items.Contains(b[i]))
return true;
return false;
}
}
namespace Solution {
using NUnit.Framework;
using System;
// TODO: Replace examples and use TDD by writing your own tests
[TestFixture]
public class SolutionTest
{
[Test]
public void MyTest()
{
Assert.AreEqual(true, Kata.ContainsCommonItemBetter(new char []{ 'a','b','g','c'}, new char[]{'z','e','c'}));
Assert.AreEqual(false, Kata.ContainsCommonItemBetter(new char []{ 'a','b','g','c'}, new char[]{'z','e','d'}));
Assert.AreEqual(false,Kata.ContainsCommonItemBetter(new char[]{},new char[]{'f','h'}));
}
}
}
(Authors note: Introducing: FixDatTrash. This is a new kumite concept that I have begun where over time I create both simple and complex noob scenarios where YOU have to find a way to fix the code. You could also suggest a faster, more easier version of the scenarios code too by just changing it to that in your fork. Get wack, translate, checklist each problem, complicate it, use you creativity! Each scenario has a little fictional character and in the next FixDatTrash as a bonus along with a new scenario you also get a response and some feedback from the character on the previous scenario.)
= = = = = = =
Scenario
= = = = = = =
= = No. 1 = =
- Persons Name: Joe
- Gender: Male
- Programming Language: Python 3.1
- Subject: Help! My Python Fruit Colour Detector is broken!
Description
Joe: Hey code warriors! I'm going on a shopping spree with my friend Fred. However, there is a problem, recnetly Fred has lost his memory! Sadly, he has no memory of most names of fruit, but can remember colours. So, I am building a tool just made for him to use! One problem, I am absolutely TRASH at programming, trust me. I can't even see what's wrong! I would be so glad if some nice code warrior at codewars.com could take some of their time to make this code better. Please, I would do anything to help my friend Fred.def colouroffruit(fruit):
if fruit == "Apple":
return "Red"
elseif fruit == "Orange":
return "Orange"
elif fruit = "Blueberry":
return "Blue"
elif frut == "Pear":
return "Green"
elif fruit == "banana"
return "Yellow"
elif fruit = "Strawberry":
return "Red"
elif fruit == "Lemon":
return "Yellow"
elif fruit == "Lime":
print("Green")
elif fruit == "Raspberry"
return "Red":
elif fruit == "Pineapple":
return "Yellow"
elif fruit == "Melon":
return "Green"
if fruit == "Plum":
return "Purple"
elif fruit == "Strawberry":
return "Red"
elif fruit == "Cabbage"
return "Greem"
#Your Checklist:
#(Optional: put a list of problems you solved here in lines of comments, along with the line number)
#[Example] 1: Fixed if statement syntax (Line 2)
import codewars_test as test
from solution import example
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(colouroffruit("Apple"), "Red")
test.assert_equals(colouroffruit("Orange"), "Orange")
test.assert_equals(colouroffruit("Blueberry"), "Blue")
test.assert_equals(colouroffruit("Pear"), "Green")
test.assert_equals(colouroffruit("Banana"), "Yellow")
test.assert_equals(colouroffruit("Strawberry"), "Red")
test.assert_equals(colouroffruit("Lemon"), "Yellow")
test.assert_equals(colouroffruit("Lime"), "Green")
test.assert_equals(colouroffruit("Raspberry"), "Red")
test.assert_equals(colouroffruit("Pineapple"), "Yellow")
test.assert_equals(colouroffruit("Melon"), "Green")
test.assert_equals(colouroffruit("Plum"), "Purple")
test.assert_equals(colouroffruit("Peach"), "Red")
test.assert_equals(colouroffruit("Avacado"), "Green")
public class Kumite {
public static boolean boolCheck(boolean[] bools) {
return bools[0] ? bools[1] || bools[2] : bools[1] && bools[2];
}
}
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
// TODO: Replace examples and use TDD by writing your own tests
class SolutionTest {
@Test
void test0True() {
boolean[] bools = new boolean[3];
assertEquals(false, Kumite.boolCheck(bools));
}
@Test
void test1True() {
boolean[] bools = new boolean[3];
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
bools[j] = false;
}
bools[i] = true;
assertEquals(false, Kumite.boolCheck(bools));
}
}
@Test
void test2True() {
boolean[] bools = new boolean[3];
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
bools[j] = true;
}
bools[i] = false;
assertEquals(true, Kumite.boolCheck(bools));
}
}
@Test
void test3True() {
boolean[] bools = new boolean[]{true, true, true};
assertEquals(true, Kumite.boolCheck(bools));
}
}
import org.scalatest._
import org.scalatest.Reporter
import org.scalatest.events._
import java.io.{StringWriter, PrintWriter}
// http://doc.scalatest.org/3.0.0/index.html#org.scalatest.Reporter
class CodewarsReporter extends Reporter {
override def apply(event: Event): Unit = event match {
case s: SuiteStarting if s.suiteName != "DiscoverySuite" =>
println(s"\n<DESCRIBE::>${s.suiteName}")
case s: SuiteCompleted if s.suiteName != "DiscoverySuite" =>
println(s"\n<COMPLETEDIN::>${durationString(s.duration)}")
case s: SuiteAborted =>
println(s"\n<ERROR::>Test Suite Aborted<:LF:>${replaceLF(s.message)}")
s.throwable foreach showStackTrace
println(s"\n<COMPLETEDIN::>${durationString(s.duration)}")
case t: TestStarting =>
println(s"\n<IT::>${t.testName}")
case t: TestSucceeded =>
println("\n<PASSED::>Test Passed")
println(s"\n<COMPLETEDIN::>${durationString(t.duration)}")
case t: TestFailed =>
println(s"\n<FAILED::>Test Failed<:LF:>${replaceLF(t.message)}")
t.throwable foreach showStackTrace
println(s"\n<COMPLETEDIN::>${durationString(t.duration)}")
case t: TestCanceled =>
println(s"\n<FAILED::>Test Cancelled<:LF:>${replaceLF(t.message)}")
t.throwable foreach showStackTrace
println(s"\n<COMPLETEDIN::>${durationString(t.duration)}")
case _: TestIgnored =>
println(s"\n<LOG::>Test Ignored")
println(s"\n<COMPLETEDIN::>")
case _: TestPending =>
println(s"\n<LOG::>Test Pending")
println(s"\n<COMPLETEDIN::>")
case _: DiscoveryStarting => ()
case _: DiscoveryCompleted => ()
case _: RunStarting => ()
case _: RunStopped => ()
case t: RunAborted =>
println(s"\n<ERROR::>${replaceLF(t.message)}")
t.throwable foreach showStackTrace
println(s"\n<COMPLETEDIN::>")
case _: RunCompleted => ()
case _: ScopeOpened => ()
case _: ScopeClosed => ()
case _: ScopePending => ()
// contained in recordedEvents?
case _: InfoProvided => ()
case _: MarkupProvided => ()
case _: AlertProvided => ()
case _: NoteProvided => ()
case _ => ()
}
private def showStackTrace(throwable: Throwable): Unit = {
val sw = new StringWriter
throwable.printStackTrace(new PrintWriter(sw))
println(s"<LOG::-Stack Trace>${sw.toString.replaceAll("\n", "<:LF:>")}")
}
private def durationString(d: Option[Long]) = d map { _.toString } getOrElse ""
private def replaceLF(s: String) = s.replaceAll("\n", "<:LF:>")
}
class HobovskysReporter extends Reporter {
override def apply(event: Event): Unit = event match {
case s: SuiteStarting if s.suiteName != "DiscoverySuite" =>
println(s"\n<DESCRIBE::>${s.suiteName}")
case s: SuiteCompleted if s.suiteName != "DiscoverySuite" =>
println(s"\n<COMPLETEDIN::>${durationString(s.duration)}")
case s: SuiteAborted =>
println(s"\n<ERROR::>Test Suite Aborted<:LF:>${replaceLF(s.message)}")
s.throwable foreach showStackTrace
println(s"\n<COMPLETEDIN::>${durationString(s.duration)}")
case t: TestStarting =>
println(s"\n<IT::>${t.testName}")
case t: TestSucceeded =>
println("\n<PASSED::>Test Passed X")
println(s"\n<COMPLETEDIN::>${durationString(t.duration)}")
case t: TestFailed =>
println(s"\n<FAILED::>Test Failed<:LF:>${replaceLF(t.message)}")
t.throwable foreach showStackTrace
println(s"\n<COMPLETEDIN::>${durationString(t.duration)}")
case t: TestCanceled =>
println(s"\n<FAILED::>Test Cancelled<:LF:>${replaceLF(t.message)}")
t.throwable foreach showStackTrace
println(s"\n<COMPLETEDIN::>${durationString(t.duration)}")
case _: TestIgnored =>
println(s"\n<LOG::>Test Ignored")
println(s"\n<COMPLETEDIN::>")
case _: TestPending =>
println(s"\n<LOG::>Test Pending")
println(s"\n<COMPLETEDIN::>")
case _: DiscoveryStarting => ()
case _: DiscoveryCompleted => ()
case _: RunStarting => ()
case _: RunStopped => ()
case t: RunAborted =>
println(s"\n<ERROR::>${replaceLF(t.message)}")
t.throwable foreach showStackTrace
println(s"\n<COMPLETEDIN::>")
case _: RunCompleted => ()
case _: ScopeOpened => ()
case _: ScopeClosed => ()
case _: ScopePending => ()
// contained in recordedEvents?
case _: InfoProvided => ()
case _: MarkupProvided => ()
case _: AlertProvided => ()
case _: NoteProvided => ()
case _ => ()
}
private def showStackTrace(throwable: Throwable): Unit = {
val sw = new StringWriter
throwable.printStackTrace(new PrintWriter(sw))
println(s"<LOG::-Stack Trace>${sw.toString.replaceAll("\n", "<:LF:>")}")
}
private def durationString(d: Option[Long]) = d map { _.toString } getOrElse ""
private def replaceLF(s: String) = s.replaceAll("\n", "<:LF:>")
}
import org.scalatest.funsuite.AnyFunSuite
class TestFunSuite extends AnyFunSuite {
test("An empty Set should have size 0") {
assert(Set.empty.size == 0)
}
test("Invoking head on an empty Set should produce NoSuchElementException") {
assertThrows[NoSuchElementException] {
Set.empty.head
}
}
}
import org.scalatest.flatspec.AnyFlatSpec
class TestFlatSpec extends AnyFlatSpec {
"An empty Set" should "have size 0" in {
assert(Set.empty.size == 0)
}
it should "produce NoSuchElementException when head is invoked" in {
assertThrows[NoSuchElementException] {
Set.empty.head
}
}
}
import org.scalatest.funspec.AnyFunSpec
class TestFunSpec extends AnyFunSpec {
describe("A Set") {
describe("when empty") {
it("should have size 0") {
assert(Set.empty.size == 0)
}
it("should produce NoSuchElementException when head is invoked") {
assertThrows[NoSuchElementException] {
Set.empty.head
}
}
}
}
}
import org.scalatest.wordspec.AnyWordSpec
class TestWordSpec extends AnyWordSpec {
"A Set" when {
"empty" should {
"have size 0" in {
assert(Set.empty.size == 0)
}
"produce NoSuchElementException when head is invoked" in {
assertThrows[NoSuchElementException] {
Set.empty.head
}
}
}
}
}
import org.scalatest.freespec.AnyFreeSpec
class TestFreeSpec extends AnyFreeSpec {
"A Set" - {
"when empty" - {
"should have size 0" in {
assert(Set.empty.size == 0)
}
"should produce NoSuchElementException when head is invoked" in {
assertThrows[NoSuchElementException] {
Set.empty.head
}
}
}
}
}
import org.scalatest._
import org.scalatest.matchers._
import org.scalatest.propspec._
import org.scalatest.prop._
import org.scalatestplus.scalacheck._
import scala.collection.immutable._
class TestPropSpec extends AnyPropSpec with TableDrivenPropertyChecks with should.Matchers {
val examples =
Table(
"set",
BitSet.empty,
HashSet.empty[Int],
TreeSet.empty[Int]
)
property("an empty Set should have size 0") {
forAll(examples) { set =>
set.size should be (0)
}
}
property("invoking head on an empty set should produce NoSuchElementException") {
forAll(examples) { set =>
a [NoSuchElementException] should be thrownBy { set.head }
}
}
}
import org.scalatest.featurespec._
class TVSet {
private var on: Boolean = false
def isOn: Boolean = on
def pressPowerButton() = {
on = !on
}
}
class TestFeatureSpec extends AnyFeatureSpec with GivenWhenThen {
info("As a TV set owner")
info("I want to be able to turn the TV on and off")
info("So I can watch TV when I want")
info("And save energy when I'm not watching TV")
feature("TV power button") {
scenario("User presses power button when TV is off") {
Given("a TV set that is switched off")
val tv = new TVSet
assert(!tv.isOn)
When("the power button is pressed")
tv.pressPowerButton()
Then("the TV should switch on")
assert(tv.isOn)
}
scenario("User presses power button when TV is on") {
Given("a TV set that is switched on")
val tv = new TVSet
tv.pressPowerButton()
assert(tv.isOn)
When("the power button is pressed")
tv.pressPowerButton()
Then("the TV should switch off")
assert(!tv.isOn)
}
}
}
import org.scalatest.refspec.RefSpec
class TestRefSpec extends RefSpec {
object `A Set` {
object `when empty` {
def `should have size 0` = {
assert(Set.empty.size == 0)
}
def `should produce NoSuchElementException when head is invoked` = {
assertThrows[NoSuchElementException] {
Set.empty.head
}
}
}
}
}
class RootSpec extends Sequential(
new TestFunSuite,
new TestFlatSpec,
new TestFunSpec,
new TestWordSpec,
new TestFreeSpec,
new TestPropSpec,
new TestFeatureSpec,
new TestRefSpec
)
class SuiteWithCodewarsReporter extends RootSpec
class SuiteWithHobovskysReporter extends RootSpec
object ScalaTEestsTest extends App {
// (new TestFlatSpec).execute(color = false, configMap = ConfigMap("reporter" -> "CodewarsReporter"));
(new SuiteWithCodewarsReporter).run(None, new Args(new CodewarsReporter));
(new SuiteWithHobovskysReporter).run(None, new Args(new HobovskysReporter));
}
<?php
namespace TennisGame;
interface TennisGame
{
/**
* @param $playerName
* @return void
*/
public function wonPoint($playerName);
/**
* @return string
*/
public function getScore();
}
class TennisGame1 implements TennisGame
{
private $m_score1 = 0;
private $m_score2 = 0;
private $player1Name = '';
private $player2Name = '';
public function __construct($player1Name, $player2Name)
{
$this->player1Name = $player1Name;
$this->player2Name = $player2Name;
}
public function wonPoint($playerName)
{
if ('player1' == $playerName) {
$this->m_score1++;
} else {
$this->m_score2++;
}
}
public function getScore()
{
$score = "";
if ($this->m_score1 == $this->m_score2) {
switch ($this->m_score1) {
case 0:
$score = "Love-All";
break;
case 1:
$score = "Fifteen-All";
break;
case 2:
$score = "Thirty-All";
break;
default:
$score = "Deuce";
break;
}
} elseif ($this->m_score1 >= 4 || $this->m_score2 >= 4) {
$minusResult = $this->m_score1 - $this->m_score2;
if ($minusResult == 1) {
$score = "Advantage player1";
} elseif ($minusResult == -1) {
$score = "Advantage player2";
} elseif ($minusResult >= 2) {
$score = "Win for player1";
} else {
$score = "Win for player2";
}
} else {
for ($i = 1; $i < 3; $i++) {
if ($i == 1) {
$tempScore = $this->m_score1;
} else {
$score .= "-";
$tempScore = $this->m_score2;
}
switch ($tempScore) {
case 0:
$score .= "Love";
break;
case 1:
$score .= "Fifteen";
break;
case 2:
$score .= "Thirty";
break;
case 3:
$score .= "Forty";
break;
}
}
}
return $score;
}
}
<?php
namespace TennisGame;
use PHPUnit\Framework\TestCase;
// PHPUnit Test Examples:
// TODO: Replace examples and use TDD by writing your own tests
class ExampleTest extends TestCase
{
/**
* @var TennisGame
*/
protected $game = null;
/**
* @return mixed[][]
*/
public function data()
{
return [
'0-0' => [0, 0, 'Love-All'],
'1-1' => [1, 1, 'Fifteen-All'],
'2-2' => [2, 2, 'Thirty-All'],
'3-3' => [3, 3, 'Deuce'],
'4-4' => [4, 4, 'Deuce'],
'1-0' => [1, 0, 'Fifteen-Love'],
'0-1' => [0, 1, 'Love-Fifteen'],
'2-0' => [2, 0, 'Thirty-Love'],
'0-2' => [0, 2, 'Love-Thirty'],
'3-0' => [3, 0, 'Forty-Love'],
'0-3' => [0, 3, 'Love-Forty'],
'4-0' => [4, 0, 'Win for player1'],
'0-4' => [0, 4, 'Win for player2'],
'2-1' => [2, 1, 'Thirty-Fifteen'],
'1-2' => [1, 2, 'Fifteen-Thirty'],
'3-1' => [3, 1, 'Forty-Fifteen'],
'1-3' => [1, 3, 'Fifteen-Forty'],
'4-1' => [4, 1, 'Win for player1'],
'1-4' => [1, 4, 'Win for player2'],
'3-2' => [3, 2, 'Forty-Thirty'],
'2-3' => [2, 3, 'Thirty-Forty'],
'4-2' => [4, 2, 'Win for player1'],
'2-4' => [2, 4, 'Win for player2'],
'4-3' => [4, 3, 'Advantage player1'],
'3-4' => [3, 4, 'Advantage player2'],
'5-4' => [5, 4, 'Advantage player1'],
'4-5' => [4, 5, 'Advantage player2'],
'15-14' => [15, 14, 'Advantage player1'],
'14-15' => [14, 15, 'Advantage player2'],
'6-4' => [6, 4, 'Win for player1'],
'4-6' => [4, 6, 'Win for player2'],
'16-14' => [16, 14, 'Win for player1'],
'14-16' => [14, 16, 'Win for player2'],
];
}
protected function seedScores(int $score1, int $score2): void
{
$highestScore = max($score1, $score2);
for ($i = 0; $i < $highestScore; $i++) {
if ($i < $score1) {
$this->game->wonPoint('player1');
}
if ($i < $score2) {
$this->game->wonPoint('player2');
}
}
}
/**
* Prepares the environment before running a test.
*/
protected function setUp(): void
{
parent::setUp();
$this->game = new TennisGame1('player1', 'player2');
}
/**
* @dataProvider data
*/
public function testScores(int $score1, int $score2, string $expectedResult): void
{
$this->seedScores($score1, $score2);
$this->assertSame($expectedResult, $this->game->getScore());
}
}