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.
RubyTester - A custom Ruby TDD Framework
My attempt at creating a custom Ruby testing framework that executes in the command line. Can also be found on GitHub.
NOTE: Original class name was Test
but it clashed with the name of the testing framework used here at Codewars so had to rename it.
class RubyTester
def initialize
@passes = 0
@fails = 0
@errors = 0
end
def describe msg, &block
80.times do
print "#"
sleep 0.025
end
puts "\e[1mRubyTester\e[22m"
sleep 1
puts "\e[1mv1.0.0\e[22m"
sleep 1
puts "\e[1mAuthored by DonaldKellett\e[22m (https://github.com/DonaldKellett)"
sleep 1
@passes = 0
@fails = 0
@errors = 0
print "Tests will execute in 3"
sleep 1
print " 2"
sleep 1
puts " 1"
sleep 1
puts "-" * 80
puts "\e[1mDescribe: #{msg}\e[22m"
start = Time.now
begin
yield
rescue Exception => e
@errors += 1
puts "\e[31mError: #{e}\e[0m"
end
dur = ((Time.now - start) * 1000).round
puts "-" * 80
sleep 1
puts "\e[32m#{@passes} Passed\e[0m"
sleep 1
puts "\e[31m#{@fails} Failed\e[0m"
sleep 1
puts "\e[31m#{@errors} Errors\e[0m"
sleep 1
puts "Process took #{dur}ms to complete"
sleep 1
puts "\e[1mThank you for using RubyTester :D\e[22m"
puts "#" * 80
end
def it msg, &block
puts "\e[1mIt: #{msg}\e[22m"
begin
yield
rescue Exception => e
@errors += 1
puts "\e[31mError: #{e}\e[0m"
end
end
def expect passed, msg = "Value was not what was expected", success = "Test Passed"
if passed
@passes += 1
puts "\e[32m#{success}\e[0m"
else
@fails += 1
puts "\e[31m#{msg}\e[0m"
end
end
def assert_equals actual, expected, msg = "Actual value did not match expected", success = "Test Passed"
self.expect actual == expected, msg + " - Expected: " + expected.to_s + ", but instead got: " + actual.to_s, success + " - Value == " + expected.to_s
end
def assert_not_equals actual, unexpected, msg = "Unexpected value returned", success = "Test Passed"
self.expect actual != unexpected, msg + " - Value was expected to not equal: " + unexpected.to_s, success + " - Value != " + unexpected.to_s
end
def expect_error msg, &block
error_thrown = false
begin
yield
rescue Exception => e
error_thrown = true
puts "Expected error thrown: #{e}"
end
self.expect error_thrown, msg
end
def expect_no_error msg, &block
error_thrown = false
error_msg = "Error"
begin
yield
rescue Exception => e
error_thrown = true
error_msg = e
end
self.expect !error_thrown, "#{msg} - #{e}"
end
def random_number
rand 101
end
def random_token length = 10
token_chars = "abcdefghijklmnopqrstuvwxyz0123456789".split ""
token = ""
length.times do
token += token_chars[(36 * rand).floor]
end
token
end
end
Test.expect true
let beerSongVerse n =
match n with
| 0 -> "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n"
| 1 -> "1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n"
| 2 -> "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n"
| _ -> System.String.Format("{0} bottles of beer on the wall, {0} bottles of beer.\nTake one down and pass it around, {1} bottles of beer on the wall.\n", n, n - 1)
let beerSong n m =
[m .. n] |> List.rev |> List.map(fun x -> beerSongVerse x) |> String.concat("\n")
beerSong 99 0
let rec hello n =
match n with
| 0 -> ()
| _ -> System.Console.WriteLine("hello"); hello (n - 1)
let add a b = a + b
let square x = x * x
let result = add 1 2 |> add 3 |> add 4 |> square
printfn result
const fn = (f) => (...args) => args.reduce((f, arg) => f(arg), f);
// ==================================
const sum = fn(a => b => c => (a + b + c));
console.log(sum(1, 2, 3)); // 6
console.log(sum(1, 2)(3)); // 6
console.log(sum(1)(2)(3)); // 6
const doubleInc = sum(1)(1);
console.log(doubleInc(4)); // 6
Taking a look at testing capabilities...
Printing arguments: work in progress...
#include <cstddef>
template <class C>
bool hasSize(C&& xs, std::size_t n) {
return xs.size() == n;
}
#include <vector>
Describe(igloo_framework) {
It(does_not_print_arguments) {
using vi = std::vector<int>;
Assert::That(hasSize(vi{0, 1, 2}, 3), Is().True());
}
};
Taking a look at Igloo testing framework.
I think there must be some automatical header generation going on here...
template <class T, class U>
auto add(const T& x, const U& y) {
return x + y;
}
#include <string>
using namespace std::string_literals;
Describe(generic_add)
{
It(should_add_numbers)
{
Assert::That(add(2, 2), Equals(4));
}
It(should_add_strings)
{
Assert::That(add("2"s, "2"s), Equals("22"s));
}
};
//
Describe(tests)
{
It(should_do_something_0)
{
Assert::That(1, Equals(2));
}
It(should_do_something_1)
{
Assert::That(123, Equals(456));
}
It(should_do_something_2)
{
Assert::That('a', Equals('b'));
}
};
#include <algorithm>
#include <iterator>
#include <random>
#include <vector>
void run() {
using namespace std;
// this is a source of true random numbers
random_device rd;
// it's used to generate a seed for an engine
default_random_engine eng(rd());
// distribution is applied to a generator to generate random numbers
uniform_int_distribution<int> dist(1, 10);
vector<int> xs;
for (unsigned i = 0; i < 20; i++)
xs.push_back(dist(eng));
for (int x : xs)
cout << x << ' ';
cout << '\n';
}
void run2() {
using namespace std;
default_random_engine eng{random_device()()};
uniform_int_distribution<int> dist(1, 10);
auto rand10 = [&eng, &dist]() { return dist(eng); };
vector<int> xs;
generate_n(back_inserter(xs), 20, rand10);
copy(cbegin(xs), cend(xs), ostream_iterator<int>(cout, " "));
cout << '\n';
}
Describe(any_group_name_you_want)
{
It(should_do_something)
{
run();
run2();
Assert::That(true, Is().True());
}
};
Test of the codewars array test case
var array = ['codewars'];
// Create your own tests here using the Test package (https://github.com/dart-lang/test)
// Here is some boilerplate:
test('The array should not be empty', () {
expect(array.length, greaterThan(0));
expect(array.length, equals(1));
expect(array[0], equals('codewars'));
});