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.
func gradeCalc(_ score: Int) -> String { (0...100~=score) ? String(Array("FFFFFFDCBAA")[score/10]) : "Not a grade" }
- func gradeCalc(_ score: Int) -> String {
(0...100~=score) ? ["F","F","F","F","F","F","D","C","B","A","A"][score / 10] : "Not a grade"- (0...100~=score) ? String(Array("FFFFFFDCBAA")[score/10]) : "Not a grade"
- }
extension String { func insert(_ value: String, interval: Int) -> String { guard interval > 0 && interval < count else { return self } let chars = Array(self) var result = "" var i = 0 while i+interval<count { result.append(String(chars[i..<min(count,i+interval)])+value) i += interval } result.append(String(chars[i..<min(count,i+interval)])) return result } }
- extension String {
- func insert(_ value: String, interval: Int) -> String {
- guard interval > 0 && interval < count else { return self }
- let chars = Array(self)
- var result = ""
- var i = 0
- while i+interval<count {
result.append(String(chars[i..<min(count,i+interval)]))result.append(value)- result.append(String(chars[i..<min(count,i+interval)])+value)
- i += interval
- }
- result.append(String(chars[i..<min(count,i+interval)]))
- return result
- }
- }
const cinema_auditorium = (spisok2d, ryad) => { console.log(spisok2d, ryad); let totalsoldtickets = 0; for(let i = 0; i < spisok2d.length; i++) { for(let j = 0; j < spisok2d[i].length; j++) { if(spisok2d[i][j] === 1 && i === ryad) { totalsoldtickets++; } } } return totalsoldtickets; }
const cinema_auditorium = (spisok2D,ryad)=> {console.log(spisok2D,ryad)return 4- const cinema_auditorium = (spisok2d, ryad) => {
- console.log(spisok2d, ryad);
- let totalsoldtickets = 0;
- for(let i = 0; i < spisok2d.length; i++) {
- for(let j = 0; j < spisok2d[i].length; j++) {
- if(spisok2d[i][j] === 1 && i === ryad) {
- totalsoldtickets++;
- }
- }
- }
- return totalsoldtickets;
- }
Improvements
# Effectively works with everything def new_expect_error(function, exception=Exception, message = "{} did not raise an exception of {}", parameters = []) -> bool: if not(isinstance(function, type(lambda:[])) and isinstance(exception, Exception) and isinstance(message, str) and isinstance(parameters, list)): raise TypeError('parameters input problem') try: if parameters==[]: function(*parameters) else: function() except exception: return True return False
# BaseException >> Exceptiondef f1(): raise Exception()- # Effectively works with everything
# BaseException >> Exception >> ArithmeticError >> ZeroDivisionErrordef f2(): return 1 // 0# BaseException >> Exception >> LookupError >> KeyErrordef f3(): return {}[1]def f0(): pass- def new_expect_error(function, exception=Exception, message = "{} did not raise an exception of {}", parameters = []) -> bool:
- if not(isinstance(function, type(lambda:[])) and isinstance(exception, Exception) and isinstance(message, str) and isinstance(parameters, list)):
- raise TypeError('parameters input problem')
- try:
- if parameters==[]:
- function(*parameters)
- else:
- function()
- except exception:
- return True
- return False
@test.describe('expect_error is backwards compatible') def d1(): for f in (new_expect_error,): test.expect_error('Should raise something', f) excn = ('Exception', 'ArithmeticError', 'ZeroDivisionError', 'LookupError', 'KeyError', 'OSError') exc = (Exception, ArithmeticError, ZeroDivisionError, LookupError, KeyError, OSError) @test.describe('expect_error with exception class') def d2(): @test.it('new_expect_error raises nothing') def i0(): test.expect_error('new_expect_error did not raise any exception', new_expect_error) for i in range(6): test.expect_error('new_expect_error did not raise {}'.format(excn[i]), new_expect_error, exc[i]) @test.it('new_expect_error raises Exception') def i1(): test.expect_error('new_expect_error did not raise Exception', new_expect_error) for i in range(6): test.expect_error('new_expect_error did not raise {}'.format(excn[i]), new_expect_error, exc[i]) @test.it('new_expect_error raises Exception >> ArithmeticError >> ZeroDivisionError') def i2(): test.expect_error('new_expect_error did not raise Exception', new_expect_error) for i in range(6): test.expect_error('new_expect_error did not raise {}'.format(excn[i]), new_expect_error, exc[i]) @test.it('new_expect_error raises Exception >> LookupError >> KeyError') def i3(): test.expect_error('new_expect_error did not raise Exception', new_expect_error) for i in range(6): test.expect_error('new_expect_error did not raise {}'.format(excn[i]), new_expect_error, exc[i]) @test.it('Testing with multiple exception types') def i4(): test.expect_error('new_expect_error did not raise one of ArithmeticError or KeyError', new_expect_error, (ArithmeticError, KeyError)) test.expect_error('new_expect_error did not raise one of LookupError or OSError', new_expect_error, (LookupError, OSError)) test.expect_error('new_expect_error did not raise one of LookupError or OSError', new_expect_error, (LookupError, OSError))
- @test.describe('expect_error is backwards compatible')
- def d1():
for f in (f0, f1, f2, f3):- for f in (new_expect_error,):
- test.expect_error('Should raise something', f)
- excn = ('Exception', 'ArithmeticError', 'ZeroDivisionError', 'LookupError', 'KeyError', 'OSError')
- exc = (Exception, ArithmeticError, ZeroDivisionError, LookupError, KeyError, OSError)
- @test.describe('expect_error with exception class')
- def d2():
@test.it('f0 raises nothing')- @test.it('new_expect_error raises nothing')
- def i0():
test.expect_error('f0 did not raise any exception', f0)- test.expect_error('new_expect_error did not raise any exception', new_expect_error)
- for i in range(6):
test.expect_error('f0 did not raise {}'.format(excn[i]), f0, exc[i])@test.it('f1 raises Exception')- test.expect_error('new_expect_error did not raise {}'.format(excn[i]), new_expect_error, exc[i])
- @test.it('new_expect_error raises Exception')
- def i1():
test.expect_error('f1 did not raise Exception', f1)- test.expect_error('new_expect_error did not raise Exception', new_expect_error)
- for i in range(6):
test.expect_error('f1 did not raise {}'.format(excn[i]), f1, exc[i])@test.it('f2 raises Exception >> ArithmeticError >> ZeroDivisionError')- test.expect_error('new_expect_error did not raise {}'.format(excn[i]), new_expect_error, exc[i])
- @test.it('new_expect_error raises Exception >> ArithmeticError >> ZeroDivisionError')
- def i2():
test.expect_error('f2 did not raise Exception', f2)- test.expect_error('new_expect_error did not raise Exception', new_expect_error)
- for i in range(6):
test.expect_error('f2 did not raise {}'.format(excn[i]), f2, exc[i])@test.it('f3 raises Exception >> LookupError >> KeyError')- test.expect_error('new_expect_error did not raise {}'.format(excn[i]), new_expect_error, exc[i])
- @test.it('new_expect_error raises Exception >> LookupError >> KeyError')
- def i3():
test.expect_error('f3 did not raise Exception', f3)- test.expect_error('new_expect_error did not raise Exception', new_expect_error)
- for i in range(6):
test.expect_error('f3 did not raise {}'.format(excn[i]), f3, exc[i])- test.expect_error('new_expect_error did not raise {}'.format(excn[i]), new_expect_error, exc[i])
- @test.it('Testing with multiple exception types')
- def i4():
test.expect_error('f2 did not raise one of ArithmeticError or KeyError',f2, (ArithmeticError, KeyError))test.expect_error('f3 did not raise one of LookupError or OSError',f3, (LookupError, OSError))test.expect_error('f0 did not raise one of LookupError or OSError',f0, (LookupError, OSError))- test.expect_error('new_expect_error did not raise one of ArithmeticError or KeyError',
- new_expect_error, (ArithmeticError, KeyError))
- test.expect_error('new_expect_error did not raise one of LookupError or OSError',
- new_expect_error, (LookupError, OSError))
- test.expect_error('new_expect_error did not raise one of LookupError or OSError',
- new_expect_error, (LookupError, OSError))