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.
Cambio al inicializar el nextIndex
import java.text.ParseException; import java.util.ArrayList; import java.util.Arrays; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; public class Kata{ public static String[] replaceLetter(String str, int n) { ArrayList<String> arr = new ArrayList<>(); StringBuilder strFinal = new StringBuilder(str); for (int i = 0; i < str.length(); i++) { int nextIndex = (i + n) % str.length(); if (str.charAt(i) != ' ' && str.charAt(nextIndex) != ' ') { nextIndex = (i + n) % str.length(); strFinal.replace(i, i + 1, String.valueOf(str.charAt(nextIndex))); arr.add(strFinal.toString()); strFinal.replace(0, str.length(), str); } } System.out.println(arr.toString()); String[] array = arr.toArray(new String[arr.size()]); return array; } }
- import java.text.ParseException;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Random;
- import java.util.concurrent.ThreadLocalRandom;
- public class Kata{
- public static String[] replaceLetter(String str, int n) {
- ArrayList<String> arr = new ArrayList<>();
- StringBuilder strFinal = new StringBuilder(str);
- for (int i = 0; i < str.length(); i++) {
int nextIndex = 0;- int nextIndex = (i + n) % str.length();
- if (str.charAt(i) != ' ' && str.charAt(nextIndex) != ' ') {
- nextIndex = (i + n) % str.length();
- strFinal.replace(i, i + 1, String.valueOf(str.charAt(nextIndex)));
- arr.add(strFinal.toString());
- strFinal.replace(0, str.length(), str);
- }
- }
- System.out.println(arr.toString());
- String[] array = arr.toArray(new String[arr.size()]);
- return array;
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.DisplayName; import java.util.Random; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { @Test void testWords() { assertEquals("PR", Encrypt.encryptByVowels("PR")); assertEquals("bc", Encrypt.encryptByVowels("ab")); } @Test void testWrap(){ assertEquals("ab", Encrypt.encryptByVowels("Za")); assertEquals("Ab", Encrypt.encryptByVowels("za")); } @Test void testEmptyOrBlank(){ assertEquals("", Encrypt.encryptByVowels("")); assertEquals(" ", Encrypt.encryptByVowels(" ")); } @Test void sentences(){ assertEquals("Mtqf vzj yfq", Encrypt.encryptByVowels("Hola que tal")); } @DisplayName("Random tests") @RepeatedTest(40) void randomTests() { Random rand = new Random(); String str = ""; for(int j = 0; j < rand.nextInt(1, 5); j++){ for(int i = 0; i < rand.nextInt(1, 100); i++){ int randomNumber = rand.nextInt(65, 122); if(randomNumber > 90 && randomNumber < 97) randomNumber+=(97-randomNumber); str+=""+(char)randomNumber; } str+=" "; } assertEquals(Encrypt.encryptByVowels(str.substring(0, str.length()-1)) ,sol(str.substring(0, str.length()-1))); } public static String sol(String s) { StringBuilder sb = new StringBuilder(); int cont = 0; for(char c: s.toLowerCase().toCharArray()) { if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') cont++; } for(char c: s.toCharArray()) { int newChar = (int) c; if(c != ' '){ newChar = c+cont; if(newChar > 90 && newChar < 97) newChar+=(97-newChar); while(newChar > 122) { newChar = 64 + newChar%122; if(newChar > 90 && newChar < 97) newChar+=(97-newChar); } } sb.append((char)newChar); } return sb.toString(); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import org.junit.jupiter.api.RepeatedTest;
- import org.junit.jupiter.api.DisplayName;
- import java.util.Random;
- // TODO: Replace examples and use TDD by writing your own tests
- class SolutionTest {
- @Test
- void testWords() {
- assertEquals("PR", Encrypt.encryptByVowels("PR"));
- assertEquals("bc", Encrypt.encryptByVowels("ab"));
- }
- @Test
- void testWrap(){
- assertEquals("ab", Encrypt.encryptByVowels("Za"));
- assertEquals("Ab", Encrypt.encryptByVowels("za"));
- }
- @Test
- void testEmptyOrBlank(){
- assertEquals("", Encrypt.encryptByVowels(""));
- assertEquals(" ", Encrypt.encryptByVowels(" "));
- }
- @Test
- void sentences(){
- assertEquals("Mtqf vzj yfq", Encrypt.encryptByVowels("Hola que tal"));
- }
- @DisplayName("Random tests")
- @RepeatedTest(40)
- void randomTests() {
- Random rand = new Random();
- String str = "";
- for(int j = 0; j < rand.nextInt(1, 5); j++){
- for(int i = 0; i < rand.nextInt(1, 100); i++){
- int randomNumber = rand.nextInt(65, 122);
- if(randomNumber > 90 && randomNumber < 97)
- randomNumber+=(97-randomNumber);
- str+=""+(char)randomNumber;
- }
- str+=" ";
- }
- assertEquals(Encrypt.encryptByVowels(str.substring(0, str.length()-1)) ,sol(str.substring(0, str.length()-1)));
- }
- public static String sol(String s) {
String newS = "";int cont = 0;for(char c: s.toLowerCase().toCharArray()) {if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')cont++;}for(char c: s.toCharArray()) {int newChar = (int) c;if(c != ' '){newChar = c+cont;if(newChar > 90 && newChar < 97)newChar+=(97-newChar);if(newChar > 122) {newChar = 64 + newChar%122;if(newChar > 90 && newChar < 97)newChar+=(97-newChar);- StringBuilder sb = new StringBuilder();
- int cont = 0;
- for(char c: s.toLowerCase().toCharArray()) {
- if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
- cont++;
- }
- for(char c: s.toCharArray()) {
- int newChar = (int) c;
- if(c != ' '){
- newChar = c+cont;
- if(newChar > 90 && newChar < 97)
- newChar+=(97-newChar);
- while(newChar > 122) {
- newChar = 64 + newChar%122;
- if(newChar > 90 && newChar < 97)
- newChar+=(97-newChar);
- }
- }
- sb.append((char)newChar);
- }
newS+=""+(char)newChar;}return newS;- return sb.toString();
- }
- }
//hacer que no funcione con una expresion regular con el caracter fin de cadena public class ConfusedDouble { public static String clearDouble(String str) { if (str == null || str.length() == 0 || str.matches("^[^.]*$")){ return ""; } double num = Double.parseDouble(str.replaceAll("[^0-9.]", "")); String result = Double.toString(num); return result; } }
- //hacer que no funcione con una expresion regular con el caracter fin de cadena
- public class ConfusedDouble {
- public static String clearDouble(String str) {
if (str == null || str.length() == 0){- if (str == null || str.length() == 0 || str.matches("^[^.]*$")){
- return "";
- }
- double num = Double.parseDouble(str.replaceAll("[^0-9.]", ""));
- String result = Double.toString(num);
- return result;
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; import org.junit.jupiter.api.Tag; class ConfusedDoubleTest { @Test void BasicTests() { assertEquals("4.3454", ConfusedDouble.clearDouble("dsa4da.3fsdf45fds4")); assertEquals("23.8822", ConfusedDouble.clearDouble("dfjhjed`´<23.882fhhjk2")); assertEquals("", ConfusedDouble.clearDouble("djasfkhkcnksnd12346gfkdj")); assertEquals("", ConfusedDouble.clearDouble("95847352414153884")); assertEquals("", ConfusedDouble.clearDouble("")); assertEquals("", ConfusedDouble.clearDouble(null)); } @Test @Tag("RandomTests") void randomTest() { Random r = new Random(); String randomText = ""; for (int i = 0; i < 99; i++) { int numAscii = ThreadLocalRandom.current().nextInt(1, 255); randomText += (char)numAscii; } System.out.println(randomText); assertEquals(Kata.clearDouble(randomText), ConfusedDouble.clearDouble(randomText)); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import java.util.Random;
- import java.util.concurrent.ThreadLocalRandom;
- import org.junit.jupiter.api.Tag;
- class ConfusedDoubleTest {
- @Test
- void BasicTests() {
// assertEquals("expected", "actual");- assertEquals("4.3454", ConfusedDouble.clearDouble("dsa4da.3fsdf45fds4"));
- assertEquals("23.8822", ConfusedDouble.clearDouble("dfjhjed`´<23.882fhhjk2"));
//assertEquals("", ConfusedDouble.clearDouble("djasfkhkcnksnd12346gfkdj"));//assertEquals("", ConfusedDouble.clearDouble("95847352414153884"));- assertEquals("", ConfusedDouble.clearDouble("djasfkhkcnksnd12346gfkdj"));
- assertEquals("", ConfusedDouble.clearDouble("95847352414153884"));
- assertEquals("", ConfusedDouble.clearDouble(""));
- assertEquals("", ConfusedDouble.clearDouble(null));
- }
- @Test
- @Tag("RandomTests")
- void randomTest() {
- Random r = new Random();
- String randomText = "";
- for (int i = 0; i < 99; i++) {
- int numAscii = ThreadLocalRandom.current().nextInt(1, 255);
- randomText += (char)numAscii;
- }
- System.out.println(randomText);
- assertEquals(Kata.clearDouble(randomText), ConfusedDouble.clearDouble(randomText));
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { @Test void basicTest() { assertEquals(10, Solution.lastPoint(52, 5, new int[] { 2, 5, 10, 15 } )); assertEquals(45, Solution.lastPoint(250, 5, new int[] { 10, 15, 30, 45 } )); assertEquals(-1, Solution.lastPoint(50, 25, new int[] { 10, 20, 30, 40, 50 } )); } @Test void moreBasicTest() { assertEquals(16, Solution.lastPoint(100, 2, new int[] { 4, 8, 12, 16 } )); assertEquals(20, Solution.lastPoint(130, 4, new int[] { 5, 15, 20, 50 } )); assertEquals(-1, Solution.lastPoint(200, 10, new int[] { 80, 85, 100} )); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- // TODO: Replace examples and use TDD by writing your own tests
- class SolutionTest {
- @Test
- void basicTest() {
- assertEquals(10, Solution.lastPoint(52, 5, new int[] { 2, 5, 10, 15 } ));
- assertEquals(45, Solution.lastPoint(250, 5, new int[] { 10, 15, 30, 45 } ));
- assertEquals(-1, Solution.lastPoint(50, 25, new int[] { 10, 20, 30, 40, 50 } ));
- }
- @Test
- void moreBasicTest() {
- assertEquals(16, Solution.lastPoint(100, 2, new int[] { 4, 8, 12, 16 } ));
- assertEquals(20, Solution.lastPoint(130, 4, new int[] { 5, 15, 20, 50 } ));
- assertEquals(-1, Solution.lastPoint(200, 10, new int[] { 80, 85, 100} ));
- }
- }