Strings
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("")); assertEquals("", ConfusedDouble.clearDouble(null)); } @Test @Tag("RandomTests") void randomTest() { //creates a string of 100 random characters from ASCII table 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 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(""));
- assertEquals("", ConfusedDouble.clearDouble(null));
- }
- @Test
- @Tag("RandomTests")
- void randomTest() {
- //creates a string of 100 random characters from ASCII table
- 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++;}- 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));
- }
- }
Strings
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("")); assertEquals("", ConfusedDouble.clearDouble(null)); } @Test @Tag("RandomTests") void randomTest() { //creates a string of 100 random characters from ASCII table 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 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 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("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(""));
- 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));}- //creates a string of 100 random characters from ASCII table
- 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 table
- sb.append((char)numAscii);
- i++;
- }
- }
- 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; } }
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, 256); randomText += (char)numAscii; } 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("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);- int numAscii = ThreadLocalRandom.current().nextInt(1, 256);
- randomText += (char)numAscii;
- }
System.out.println(randomText);- assertEquals(Kata.clearDouble(randomText), ConfusedDouble.clearDouble(randomText));
- }
- }
Strings
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(); 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)); } }
- 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() {- @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();
- 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));
- }
- }
Strings
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class ConfusedDoubleTest { @Test void BasicTests() { // 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)); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- class ConfusedDoubleTest {
- @Test
- void BasicTests() {
- // 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));
- }
- }
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){ 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 double clearDouble(String str) {if (str == null || str.length() == 0) return 0;return Double.parseDouble(str.replaceAll("[^0-9.]", ""));- public static String clearDouble(String str) {
- if (str == null || str.length() == 0){
- 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; class ConfusedDoubleTest { @Test void BasicTests() { // assertEquals("expected", "actual"); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- class ConfusedDoubleTest {
- @Test
- void BasicTests() {
// añadir tests de prueba, nulidad, cadena vacia etc// assertEquals("expected", "actual");- // assertEquals("expected", "actual");
- }
- }
Strings
//hacer que no funcione con una expresion regular con el caracter fin de cadena public class ConfusedDouble { public static double clearDouble(String str) { if (str == null || str.length() == 0) return 0; return Double.parseDouble(str.replaceAll("[^0-9.]", "")); } }
- //hacer que no funcione con una expresion regular con el caracter fin de cadena
public class Solution {- public class ConfusedDouble {
- public static double clearDouble(String str) {
- if (str == null || str.length() == 0) return 0;
- return Double.parseDouble(str.replaceAll("[^0-9.]", ""));
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class ConfusedDoubleTest { @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 {- class ConfusedDoubleTest {
- @Test
- void BasicTests() {
- // añadir tests de prueba, nulidad, cadena vacia etc
- // assertEquals("expected", "actual");
- }
- }