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.
The watcher part isn't needed. All you have to do is write the tests themeselves.
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 {} @Test public final void testMultiply() { Assert.assertEquals("The two values should multiply together", 50, java.multiply(10, 5)); } }
… Expand 1 1 import org.junit.*;
2 2 import org.junit.rules.*;
3 3 import org.junit.runner.Description;
4 4 5 5 public class JavaTest{
6 6 Java java = new Java();
7 7 8 8 @Before
9 9 public void setUp() throws Exception {}
10 10 @After
11 11 public void tearDown() throws Exception {}
12 12 13 − @Rule
14 − public TestWatcher testWatcher = new TestWatcher(){
15 − @Override
16 − protected final void succeeded(Description description) {
17 − super.succeeded(description);
18 − }
19 − 20 − @Override
21 − protected final void failed(Throwable e, Description description) {
22 − super.failed(e, description);
23 − }
24 − };
25 25 26 26 @Test
27 27 public final void testMultiply() {
28 28 Assert.assertEquals("The two values should multiply together", 50, java.multiply(10, 5));
29 29 }
30 30 }
Recent Moves:
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));
}
}
Security permissions were tighted up, so had to add /tmp/
to the mongoid config file path.
require 'mongoid' File.open('/tmp/mongoid.yml', 'w') do |file| file.write <<-CONFIG development: sessions: default: database: mongoid hosts: - localhost:27017 CONFIG end fork { `mongod` } sleep 1.5 # need to find a better way to wait for mongo to startup ENV['RACK_ENV'] = 'development' Mongoid.load!('/tmp/mongoid.yml') class User include Mongoid::Document field :name end
1 1 require 'mongoid'
2 − File.open('mongoid.yml', 'w') do |file|
2 + File.open('/tmp/mongoid.yml', 'w') do |file|
3 3 file.write <<-CONFIG
4 4 development:
5 5 sessions:
6 6 default:
7 7 database: mongoid
8 8 hosts:
9 9 - localhost:27017
10 10 CONFIG
11 11 end
12 12 fork { `mongod` }
13 − sleep 1 # need to find a better way to wait for mongo to startup
13 + sleep 1.5 # need to find a better way to wait for mongo to startup
14 14 15 15 ENV['RACK_ENV'] = 'development'
16 − Mongoid.load!('mongoid.yml')
16 + Mongoid.load!('/tmp/mongoid.yml')
17 17 18 18 class User
19 19 include Mongoid::Document
20 20 field :name
21 21 end
Recent Moves:
import subprocess import re mongod = subprocess.Popen("mongod", stdout=subprocess.PIPE, stderr=subprocess.STDOUT) # @jhoffner: I listen to my child process until it prints "waiting for connections" instead of sleeping... while True: l = mongod.stdout.readline() m = re.match(r".*waiting for connections on port 27017", l) if m: print l break from pymongo import MongoClient with MongoClient() as client: table = client["mongoid"]["User"] table.insert({'_id': 9999, 'first name': 'William', 'last name': 'the Conqueror'})
1 − require 'mongoid'
2 − File.open('mongoid.yml', 'w') do |file|
3 − file.write <<-CONFIG
4 − development:
5 − sessions:
6 − default:
7 − database: mongoid
8 − hosts:
9 − - localhost:27017
10 − CONFIG
11 − end
12 − fork { `mongod` }
13 − sleep 1 # need to find a better way to wait for mongo to startup
1 + import subprocess
2 + import re
3 + mongod = subprocess.Popen("mongod", stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
4 + # @jhoffner: I listen to my child process until it prints "waiting for connections" instead of sleeping...
5 + while True:
6 + l = mongod.stdout.readline()
7 + m = re.match(r".*waiting for connections on port 27017", l)
8 + if m:
9 + print l
10 + break
14 14 15 − ENV['RACK_ENV'] = 'development'
16 − Mongoid.load!('mongoid.yml')
17 − 18 − class User
19 − include Mongoid::Document
20 − field :name
21 − end
12 + from pymongo import MongoClient
13 + with MongoClient() as client:
14 + table = client["mongoid"]["User"]
15 + table.insert({'_id': 9999, 'first name': 'William', 'last name': 'the Conqueror'})
test.describe("Checking to see if Mongo contains little Billy...") from pymongo import MongoClient with MongoClient() as client: table = client["mongoid"]["User"] test.assert_equals(table.find_one()['first name'], 'William')
1 − describe User do
2 − it 'should save' do
3 − Test.expect(User.new.save)
4 − Test.assert_equals(User.count, 1)
5 − end
6 − end
1 + test.describe("Checking to see if Mongo contains little Billy...")
2 + 3 + from pymongo import MongoClient
4 + with MongoClient() as client:
5 + table = client["mongoid"]["User"]
6 + test.assert_equals(table.find_one()['first name'], 'William')
class Fridge def initialize @items = {} end def add(item, amount = 1) @items[item] ||= 0 @items[item] += amount end def serve(item, amount = 1) _amount = [amount, inventory(item)].min add(item, _amount * -1) _amount.times do puts "One #{item} coming right up!" end (amount - _amount).times do puts "We're all out of #{item}" end end def inventory(item = nil) if item @items[item] else @items.values.reduce(0) {|s, v| s + v} end end end ## examples: fridge = Fridge.new fridge.add :beer, 6 fridge.add :pudding, 8 fridge.add :salsa fridge.add :soda fridge.add :eggs fridge.add :steak puts "There are #{fridge.inventory} items in the fridge" puts "#{fridge.inventory(:beer)} of those are beers" fridge.serve(:beer, 7) fridge.serve(:steak) puts "There are #{fridge.inventory} items in the fridge" puts "#{fridge.inventory(:beer)} of those are beers"
1 − Proc = fun(Y, Items) ->
2 − receive
3 − {Sender, Item} when is_pid(Sender) ->
4 − case dict:find(Item, Items) of
5 − {ok, Value} ->
6 − NewCount = Value - 1,
7 − io:format("One ~p coming right up!~n", [Item]),
8 − Sender ! Item,
9 − Y(Y, dict:store(Item, NewCount, Items));
10 − _ ->
11 − io:format("We're all out of ~p~n", [Item]),
12 − Y(Y, Items)
13 − end;
14 − 15 − {count, Item} ->
16 − case dict:find(Item, Items) of
17 − {ok, Value} -> io:format("~p: ~p~n", [Item, Value]);
18 − _ -> io:format("We're all out of ~p~n", [Item])
19 − end,
20 − Y(Y, Items);
21 − 22 − {Item, Count} when is_atom(Item) andalso is_integer(Count) ->
23 − io:format("~p added.~n", [Item]),
24 − NewCount = case dict:find(Item, Items) of
25 − {ok, Value} -> Value + Count;
26 − _ -> Count
27 − end,
28 − Y(Y, dict:store(Item, NewCount, Items));
29 − 30 − count ->
31 − io:format("~p~n", [dict:to_list(Items)]),
32 − Y(Y, Items);
33 − 34 − Item when is_atom(Item) ->
35 − io:format("~p added.~n", [Item]),
36 − NewCount = case dict:find(Item, Items) of
37 − {ok, Value} -> Value + 1;
38 − _ -> 0
39 − end,
40 − Y(Y, dict:store(Item, NewCount, Items));
41 − 42 − _ -> io:format("Killing Fridge...")
1 + class Fridge
2 + def initialize
3 + @items = {}
43 43 end
44 − end,
5 + 6 + def add(item, amount = 1)
7 + @items[item] ||= 0
8 + @items[item] += amount
9 + end
10 + 11 + def serve(item, amount = 1)
12 + _amount = [amount, inventory(item)].min
13 + add(item, _amount * -1)
14 + 15 + _amount.times do
16 + puts "One #{item} coming right up!"
17 + end
18 + 19 + (amount - _amount).times do
20 + puts "We're all out of #{item}"
21 + end
22 + end
23 + 24 + def inventory(item = nil)
25 + if item
26 + @items[item]
27 + else
28 + @items.values.reduce(0) {|s, v| s + v}
29 + end
30 + end
31 + end
32 + 33 + ## examples:
34 + 35 + fridge = Fridge.new
36 + 37 + fridge.add :beer, 6
38 + fridge.add :pudding, 8
39 + fridge.add :salsa
40 + fridge.add :soda
41 + fridge.add :eggs
42 + fridge.add :steak
45 45 46 − Pid = spawn(fun() -> Proc(Proc, dict:new()) end),
44 + puts "There are #{fridge.inventory} items in the fridge"
45 + puts "#{fridge.inventory(:beer)} of those are beers"
47 47 48 − Pid ! {beer, 6},
49 − Pid ! {pudding, 8},
50 − Pid ! salsa,
51 − Pid ! soda,
52 − Pid ! eggs,
53 − Pid ! steak,
54 − 55 − Pid ! count,
56 − Pid ! {count, beer},
57 − Pid ! {self(), beer},
58 − Pid ! {count, beer},
47 + fridge.serve(:beer, 7)
48 + fridge.serve(:steak)
59 59 60 − init:stop().
50 + puts "There are #{fridge.inventory} items in the fridge"
51 + puts "#{fridge.inventory(:beer)} of those are beers"
Recent Moves:
Add, remove and display the items in the fridge. There is some room for improvement here!
Proc = fun(Y, Items) -> receive {Sender, Item} when is_pid(Sender) -> case dict:find(Item, Items) of {ok, Value} -> NewCount = Value - 1, io:format("One ~p coming right up!~n", [Item]), Sender ! Item, Y(Y, dict:store(Item, NewCount, Items)); _ -> io:format("We're all out of ~p~n", [Item]), Y(Y, Items) end; {count, Item} -> case dict:find(Item, Items) of {ok, Value} -> io:format("~p: ~p~n", [Item, Value]); _ -> io:format("We're all out of ~p~n", [Item]) end, Y(Y, Items); {Item, Count} when is_atom(Item) andalso is_integer(Count) -> io:format("~p added.~n", [Item]), NewCount = case dict:find(Item, Items) of {ok, Value} -> Value + Count; _ -> Count end, Y(Y, dict:store(Item, NewCount, Items)); count -> io:format("~p~n", [dict:to_list(Items)]), Y(Y, Items); Item when is_atom(Item) -> io:format("~p added.~n", [Item]), NewCount = case dict:find(Item, Items) of {ok, Value} -> Value + 1; _ -> 0 end, Y(Y, dict:store(Item, NewCount, Items)); _ -> io:format("Killing Fridge...") end end, Pid = spawn(fun() -> Proc(Proc, dict:new()) end), Pid ! {beer, 6}, Pid ! {pudding, 8}, Pid ! salsa, Pid ! soda, Pid ! eggs, Pid ! steak, Pid ! count, Pid ! {count, beer}, Pid ! {self(), beer}, Pid ! {count, beer}, init:stop().
1 1 Proc = fun(Y, Items) ->
2 2 receive
3 − Item when is_atom(Item) ->
3 + {Sender, Item} when is_pid(Sender) ->
4 + case dict:find(Item, Items) of
5 + {ok, Value} ->
6 + NewCount = Value - 1,
7 + io:format("One ~p coming right up!~n", [Item]),
8 + Sender ! Item,
9 + Y(Y, dict:store(Item, NewCount, Items));
10 + _ ->
11 + io:format("We're all out of ~p~n", [Item]),
12 + Y(Y, Items)
13 + end;
14 + 15 + {count, Item} ->
16 + case dict:find(Item, Items) of
17 + {ok, Value} -> io:format("~p: ~p~n", [Item, Value]);
18 + _ -> io:format("We're all out of ~p~n", [Item])
19 + end,
20 + Y(Y, Items);
21 + 22 + {Item, Count} when is_atom(Item) andalso is_integer(Count) ->
4 4 io:format("~p added.~n", [Item]),
5 − Y(Y, [Item | Items]);
24 + NewCount = case dict:find(Item, Items) of
25 + {ok, Value} -> Value + Count;
26 + _ -> Count
27 + end,
28 + Y(Y, dict:store(Item, NewCount, Items));
29 + 30 + count ->
31 + io:format("~p~n", [dict:to_list(Items)]),
32 + Y(Y, Items);
33 + 34 + Item when is_atom(Item) ->
35 + io:format("~p added.~n", [Item]),
36 + NewCount = case dict:find(Item, Items) of
37 + {ok, Value} -> Value + 1;
38 + _ -> 0
39 + end,
40 + Y(Y, dict:store(Item, NewCount, Items));
41 + 6 6 _ -> io:format("Killing Fridge...")
7 7 end
8 8 end,
9 9 10 − Pid = spawn(fun() -> Proc(Proc, []) end),
46 + Pid = spawn(fun() -> Proc(Proc, dict:new()) end),
11 11 12 − Pid ! beer,
48 + Pid ! {beer, 6},
49 + Pid ! {pudding, 8},
13 13 Pid ! salsa,
14 14 Pid ! soda,
15 15 Pid ! eggs,
16 16 Pid ! steak,
17 − Pid ! pudding,
54 + 55 + Pid ! count,
56 + Pid ! {count, beer},
57 + Pid ! {self(), beer},
58 + Pid ! {count, beer},
18 18 19 19 init:stop().
Spawning a more complex function as a process.
Proc = fun(Y, Items) ->
receive
Item when is_atom(Item) ->
io:format("~p added.~n", [Item]),
Y(Y, [Item | Items]);
_ -> io:format("Killing Fridge...")
end
end,
Pid = spawn(fun() -> Proc(Proc, []) end),
Pid ! beer,
Pid ! salsa,
Pid ! soda,
Pid ! eggs,
Pid ! steak,
Pid ! pudding,
init:stop().
Proc = fun (Index) -> timer:sleep(10), io:format("~p~n", [Index]) end, [spawn(fun() -> Proc(X) end) || X <- lists:seq(1, 40)], init:stop().
1 − Proc = fun () ->
2 − io:format("Hello Process.~n")
1 + Proc = fun (Index) ->
2 + timer:sleep(10),
3 + io:format("~p~n", [Index])
3 3 end,
4 4 5 − Pid = spawn(Proc),
6 − 7 − io:format(" Hello's Pid: ~p~n", [Pid]),
6 + [spawn(fun() -> Proc(X) end) || X <- lists:seq(1, 40)],
8 8 9 9 init:stop().
Recent Moves:
Proc = fun () ->
io:format("Hello Process.~n")
end,
Pid = spawn(Proc),
io:format(" Hello's Pid: ~p~n", [Pid]),
init:stop().