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.
I decided to test the java framework.
My opinions:
-I just started learning python, and in comparison, it takes a lot more to set up the tests in java, mostly beacause you have to set up the class and methods. Not much can be done about that anyway though.
-It takes a while to start up, and I even got some timeouts on something this simple. I assume the JVM that takes this much time to start up.
-I do miss eclipse's hability to automatiaclly indent and add the missing "}" when you press enter while the cursor is right after a "{". That would speed up setting up stuff.
-After so much programming in python and not much java, I found myself consistently forgetting to add ";" :P
Note:
I copied most stuff from https://github.com/Codewars/kata-test-framework-java , under CodewarsJava/src.
I found the int's in the beggining of the tester class to be completly useless in a test this simple though.
Also, just wanted to point out that in that kata in the git repository the assertEquals, in case of fail will print the error message, and after that the failed method will be called, which prints it again, causing it to print the exact same thing twice.
Notes to self and others that want to try making a java kumite:
To start a kumite, must set up:
-Class with the name of the test
-A class with the same name plus "Test"
-Create a member instante of the first class within the test.
-Create public void setUp() and tearDown() with @Before and @After anotations.
-Make the method that will test the kata or kumite, with a @Test anotation
-Create an instance of TestWatcher, with @Rule anotation, overriding both protected final void succeeded(Description description) and failed(Throwable e, Description description)
Hope this is useful to others.
Thanks for reading :)
PS: Sorry if my english is not the best, I'm not a native speaker.
public class Java {
public int multiply(int x, int y) {
return x * y;
}
}
import org.junit.*;
import org.junit.rules.*;
import org.junit.runner.Description;
public class JavaTest{
Java java = new Java();
@Before
public void setUp() throws Exception {}
@After
public void tearDown() throws Exception {}
@Rule
public TestWatcher testWatcher = new TestWatcher(){
@Override
protected final void succeeded(Description description) {
super.succeeded(description);
}
@Override
protected final void failed(Throwable e, Description description) {
super.failed(e, description);
}
};
@Test
public final void testMultiply() {
Assert.assertEquals("The two values should multiply together", 50, java.multiply(10, 5));
}
}
#include<stdio.h>
int main() {
printf("Hello, C!\n");
}
Checking to see if the clojure runner has the same problems as the Java runner. Apparently not...
(ns codewars.sanity.check)
(defn multiply [ & args ] (apply * args))
(ns codewars.sanity.check-t
(:require [codewars.sanity.check :refer :all]
[clojure.test :refer :all]))
(deftest sanity-check
(testing "1 is 1"
(is (= 1 1)))
(testing "24 = 1 * 2 * 3 * 4"
(is (= 24 (multiply 1 2 3 4)))))
;(deftest sad-path
; (testing "Will format an error properly"
; (is (= false (/ 1 0)))))
This is an example from the Style Guide for Python Code, accompanied by the statement "Make sure to indent the continued line appropriately. The preferred place to break around a binary operator is after the operator, not before it."
class Rectangle(Blob):
def __init__(self, width, height,
color='black', emphasis=None, highlight=0):
if (width == 0 and height == 0 and
color == 'red' and emphasis == 'strong' or
highlight > 100):
raise ValueError("sorry, you lose")
if width == 0 and height == 0 and (color == 'red' or
emphasis is None):
raise ValueError("I don't think so -- values are %s, %s" %
(width, height))
Blob.__init__(self, width, height,
color, emphasis, highlight)
Showcase your personal style for a purpose of your choosing! How would you write this for a Best Practices kata solution? A Clever kata solution? Something else?
I've reformatted it in my personal style for open-source code.
class Rectangle(Blob):
def __init__(self,
width,
height,
color='black',
emphasis=None,
highlight=0):
if (width, height) == (0, 0):
if color == 'red' and emphasis == 'strong' or highlight > 100:
raise ValueError('sorry, you lose')
elif color == 'red' or emphasis is None:
raise ValueError("I don't think so -- values are %s, %s" % (width, height))
Blob.__init__(self,
width=width,
height=height,
color=color,
emphasis=emphasis,
highlight=highlight)
A pretty contrived example. Its an interesting pattern though that doesn't really get used often. I wonder how the pattern could be used for more practical purposes.
class Salutation
def initialize(default)
@default = default
@handlers = {}
end
def to_proc
Proc.new do |name|
if @handlers[name]
@handlers[name].call(name)
else
@default.gsub('{{name}}', name)
end
end
end
def add_handler(*names, &block)
names.each do |name|
@handlers[name] = block
end
end
end
greeter = Salutation.new("Hello {{name}}, how are you doing today?")
greeter.add_handler('Bob', 'Bill') {|name| "Hi again #{name}" }
salutations = ["Mary", "Kate", "Bob", "Bill"].map(&greeter)
Test.assert_equals(salutations.first, "Hello Mary, how are you doing today?")
Test.assert_equals(salutations.last, "Hi again Bill")
A little utility that I came up with recently to deal with needing to loop through multiple items and run an async operation within each. This makes it very easy to chain together a sequence of callbacks.
For example:
var chain = new Chain();
someItemsToProcess.forEach(function(item){
chain.link(function(next){
asyncProcess(item, next);
});
});
chain.run(function(){
// done
});
Some possible room for improvement:
- Promise support
- Events
- ?
function Chain(){
this.links = [];
}
Chain.prototype.link = function link(cb){
this.links.push(cb);
return this;
}
Chain.prototype.run = function run(end){
var self = this;
var next = function(i){
return function(){
if (i < self.links.length){
self.links[i++](next(i), end);
}
}
};
next(0)();
}
var chain = new Chain();
var i = 0;
chain.link(function(next, end){
i++;
next();
});
chain.link(function(next, end){
i++;
end();
});
chain.link(function(next, end){
i++;
console.log('Should not have ran');
});
chain.run(function(){
Test.assertEquals(i, 2);
});
With that you can check if a word is present in a file, and how many time :)
It was my first program in C, if you want to optimise my program you can !
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
void str(char *str)
{
int i = 0;
while (str[i])
{
write(1, &str[i], 1);
i++;
}
}
int find(char *name, char *file)
{
int i = 0;
int j = 0;
int len = 0;
int count = 0;
len = strlen(name);
while (file[i])
{
if (file[i] == name[j])
{
while (file[i] == name[j])
{
j++;
i++;
if (j == len)
count = count + 1;
}
j = 0;
}
i++;
}
return (count);
}
int main(int ac, char **av)
{
int fd;
int readint;
char *name;
char *string;
int acc;
if (ac < 4)
{
str("Usage :\n");
str(" ./name [Your_word] [Buffer] [File] [Other_file] ...\n");
return (0);
}
int BUFF_SIZE = atoi(av[2]);
char buffer[BUFF_SIZE + 1];
name = strdup(av[1]);
acc = ac;
ac = 4;
while (ac <= acc)
{
fd = open(av[ac - 1], O_RDONLY);
readint = read(fd, buffer, BUFF_SIZE);
if (readint == -1)
{
str("Error : read fail\n");
return (-1);
}
str(av[ac - 1]);
str(":\n");
if (find(name, buffer) > 0)
{
str("\033[1;32;40m I found '");
str(name);
printf("' %d time(s)\033[0m\n", find(name, buffer));
}
else
str("\033[1;31;40m Wrong... I didn't find sorry...!\033[0m\n");
ac++;
}
return (0);
}
#!/usr/bin/env python
def main():
print "hello world"
if __name__ == "__main__":
main()