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.
It looks like it it trying to walk-through the directories of a .venv
virtual enviornment folder.
import os # The subprocess module is never used # import subprocess # Setting constant: DIR = os.path.join(os.getcwd(), 'venv') # Using the walrus operator to ve tp DIR, and printing results of venv directory: print((ve := os.listdir(DIR))) # For files in venv, which will be (Libs, and Scripts) for x in ve: try: # Printing a list of files, and directories within first directory of (venv) print(x, os.listdir(os.path.join(DIR, x))) # FOr subfile in file: for y in x: try: # This does not get executed print(x, os.listdir(os.path.join(DIR, x, y))) # FOr super-sub file in subfile for z in y: try: # This des not get executed with open(os.path.join(DIR, x, y), 'r') as file: print(file.read()) except: # This does not get executed print("...goes on...") except: try: # This does not get executed with open(os.path.join(DIR, x), 'r') as file: print(file.read()) except: # This gets executed print('') except: # This will get executed twice, opening the .gitignore, and pyvenv.cfg file with open(os.path.join(DIR, x), 'r') as file: print(file.read())
- import os
import subprocessprint((ve := os.listdir(".venv")))- # The subprocess module is never used
- # import subprocess
- # Setting constant:
- DIR = os.path.join(os.getcwd(), 'venv')
- # Using the walrus operator to ve tp DIR, and printing results of venv directory:
- print((ve := os.listdir(DIR)))
- # For files in venv, which will be (Libs, and Scripts)
- for x in ve:
- try:
print(x, os.listdir(f".venv/{x}"))for y in x:- # Printing a list of files, and directories within first directory of (venv)
- print(x, os.listdir(os.path.join(DIR, x)))
- # FOr subfile in file:
- for y in x:
- try:
print(y, os.listdir(f".venv/{x}/{y}"))- # This does not get executed
- print(x, os.listdir(os.path.join(DIR, x, y)))
- # FOr super-sub file in subfile
- for z in y:
- try:
with open(f".venv/{x}/{y}/{z}","r") as file: print(file.open())except:- # This des not get executed
- with open(os.path.join(DIR, x, y), 'r') as file:
- print(file.read())
- except:
- # This does not get executed
- print("...goes on...")
except:- except:
- try:
with open(rf".venv/{x}") as f:print(f.read())- # This does not get executed
- with open(os.path.join(DIR, x), 'r') as file:
- print(file.read())
- except:
print()- # This gets executed
- print('')
- except:
with open(rf".venv/{x}") as f:print(f.read())- # This will get executed twice, opening the .gitignore, and pyvenv.cfg file
- with open(os.path.join(DIR, x), 'r') as file:
- print(file.read())
import codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(1 + 1, 2)
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(1 + 1, 2)
feed_the_primates_v1 = lambda a,f: 'No bananas!' if "🍌" not in set(f) else ["🍌" for m in a if m in {"🐒", "🦍"} and "🍌" in f] banana = "🍌" feed_the_primates_v2 = lambda a,f: 'No bananas!' if banana not in set(f) else [banana for m in a if m in {"🐒", "🦍"} and banana in f] # other option being: replacing banana as inline value
def feed_the_primates_v1(animals, food):return 'No bananas!' if "🍌" not in set(food) else ["🍌" for m in animals if m in {"🐒", "🦍"} and "🍌" in food]- feed_the_primates_v1 = lambda a,f: 'No bananas!' if "🍌" not in set(f) else ["🍌" for m in a if m in {"🐒", "🦍"} and "🍌" in f]
- banana = "🍌"
- feed_the_primates_v2 = lambda a,f: 'No bananas!' if banana not in set(f) else [banana for m in a if m in {"🐒", "🦍"} and banana in f]
def feed_the_primates_v2(animals, food):banana = "🍌"return 'No bananas!' if banana not in set(food) else [banana for m in animals if m in {"🐒", "🦍"} and banana in food]- # other option being: replacing banana as inline value
you can do this weird import thing to achive the one-line.
public class ColorAdder { public static string AddColor(string color, string text) { string Reset = "\033[0m"; return color switch{ "Red" => $"\033[31m{text}{Reset}", "Green" => $"\033[32m{text}{Reset}", "Yellow" => $"\033[33m{text}{Reset}", "Blue" => $"\033[34m{text}{Reset}", "Magenta" => $"\033[35m{text}{Reset}", "Cyan" => $"\033[36m{text}{Reset}", "White" => $"\033[37m{text}{Reset}", _ => "" }; } }
- public class ColorAdder
- {
- public static string AddColor(string color, string text)
- {
- string Reset = "\033[0m";
string Red = "\033[31m";string Green = "\033[32m";string Yellow = "\033[33m";string Blue = "\033[34m";string Magenta = "\033[35m";string Cyan = "\033[36m";string White = "\033[37m";switch(color) {case "Red":return string.Concat(string.Concat(Red, text), Reset);break;case "Green":return string.Concat(string.Concat(Green, text), Reset);break;case "Yellow":return string.Concat(string.Concat(Yellow, text), Reset);break;case "Blue":return string.Concat(string.Concat(Blue, text), Reset);break;case "Magenta":return string.Concat(string.Concat(Magenta, text), Reset);break;case "Cyan":return string.Concat(string.Concat(Cyan, text), Reset);break;case "White":return string.Concat(string.Concat(White, text), Reset);break;default:return "Invalid Color";break;}- return color switch{
- "Red" => $"\033[31m{text}{Reset}",
- "Green" => $"\033[32m{text}{Reset}",
- "Yellow" => $"\033[33m{text}{Reset}",
- "Blue" => $"\033[34m{text}{Reset}",
- "Magenta" => $"\033[35m{text}{Reset}",
- "Cyan" => $"\033[36m{text}{Reset}",
- "White" => $"\033[37m{text}{Reset}",
- _ => ""
- };
- }
- }
import static java.time.format.DateTimeFormatter.ofPattern; import java.time.LocalDateTime; public class Account { private Transaction current = new Transaction(0, 0); public void deposit(int amount) { current = new Transaction(current.balance() + amount, Math.abs(amount)); } public void withdraw(int amount) { deposit(-amount); } public String printStatement() { return current.toString(); } private record Transaction(int balance, int amount, LocalDateTime date) { public Transaction(int balance, int amount) { this(balance, amount, LocalDateTime.now()); } @Override public String toString() { return String.format("Date Amount Balance%n%s%n%s %d %d", balance < 0 ? "Failed: Insufficient Funds" : amount <= 0 ? "Failed: Negative Transaction" : "", date.format(ofPattern("dd-MM-yyyy")), amount, balance); } } }
- import static java.time.format.DateTimeFormatter.ofPattern;
- import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;- public class Account {
- private Transaction current = new Transaction(0, 0);
- public void deposit(int amount) {
- current = new Transaction(current.balance() + amount, Math.abs(amount));
- }
LocalDateTime lastTransactionDate = LocalDateTime.of(1900,1,1,1,1);int lastTransactionAmount = 0;int lastTransactionBalance = 0;private String statement = "Date Amount Balance" + "\n";private static final String DATE_FORMATTER= "dd-MM-yyyy";DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMATTER);- public void withdraw(int amount) {
- deposit(-amount);
- }
- public String printStatement() {
- return current.toString();
- }
- private record Transaction(int balance, int amount, LocalDateTime date) {
public String printStatement() {if(this.lastTransactionBalance < 0){return this.statement + "\n Failed: Insufficient Funds";} else if(this.lastTransactionAmount <= 0){return this.statement + "Failed: Negative Transaction";}return this.statement + "\n" + lastTransactionDate.format(formatter) + " " + lastTransactionAmount + " " + lastTransactionBalance;- public Transaction(int balance, int amount) {
- this(balance, amount, LocalDateTime.now());
- }
public void deposit(int amount){this.lastTransactionBalance += amount;this.lastTransactionAmount = amount;this.lastTransactionDate = LocalDateTime.now();;- @Override
- public String toString() {
- return String.format("Date Amount Balance%n%s%n%s %d %d",
- balance < 0 ? "Failed: Insufficient Funds" : amount <= 0 ? "Failed: Negative Transaction" : "",
- date.format(ofPattern("dd-MM-yyyy")), amount, balance);
- }
public void withdraw(int amount){this.lastTransactionBalance -= amount;this.lastTransactionAmount = amount;this.lastTransactionDate = LocalDateTime.now();- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { @Test void printStatement_displays_column_headings() { Account account = new Account(); String statement = account.printStatement(); String[] rows = statement.split("\\n"); String[] columns= rows[0].split("\\s"); String[] expectedColumns = "Date Amount Balance".split(" "); assertArrayEquals(expectedColumns, columns); } @Test void depositAmountIsDisplayedOnStatement(){ Account account = new Account(); account.deposit(500); String testStatement = account.printStatement(); String[] lines = testStatement.split("\n"); StatementLine line = parseStatementLine(lines[lines.length - 1]); assertEquals(500, line.amount()); } @Test void depositAmountIsAddedToAccountBalance(){ Account account = new Account(); account.deposit(500); String testStatement = account.printStatement(); String[] lines = testStatement.split("\n"); StatementLine line = parseStatementLine(lines[lines.length - 1]); assertEquals(500, line.balance()); } @Test void depositDateIsDisplayedOnStatment(){ String DATE_FORMATTER= "dd-MM-yyyy"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMATTER); Account account = new Account(); account.deposit(500); String testStatement = account.printStatement(); String[] lines = testStatement.split("\n"); StatementLine line = parseStatementLine(lines[lines.length - 1]); assertEquals(LocalDateTime.now().format(formatter), line.date()); } @Test void withdrawalAmountIsDisplayedOnStatement(){ Account account = new Account(); account.deposit(500); account.withdraw(100); String testStatement = account.printStatement(); String[] lines = testStatement.split("\n"); StatementLine line = parseStatementLine(lines[lines.length - 1]); assertEquals(100, line.amount()); } @Test void withdrawalAmountIsSubtractedFromAccountBalance(){ Account account = new Account(); account.deposit(500); account.withdraw(100); String testStatement = account.printStatement(); String[] lines = testStatement.split("\n"); StatementLine line = parseStatementLine(lines[lines.length - 1]); assertEquals(400, line.balance()); } @Test void withdrawalDateIsDisplayedOnStatment(){ String DATE_FORMATTER= "dd-MM-yyyy"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMATTER); Account account = new Account(); account.deposit(100); account.withdraw(100); String testStatement = account.printStatement(); String[] lines = testStatement.split("\n"); StatementLine line = parseStatementLine(lines[lines.length - 1]); assertEquals(LocalDateTime.now().format(formatter), line.date()); } @Test public void cannotOverdrawAccount(){ } //test helper method private StatementLine parseStatementLine(String statementLine) { String[] lineContents = statementLine.trim().split("\\s"); String date = lineContents[0]; int amount = Integer.parseInt(lineContents[1]); int balance = Integer.parseInt(lineContents[2]); return new StatementLine(date, amount, balance); } private record StatementLine(String date, int amount, int balance){} }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import static org.junit.jupiter.api.Assertions.assertTrue;
- import static org.junit.jupiter.api.Assertions.assertArrayEquals;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- // TODO: Replace examples and use TDD by writing your own tests
- class SolutionTest {
- @Test
- void printStatement_displays_column_headings() {
- Account account = new Account();
- String statement = account.printStatement();
- String[] rows = statement.split("\\n");
- String[] columns= rows[0].split("\\s");
- String[] expectedColumns = "Date Amount Balance".split(" ");
- assertArrayEquals(expectedColumns, columns);
- }
- @Test
- void depositAmountIsDisplayedOnStatement(){
- Account account = new Account();
- account.deposit(500);
- String testStatement = account.printStatement();
- String[] lines = testStatement.split("\n");
- StatementLine line = parseStatementLine(lines[lines.length - 1]);
- assertEquals(500, line.amount());
- }
- @Test
- void depositAmountIsAddedToAccountBalance(){
- Account account = new Account();
- account.deposit(500);
- String testStatement = account.printStatement();
- String[] lines = testStatement.split("\n");
- StatementLine line = parseStatementLine(lines[lines.length - 1]);
- assertEquals(500, line.balance());
- }
- @Test
- void depositDateIsDisplayedOnStatment(){
- String DATE_FORMATTER= "dd-MM-yyyy";
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMATTER);
- Account account = new Account();
- account.deposit(500);
- String testStatement = account.printStatement();
- String[] lines = testStatement.split("\n");
- StatementLine line = parseStatementLine(lines[lines.length - 1]);
- assertEquals(LocalDateTime.now().format(formatter), line.date());
- }
- @Test
- void withdrawalAmountIsDisplayedOnStatement(){
- Account account = new Account();
- account.deposit(500);
- account.withdraw(100);
- String testStatement = account.printStatement();
- String[] lines = testStatement.split("\n");
- StatementLine line = parseStatementLine(lines[lines.length - 1]);
- assertEquals(100, line.amount());
- }
- @Test
- void withdrawalAmountIsSubtractedFromAccountBalance(){
- Account account = new Account();
- account.deposit(500);
- account.withdraw(100);
- String testStatement = account.printStatement();
- String[] lines = testStatement.split("\n");
- StatementLine line = parseStatementLine(lines[lines.length - 1]);
- assertEquals(400, line.balance());
- }
- @Test
- void withdrawalDateIsDisplayedOnStatment(){
- String DATE_FORMATTER= "dd-MM-yyyy";
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMATTER);
- Account account = new Account();
account.lastTransactionBalance = 100;- account.deposit(100);
- account.withdraw(100);
- String testStatement = account.printStatement();
- String[] lines = testStatement.split("\n");
- StatementLine line = parseStatementLine(lines[lines.length - 1]);
- assertEquals(LocalDateTime.now().format(formatter), line.date());
- }
- @Test
- public void cannotOverdrawAccount(){
- }
- //test helper method
- private StatementLine parseStatementLine(String statementLine) {
- String[] lineContents = statementLine.trim().split("\\s");
- String date = lineContents[0];
- int amount = Integer.parseInt(lineContents[1]);
- int balance = Integer.parseInt(lineContents[2]);
- return new StatementLine(date, amount, balance);
- }
- private record StatementLine(String date, int amount, int balance){}
- }