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.
Module Kumite Public Function Min(array() As Single) As Single Return array.Min() End Function End Module
Imports NUnit.FrameworkModule Testpublic function MinF(x, n)dim min as integerdim i as integermin = x(0)for i = 1 to nif x(i) < min thenmin = x(i)end ifnextreturn minend function- Module Kumite
- Public Function Min(array() As Single) As Single
- Return array.Min()
- End Function
- End Module
Imports NUnit.Framework <TestFixture> Public Class Kumite_KumiteShould <TestCase(New Single() {1.0f, 2.0f, 3.0f, 4.0f, 5.0f}, 1)> <TestCase(New Single() {2.3f, 1.2f, 4.6f, 8.0f, 3.0f}, 1.2f)> <TestCase(New Single() {2.3f, 1.2f, 4.6f, 2.6f, 10231.0f, -2.2f, 1.2f, 4.6f, 8.0f, 3.0f}, -2.2f)> <TestCase(New Single() {-1.0f, -1.0f}, -1.0f)> Public Sub Min_PassedArray_ReturnsMinimumValue(array() As Single, expected As Single) Dim actual As Single = Kumite.Min(array) Assert.AreEqual(expected, actual) End Sub End Class
- Imports NUnit.Framework
- <TestFixture>
Public Class AdderTest<Test>Public Sub GetsHelloWorld()dim x() as single = {4,8,4,8}dim n = 3Assert.AreEqual(4, Test.MinF(x, n))- Public Class Kumite_KumiteShould
- <TestCase(New Single() {1.0f, 2.0f, 3.0f, 4.0f, 5.0f}, 1)>
- <TestCase(New Single() {2.3f, 1.2f, 4.6f, 8.0f, 3.0f}, 1.2f)>
- <TestCase(New Single() {2.3f, 1.2f, 4.6f, 2.6f, 10231.0f, -2.2f, 1.2f, 4.6f, 8.0f, 3.0f}, -2.2f)>
- <TestCase(New Single() {-1.0f, -1.0f}, -1.0f)>
- Public Sub Min_PassedArray_ReturnsMinimumValue(array() As Single, expected As Single)
- Dim actual As Single = Kumite.Min(array)
- Assert.AreEqual(expected, actual)
- End Sub
- End Class
- Introduced function chaining to reuse existing functions.
- Introduced a base kwarg to override self.num as argument for the function for a more dynamic approach/higher reusability of existing functions.
#!/usr/bin/env python3 """ Debugging: FixDatTrash # 2 """ # constant: PI = 3.1415926535897 class Calculator: """A calculator class.""" def __init__(self, num): """Initialize attributes.""" self.num = num def calculate_power(self, exp, base=None): """ Calculates power of self.num. parameter `exp` is the exponent. parameter `base` is an optional argument to override self.num with. """ return (base or self.num) ** exp def calculate_square_root(self): """Calculates square root of self.num or any other real number.""" return self.calculate_power(0.5) def calculate_cube_root(self): """Calculates cube root of self.num or any other real number.""" return self.calculate_power(1 / 3) def calculate_circumference(self, base=None): """ Calculates circumference of circle. self.num is the diameter of the circle. """ return PI * (base or self.num) def calculate_circle_area(self): """ Calculates area of circle. self.num is the radius of the circle. A=πr2 """ radius_squared = self.calculate_power(2) return self.calculate_circumference(radius_squared)
- #!/usr/bin/env python3
- """
- Debugging: FixDatTrash # 2
- """
import mathfrom dataclasses import dataclassPI = math.pi- # constant:
- PI = 3.1415926535897
@dataclass- class Calculator:
- """A calculator class."""
num: intdef calculate_power(self, exp):- def __init__(self, num):
- """Initialize attributes."""
- self.num = num
- def calculate_power(self, exp, base=None):
- """
- Calculates power of self.num.
- parameter `exp` is the exponent.
- parameter `base` is an optional argument to override self.num with.
- """
return self.num ** exp- return (base or self.num) ** exp
- def calculate_square_root(self):
"""Calculates square root of self.num."""return self.num ** 0.5- """Calculates square root of self.num or any other real number."""
- return self.calculate_power(0.5)
- def calculate_cube_root(self):
"""Calculates cube root of self.num."""return self.num ** (1 / 3)- """Calculates cube root of self.num or any other real number."""
- return self.calculate_power(1 / 3)
def calculate_circumference(self):- def calculate_circumference(self, base=None):
- """
- Calculates circumference of circle.
- self.num is the diameter of the circle.
- """
return PI * self.num- return PI * (base or self.num)
- def calculate_circle_area(self):
- """
- Calculates area of circle.
self.num is the radius of the circle- self.num is the radius of the circle.
- A=πr2
- """
return self.num ** 2 * PI- radius_squared = self.calculate_power(2)
- return self.calculate_circumference(radius_squared)
from solution import Calculator, PI import unittest import math class TestCalculator(unittest.TestCase): def test_calculate_power(self): self.assertEqual(Calculator(2).calculate_power(2), 4) self.assertEqual(Calculator(4).calculate_power(4), 256) def test_calculate_square_root(self): self.assertEqual(Calculator(3).calculate_square_root(), 1.7320508075688772) self.assertEqual(Calculator(16).calculate_square_root(), 4) def test_calculate_cube_root(self): self.assertEqual(Calculator(27).calculate_cube_root(), 3) self.assertEqual(Calculator(125).calculate_cube_root(), 4.999999999999999) def test_calculate_circumference(self): self.assertEqual(Calculator(3).calculate_circumference(), 9.424777960769099) self.assertEqual(Calculator(12).calculate_circumference(), 37.699111843076395) def test_calculate_circle_area(self): self.assertEqual(math.floor(Calculator(3).calculate_circle_area()), 28) self.assertEqual(math.floor(Calculator(54).calculate_circle_area()), 9160) if __name__ == '__main__': unittest.main()
- from solution import Calculator, PI
- import unittest
- import math
- class TestCalculator(unittest.TestCase):
- def test_calculate_power(self):
- self.assertEqual(Calculator(2).calculate_power(2), 4)
- self.assertEqual(Calculator(4).calculate_power(4), 256)
- def test_calculate_square_root(self):
- self.assertEqual(Calculator(3).calculate_square_root(), 1.7320508075688772)
- self.assertEqual(Calculator(16).calculate_square_root(), 4)
- def test_calculate_cube_root(self):
- self.assertEqual(Calculator(27).calculate_cube_root(), 3)
- self.assertEqual(Calculator(125).calculate_cube_root(), 4.999999999999999)
- def test_calculate_circumference(self):
self.assertEqual(Calculator(3).calculate_circumference(), 9.42477796076938)self.assertEqual(Calculator(12).calculate_circumference(), 37.69911184307752)- self.assertEqual(Calculator(3).calculate_circumference(), 9.424777960769099)
- self.assertEqual(Calculator(12).calculate_circumference(), 37.699111843076395)
- def test_calculate_circle_area(self):
- self.assertEqual(math.floor(Calculator(3).calculate_circle_area()), 28)
- self.assertEqual(math.floor(Calculator(54).calculate_circle_area()), 9160)
- if __name__ == '__main__':
- unittest.main()
hey look I made it a code-golf one liner.
using System;using System.Linq;public class Math{public static T Max<T>(params T[] param)where T:IComparable<T>{return param.Any()?param.Aggregate(param[0],(a,b)=>a.CompareTo(b)>0?a:b):default;}}
using System;using System.Linq;public class Math{public static T Max<T>(params T[] param)where T : IComparable<T>{return param.Any() ? param.Aggregate(param[0], (a, b) => a.CompareTo(b) > 0 ? a : b) : default;}}- using System;using System.Linq;public class Math{public static T Max<T>(params T[] param)where T:IComparable<T>{return param.Any()?param.Aggregate(param[0],(a,b)=>a.CompareTo(b)>0?a:b):default;}}
package kata func MergeSort(data []int) []int { if len(data) <= 1 { return data } mid := len(data) / 2 return merge(MergeSort(data[:mid]), MergeSort(data[mid:])) } func merge(left []int, right []int) []int { result := make([]int, 0, len(left) + len(right)) for len(left) > 0 && len(right) > 0 { if left[0] < right[0] { result = append(result, left[0]) left = left[1:] } else { result = append(result, right[0]) right = right[1:] } } result = append(result, left...) result = append(result, right...) return result }
- package kata
- func MergeSort(data []int) []int {
- if len(data) <= 1 {
- return data
- }
- mid := len(data) / 2
- return merge(MergeSort(data[:mid]), MergeSort(data[mid:]))
- }
- func merge(left []int, right []int) []int {
result := make([]int, 0, len(left)+len(right))- result := make([]int, 0, len(left) + len(right))
- for len(left) > 0 && len(right) > 0 {
- if left[0] < right[0] {
- result = append(result, left[0])
- left = left[1:]
- } else {
- result = append(result, right[0])
- right = right[1:]
- }
- }
if len(left) > 0 {result = append(result, left...)}if len(right) > 0 {result = append(result, right...)}- result = append(result, left...)
- result = append(result, right...)
- return result
- }