Strings
public class ConfusedDouble { public static String clearDouble(String str) { if (str == null || str.length() == 0 || str.matches("^[^.]*$")){ return ""; } String ret = str.replaceAll("[^0-9.]", ""); if(ret.length() == 1) return ""; return ret; } }
//hacer que no funcione con una expresion regular con el caracter fin de cadena- public class ConfusedDouble {
public static String clearDouble(String str) {- 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;- return "";
- }
- String ret = str.replaceAll("[^0-9.]", "");
- if(ret.length() == 1) return "";
- return ret;
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Random; import org.junit.jupiter.api.Tag; class ConfusedDoubleTest { @Test @Tag("SampleTests") void SampleTests() { assertEquals("523.8822", ConfusedDouble.clearDouble("d5fjhjed`´<23.882fhhjk2")); assertEquals("3.15", ConfusedDouble.clearDouble("sakd3xH>Q;_r.wB1==5")); assertEquals("", ConfusedDouble.clearDouble("djasfkhkcnksnd12346gfkdj")); assertEquals("", ConfusedDouble.clearDouble("95847352414153884")); } @Test @Tag("EmptyDoubleTest") void emptyDoubleTest() { assertEquals("", ConfusedDouble.clearDouble(".")); } @Test @Tag("NullityTest") void nullityTest() { assertEquals("", ConfusedDouble.clearDouble(null)); } @Test @Tag("EmptyStringTest") void emptyTest() { assertEquals("", ConfusedDouble.clearDouble("")); } @Test @Tag("RandomTests") void randomTest() { //Tests for a random generated String 50 times Random r = new Random(); for(int j = 0; j < 50; ++j) { StringBuilder sb = new StringBuilder(); int i = 0; //Creates a string of 100 random characters from ASCII table while(i < 100) { int numAscii = r.nextInt(256); if(numAscii != 46) {//46 - point in ASCII table sb.append((char)numAscii); i++; } } sb.insert(r.nextInt(sb.length()), '.'); String randomText = sb.toString(); 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 org.junit.jupiter.api.Tag;
- class ConfusedDoubleTest {
- @Test
- @Tag("SampleTests")
- void SampleTests() {
//assertEquals("expected", "actual");- assertEquals("523.8822", ConfusedDouble.clearDouble("d5fjhjed`´<23.882fhhjk2"));
- assertEquals("3.15", ConfusedDouble.clearDouble("sakd3xH>Q;_r.wB1==5"));
- assertEquals("", ConfusedDouble.clearDouble("djasfkhkcnksnd12346gfkdj"));
- assertEquals("", ConfusedDouble.clearDouble("95847352414153884"));
assertEquals("", ConfusedDouble.clearDouble(""));- }
- @Test
- @Tag("EmptyDoubleTest")
- void emptyDoubleTest() {
- assertEquals("", ConfusedDouble.clearDouble("."));
- }
- @Test
- @Tag("NullityTest")
- void nullityTest() {
- assertEquals("", ConfusedDouble.clearDouble(null));
- }
- @Test
- @Tag("EmptyStringTest")
- void emptyTest() {
- assertEquals("", ConfusedDouble.clearDouble(""));
- }
- @Test
- @Tag("RandomTests")
- void randomTest() {
//creates a string of 100 random characters from ASCII table- //Tests for a random generated String 50 times
- Random r = new Random();
StringBuilder sb = new StringBuilder();int i = 0;while(i < 100) {int numAscii = r.nextInt(256);if(numAscii != 46) {//46 - point in ASCII tablesb.append((char)numAscii);i++;- for(int j = 0; j < 50; ++j) {
- StringBuilder sb = new StringBuilder();
- int i = 0;
- //Creates a string of 100 random characters from ASCII table
- while(i < 100) {
- int numAscii = r.nextInt(256);
- if(numAscii != 46) {//46 - point in ASCII table
- sb.append((char)numAscii);
- i++;
- }
- }
- sb.insert(r.nextInt(sb.length()), '.');
- String randomText = sb.toString();
- assertEquals(Kata.clearDouble(randomText), ConfusedDouble.clearDouble(randomText));
- }
- }
sb.insert(r.nextInt(sb.length()), '.');String randomText = sb.toString();assertEquals(Kata.clearDouble(randomText), ConfusedDouble.clearDouble(randomText));}- }
Strings
//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 @Tag("SampleTests") void SampleTests() { //assertEquals("expected", "actual"); 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(); StringBuilder sb = new StringBuilder(); int i = 0; while(i < 100) { int numAscii = r.nextInt(256); if(numAscii != 46) { sb.append((char)numAscii); ++i; } } sb.insert(r.nextInt(sb.length()), '.'); String randomText = sb.toString(); 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
- @Tag("SampleTests")
- void SampleTests() {
// assertEquals("expected", "actual");- //assertEquals("expected", "actual");
- 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, 256);randomText += (char)numAscii;}assertEquals(Kata.clearDouble(randomText), ConfusedDouble.clearDouble(randomText));}- Random r = new Random();
- StringBuilder sb = new StringBuilder();
- int i = 0;
- while(i < 100) {
- int numAscii = r.nextInt(256);
- if(numAscii != 46) {
- sb.append((char)numAscii);
- ++i;
- }
- }
- sb.insert(r.nextInt(sb.length()), '.');
- String randomText = sb.toString();
- assertEquals(Kata.clearDouble(randomText), ConfusedDouble.clearDouble(randomText));
- }
- }
Strings
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class SolutionTest { @Test void BasicTests() { // añadir tests de prueba, nulidad, cadena vacia etc // assertEquals("expected", "actual"); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- class SolutionTest {
- @Test
- void BasicTests() {
// añadir tests de prueba- // añadir tests de prueba, nulidad, cadena vacia etc
- // assertEquals("expected", "actual");
- }
- }