From 72e3f6de9f446d81f858e25ccea737a67655b934 Mon Sep 17 00:00:00 2001 From: 666nonak666 Date: Mon, 20 Mar 2017 19:06:01 +0000 Subject: [PATCH 1/8] prueba task 1and 2 --- .../coding/norman/Kata2/CodingTask2.java | 50 +++++++++++++ .../coding/norman/kata1/Task1.java | 56 +++++++++++++++ .../coding/norman/Kata2/CodingTask2Test.java | 70 +++++++++++++++++++ .../coding/norman/kata1/Task1Test.java | 43 ++++++++++++ 4 files changed, 219 insertions(+) create mode 100644 src/main/java/org/fundacionjala/coding/norman/Kata2/CodingTask2.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/kata1/Task1.java create mode 100644 src/test/java/org/fundacionjala/coding/norman/Kata2/CodingTask2Test.java create mode 100644 src/test/java/org/fundacionjala/coding/norman/kata1/Task1Test.java diff --git a/src/main/java/org/fundacionjala/coding/norman/Kata2/CodingTask2.java b/src/main/java/org/fundacionjala/coding/norman/Kata2/CodingTask2.java new file mode 100644 index 0000000..666fa24 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/Kata2/CodingTask2.java @@ -0,0 +1,50 @@ +package org.fundacionjala.coding.norman.Kata2; + +/** + * Created by Administrator on 3/20/2017. + */ + +/** + * @author Norman + */ +public final class CodingTask2 { + private static final int LIMIT = 5; + + private static final String SPACE_DELIMITER = " "; + + /** + * Constructor. + */ + private CodingTask2() { + + } + + /** + * @param sentence String the origin + * @return sentence the change sentence + * @This function change the words the size major 5. + */ + public static String functionReverse(final String sentence) { + // String res = ""; + + // String s1=sentence; + String[] words = sentence.split(SPACE_DELIMITER); + // int cont=0; + // StringBuilder str=new StringBuilder(); + for (int i = 0; i < words.length; i++) { + //str.append(words[i]); + // str=new StringBuilder(words[i]); + if (words[i].length() >= LIMIT) { + words[i] = new StringBuilder(words[i]).reverse().toString(); + // words[i]=""+str.reverse(); + + + } + } + return String.join(" ", words); + //return res=mostrar(words); + + } + + +} diff --git a/src/main/java/org/fundacionjala/coding/norman/kata1/Task1.java b/src/main/java/org/fundacionjala/coding/norman/kata1/Task1.java new file mode 100644 index 0000000..efa6373 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/kata1/Task1.java @@ -0,0 +1,56 @@ +package org.fundacionjala.coding.norman.kata1; + +/** + * Norman. + * + */ +public final class Task1 { + /** + * Validate a given EAN-Code. Return true if the given EAN-Code is valid, otherwise false. + * You can assume the given code is syntactically valid, i.e. it only consists of numbers and it exactly + * has a length of 13 characters. + * Examples + * EANValidator.validate("4003301018398") // True + * EANValidator.validate("4003301018392") // False + */ + + + private static final int DIGIT_MULTIPLIER = 3; + private static final int DIVISIBILITY_FACTOR = 10; + + + /** + * Constructor private. + */ + + private Task1() { + } + + /** + * Takes an string number to verify it is checksum it's correct. + * + * @param eAN String number with exactly 13 digits. + * @return true if the checksum is ok. + */ + + public static boolean validate(final String eAN) { + int sum = 0; + + + for (int i = 1; i < eAN.length(); i++) { + int numericValue = Character.getNumericValue(eAN.charAt(i - 1)); + sum += i % 2 == 0 ? numericValue * DIGIT_MULTIPLIER : numericValue; + } + + int module = sum % DIVISIBILITY_FACTOR; + int check = module != 0 ? DIVISIBILITY_FACTOR - module : 0; + + return check == Character.getNumericValue(eAN.charAt(eAN.length() - 1)); + + } + + +} + + + diff --git a/src/test/java/org/fundacionjala/coding/norman/Kata2/CodingTask2Test.java b/src/test/java/org/fundacionjala/coding/norman/Kata2/CodingTask2Test.java new file mode 100644 index 0000000..7a05c65 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/norman/Kata2/CodingTask2Test.java @@ -0,0 +1,70 @@ +package org.fundacionjala.coding.norman.Kata2; + +//import org.junit.jupiter.api.Test; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +// import org.junit.jupiter.api.Test; + + +/** + * Created by Administrator on 3/20/2017. + */ + +public class CodingTask2Test { + + + /** + * Test when testValidateReverse2Words. + */ + @Test + public void testValidateReverse2Words() { + // given: + final String stringReverse = "Hey fellow warriors"; + + // when: + final String actualResult = CodingTask2.functionReverse(stringReverse); + + // then: + final String expectedResult = "Hey wollef sroirraw"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test when testValidateNoReverse. + */ + @Test + public void testValidateNoReverse() { + // given: + final String stringReverse = "This is a test"; + + // when: + final String actualResult = CodingTask2.functionReverse(stringReverse); + + // then: + assertEquals(stringReverse, actualResult); + } + + /** + * Test when testValidateReverse1WordInMidle. + */ + @Test + public void testValidateReverse1WordInMidle() { + // given: + final String stringReverse = "This is another test"; + + // when: + final String actualResult = CodingTask2.functionReverse(stringReverse); + + // then: + final String expectedResult = "This is rehtona test"; + assertEquals(expectedResult, actualResult); + } + + + //spinWords( "Hey fellow warriors" ) => returns "Hey wollef sroirraw" + //spinWords( "This is a test") => returns "This is a test" + //spinWords( "This is another test" )=> returns "This is rehtona test" + +} diff --git a/src/test/java/org/fundacionjala/coding/norman/kata1/Task1Test.java b/src/test/java/org/fundacionjala/coding/norman/kata1/Task1Test.java new file mode 100644 index 0000000..0b9f869 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/norman/kata1/Task1Test.java @@ -0,0 +1,43 @@ +package org.fundacionjala.coding.norman.kata1; + + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +/** + * Test kata2. + */ +public class Task1Test { + + /** + * Test when the EAN string number checksum is different from 0. + */ + @Test + public void testValidateTheCheckSumIsDifferentFromZero() { + // given: + final String eanStringNumber = "4003301018398"; + + // when: + final boolean actualResult = Task1.validate(eanStringNumber); + + // then: + assertTrue(actualResult); + } + + /** + * Test when the EAN string number checksum is equal to 0. + */ + @Test + public void testValidateTheCheckSumIsEqualToZero() { + // given: + final String eanStringNumber = "4003301018392"; + + // when: + final boolean actualResult = Task1.validate(eanStringNumber); + + // then: + assertTrue(!actualResult); + } + } + + From 021b19dc504c581468f1af6a8249665447d2b0c7 Mon Sep 17 00:00:00 2001 From: 666nonak666 Date: Thu, 23 Mar 2017 15:24:01 +0000 Subject: [PATCH 2/8] refactor calculateAmount --- .../coding/norman/movie/Children.java | 35 +++++++++ .../coding/norman/movie/Customer.java | 77 +++++++++++++++++++ .../coding/norman/movie/Movie.java | 32 ++++++++ .../coding/norman/movie/NewRelease.java | 31 ++++++++ .../coding/norman/movie/Regular.java | 38 +++++++++ .../coding/norman/movie/Rental.java | 46 +++++++++++ 6 files changed, 259 insertions(+) create mode 100644 src/main/java/org/fundacionjala/coding/norman/movie/Children.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/movie/Customer.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/movie/Movie.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/movie/NewRelease.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/movie/Regular.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/movie/Rental.java diff --git a/src/main/java/org/fundacionjala/coding/norman/movie/Children.java b/src/main/java/org/fundacionjala/coding/norman/movie/Children.java new file mode 100644 index 0000000..50cdd2d --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/movie/Children.java @@ -0,0 +1,35 @@ +package org.fundacionjala.coding.norman.movie; + +/** + * Created by Administrator on 3/21/2017. + */ +public class Children extends Movie { + private static final int LIMITNEWCHILD = 3; + private static final double PRICE = 1.5; + /** + * contructor children. + * @param title the name + */ + public Children(final String title) { + super(title); + } + + @Override + public double calculateAmount(final int daysRented) { + // double amount = PRICE; + // if (daysRented > LIMITNEWCHILD) { + // amount += (daysRented - LIMITNEWCHILD) * PRICE; + // } + // return amount; + //sum += i % 2 == 0 ? numericValue * DIGIT_MULTIPLIER : numericValue; + return daysRented > LIMITNEWCHILD ? ((daysRented - LIMITNEWCHILD) * PRICE)+PRICE : PRICE ; + } + /** + * @param daysRented . + * return double of calculateFrequentRenterPoints. + */ + @Override + public int calculateFrequentRenterPoints(final int daysRented) { + return 1; + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/movie/Customer.java b/src/main/java/org/fundacionjala/coding/norman/movie/Customer.java new file mode 100644 index 0000000..16c4724 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/movie/Customer.java @@ -0,0 +1,77 @@ +package org.fundacionjala.coding.norman.movie; + +import java.util.ArrayList; +import java.util.List; + + +/** + * This is the class Customer of rental movie. + */ +public class Customer { + private String nameCustomer; + private List rentalsCustomer; + + /** + * @param nameCustomer String with words. + * Constructor. + */ + Customer(final String nameCustomer) { + this.nameCustomer = nameCustomer; + rentalsCustomer = new ArrayList<>(); + } + + /** + * @param rental String with words. + */ + public void addRental(final Rental rental) { + rentalsCustomer.add(rental); + } + + /** + * @return the nameCustomer string. + */ + public String getName() { + return this.nameCustomer; + } + + /** + * @return the string. + */ + public String generateDetail() { + StringBuffer result = new StringBuffer(); + result.append("Rental Record for " + getName() + "\n"); + for (Rental rental : rentalsCustomer) { + result.append("\t" + rental.getMovie().getTitle() + "\t"); + result.append(rental.calculateAmount() + "\n"); + } + result.append("Amount owed is " + calculateTotalAmount() + "\n"); + result.append("You earned " + calculateTotalFrequentRenterPoints() + " frequent renter points"); + return result.toString(); + } + /** + * @return double the TotalAmount. + */ + public double calculateTotalAmount() { +// double totalAmount = 0; +// for (Rental rental : rentalsCustomer) { +// totalAmount += rental.calculateAmount(); +// } +// return totalAmount; + return rentalsCustomer.stream() + .mapToDouble(Rental::calculateAmount) + .sum(); + } + /** + * @return int the Total of FrequentRenterPoints. + */ + public int calculateTotalFrequentRenterPoints() { +// int totalFrequentRenterPoints = 0; +// for (Rental rental : rentalsCustomer) { +// totalFrequentRenterPoints += rental.calculateFrequentRenterPoint(); +// } +// return totalFrequentRenterPoints; + return rentalsCustomer.stream() + .mapToInt(rental -> rental.calculateFrequentRenterPoint()) + .sum(); + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/movie/Movie.java b/src/main/java/org/fundacionjala/coding/norman/movie/Movie.java new file mode 100644 index 0000000..dd1aed7 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/movie/Movie.java @@ -0,0 +1,32 @@ +package org.fundacionjala.coding.norman.movie; + +/** + * Created by Administrator on 3/21/2017. + */ +public abstract class Movie { + private String title; + + /** + * @param title of movie. + */ + public Movie(final String title) { + this.title = title; + } + /** + * @param daysRented int number. + * @return calculateAmount. + */ + public abstract double calculateAmount(int daysRented); + /** + * @param daysRented int days. + * @return calculateFrequentRenterPoint . + */ + public abstract int calculateFrequentRenterPoints(int daysRented); + /** + * + * @return getTitle. + */ + public String getTitle() { + return title; + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/movie/NewRelease.java b/src/main/java/org/fundacionjala/coding/norman/movie/NewRelease.java new file mode 100644 index 0000000..af2bc35 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/movie/NewRelease.java @@ -0,0 +1,31 @@ +package org.fundacionjala.coding.norman.movie; + +/** + * Created by Administrator on 3/21/2017. + */ +public class NewRelease extends Movie { + + private static final int LIMITNEWCHILD = 3; + /** + * contructor NewRelease. + * @param title string title. + */ + public NewRelease(final String title) { + super(title); + } + /** + * @param daysRented . + * @return double of calculateAmount. + */ + @Override + public double calculateAmount(final int daysRented) { + return daysRented * LIMITNEWCHILD; + } + /** + * @return calculateFrequentRenterPoint int. + */ + @Override + public int calculateFrequentRenterPoints(final int daysRented) { + return daysRented > 1 ? 2 : 1; + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/movie/Regular.java b/src/main/java/org/fundacionjala/coding/norman/movie/Regular.java new file mode 100644 index 0000000..bf56d63 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/movie/Regular.java @@ -0,0 +1,38 @@ +package org.fundacionjala.coding.norman.movie; + +/** + * Created by Administrator on 3/21/2017. + */ +public class Regular extends Movie { + + private static final double PRICE = 1.5; + + private static final int LIMITREGULAR = 2; + /** + * Constructor regular. + * @param title string title. + */ + public Regular(final String title) { + super(title); + } + /** + * @param daysRented int days. + * @return double of calculateAmount. + */ + @Override + public double calculateAmount(final int daysRented) { + // double amount = LIMITREGULAR; + // if (daysRented > LIMITREGULAR) { + // amount += (daysRented - LIMITREGULAR) * PRICE; + // } + // return amount; + return daysRented > LIMITREGULAR ? ((daysRented - LIMITREGULAR) * PRICE)+LIMITREGULAR : LIMITREGULAR ; + } + /** + * @return calculateFrequentRenterPoint int. + */ + @Override + public int calculateFrequentRenterPoints(final int daysRented) { + return 1; + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/movie/Rental.java b/src/main/java/org/fundacionjala/coding/norman/movie/Rental.java new file mode 100644 index 0000000..638b7f1 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/movie/Rental.java @@ -0,0 +1,46 @@ +package org.fundacionjala.coding.norman.movie; +/** + * Created by reinaldo on 11/03/2017. + */ +class Rental { + private Movie movie; + private int daysRented; + + /** + * @param movie Movie. + * @param daysRented DaysRented. + */ + Rental(final Movie movie, final int daysRented) { + this.movie = movie; + this.daysRented = daysRented; + } + + /** + * @return the daysRented. + */ + public int getDaysRented() { + return daysRented; + } + + /** + * @return movie object. + */ + public Movie getMovie() { + return this.movie; + } + + /** + * @return price object. + */ + public double calculateAmount() { + return movie.calculateAmount(daysRented); + } + + /** + * @return calculateFrequentRenterPoint int. + */ + public int calculateFrequentRenterPoint() { + return movie.calculateFrequentRenterPoints(daysRented); + } +} + From 60e9168d09757cf0899dd9b290bed819b6da0e84 Mon Sep 17 00:00:00 2001 From: 666nonak666 Date: Thu, 23 Mar 2017 19:06:33 +0000 Subject: [PATCH 3/8] exam passed test cases --- .../coding/norman/exam/Kata.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/org/fundacionjala/coding/norman/exam/Kata.java diff --git a/src/main/java/org/fundacionjala/coding/norman/exam/Kata.java b/src/main/java/org/fundacionjala/coding/norman/exam/Kata.java new file mode 100644 index 0000000..409d0bf --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/exam/Kata.java @@ -0,0 +1,30 @@ +package org.fundacionjala.coding.norman.exam; + +import java.lang.reflect.Array; +import java.util.Arrays; + +/** + * Created by Administrator on 3/23/2017. + */ +public class Kata { + + public static double[] averages(int[] input){ + double[] res; + if(input!=null&&input.length!=0&&input.length!=1) { + res = new double[input.length - 1]; + // } + //if(input.length!=0&&input.length!=1&&input!=null){ + + for (int i = 0; i < input.length - 1; i++) { + int contAux = i + 1; + // int indice=i; + res[i] = ((double) input[i] + (double) input[contAux]) / 2; + } + }else{ + return new double[0]; + } + //} + + return res ; + } +} From 58ad1da32efc31708c92e0f3d8030c0978fb9f90 Mon Sep 17 00:00:00 2001 From: 666nonak666 Date: Mon, 22 May 2017 17:56:54 +0000 Subject: [PATCH 4/8] Update Kata.java --- .../coding/norman/exam/Kata.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/fundacionjala/coding/norman/exam/Kata.java b/src/main/java/org/fundacionjala/coding/norman/exam/Kata.java index 409d0bf..2b34bb2 100644 --- a/src/main/java/org/fundacionjala/coding/norman/exam/Kata.java +++ b/src/main/java/org/fundacionjala/coding/norman/exam/Kata.java @@ -1,16 +1,25 @@ package org.fundacionjala.coding.norman.exam; -import java.lang.reflect.Array; -import java.util.Arrays; - /** - * Created by Administrator on 3/23/2017. + * Created by Norman on 3/23/2017. */ -public class Kata { - public static double[] averages(int[] input){ +public final class Kata { + /** + * constructor private. + */ + private Kata() { + } + + /** + * average. + * + * @return double[] of list. + * @param input list. + */ + public static double[] averages(final int[] input) { double[] res; - if(input!=null&&input.length!=0&&input.length!=1) { + if (input != null && input.length != 0 && input.length != 1) { res = new double[input.length - 1]; // } //if(input.length!=0&&input.length!=1&&input!=null){ @@ -20,11 +29,11 @@ public static double[] averages(int[] input){ // int indice=i; res[i] = ((double) input[i] + (double) input[contAux]) / 2; } - }else{ + } else { return new double[0]; } //} - return res ; + return res; } } From 7e3d84df763df3c819aaafad9517428a8360bdbe Mon Sep 17 00:00:00 2001 From: 666nonak666 Date: Mon, 22 May 2017 17:59:10 +0000 Subject: [PATCH 5/8] Update Children.java --- .../coding/norman/movie/Children.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/fundacionjala/coding/norman/movie/Children.java b/src/main/java/org/fundacionjala/coding/norman/movie/Children.java index 50cdd2d..7a5970f 100644 --- a/src/main/java/org/fundacionjala/coding/norman/movie/Children.java +++ b/src/main/java/org/fundacionjala/coding/norman/movie/Children.java @@ -1,13 +1,14 @@ -package org.fundacionjala.coding.norman.movie; /** - * Created by Administrator on 3/21/2017. + * Created by Norman on 3/21/2017. */ public class Children extends Movie { private static final int LIMITNEWCHILD = 3; private static final double PRICE = 1.5; + /** * contructor children. + * * @param title the name */ public Children(final String title) { @@ -16,17 +17,18 @@ public Children(final String title) { @Override public double calculateAmount(final int daysRented) { - // double amount = PRICE; - // if (daysRented > LIMITNEWCHILD) { + // double amount = PRICE; + // if (daysRented > LIMITNEWCHILD) { // amount += (daysRented - LIMITNEWCHILD) * PRICE; - // } - // return amount; + // } + // return amount; //sum += i % 2 == 0 ? numericValue * DIGIT_MULTIPLIER : numericValue; - return daysRented > LIMITNEWCHILD ? ((daysRented - LIMITNEWCHILD) * PRICE)+PRICE : PRICE ; + return daysRented > LIMITNEWCHILD ? ((daysRented - LIMITNEWCHILD) * PRICE) + PRICE : PRICE; } + /** * @param daysRented . - * return double of calculateFrequentRenterPoints. + * return double of calculateFrequentRenterPoints. */ @Override public int calculateFrequentRenterPoints(final int daysRented) { From 684442100f64f8aba6b8d1df8d9dda1aca227bb7 Mon Sep 17 00:00:00 2001 From: 666nonak666 Date: Mon, 22 May 2017 18:00:09 +0000 Subject: [PATCH 6/8] Update Regular.java --- .../fundacionjala/coding/norman/movie/Regular.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/fundacionjala/coding/norman/movie/Regular.java b/src/main/java/org/fundacionjala/coding/norman/movie/Regular.java index bf56d63..2461a9c 100644 --- a/src/main/java/org/fundacionjala/coding/norman/movie/Regular.java +++ b/src/main/java/org/fundacionjala/coding/norman/movie/Regular.java @@ -8,26 +8,30 @@ public class Regular extends Movie { private static final double PRICE = 1.5; private static final int LIMITREGULAR = 2; + /** * Constructor regular. + * * @param title string title. */ public Regular(final String title) { super(title); } + /** * @param daysRented int days. * @return double of calculateAmount. */ @Override public double calculateAmount(final int daysRented) { - // double amount = LIMITREGULAR; - // if (daysRented > LIMITREGULAR) { + // double amount = LIMITREGULAR; + // if (daysRented > LIMITREGULAR) { // amount += (daysRented - LIMITREGULAR) * PRICE; - // } - // return amount; - return daysRented > LIMITREGULAR ? ((daysRented - LIMITREGULAR) * PRICE)+LIMITREGULAR : LIMITREGULAR ; + // } + // return amount; + return daysRented > LIMITREGULAR ? ((daysRented - LIMITREGULAR) * PRICE) + LIMITREGULAR : LIMITREGULAR; } + /** * @return calculateFrequentRenterPoint int. */ From d8ddf2759614c4faa5845f14d20b01740fa599af Mon Sep 17 00:00:00 2001 From: 666nonak666 Date: Fri, 7 Jul 2017 00:39:40 +0000 Subject: [PATCH 7/8] fixed with package the Pablo and Ruber. --- .../coding/norman/Kata2/CodingTask2.java | 50 ---- .../coding/norman/average/Average.java | 30 +++ .../coding/norman/banck_ocr/Digit.java | 8 + .../norman/banck_ocr/FileNumberBankOcr.java | 84 ++++++ .../norman/banck_ocr/HistoryOneBankOcr.java | 29 +++ .../norman/banck_ocr/HistoryThreeErrFall.java | 23 ++ .../norman/banck_ocr/HistoryTwoChecksum.java | 34 +++ .../norman/eanvalidator/EANValidator.java | 40 +++ .../coding/norman/evaporator/Evaporator.java | 34 +++ .../coding/norman/exam/Kata.java | 39 --- .../highestandlowest/HighestAndLowest.java | 30 +++ .../coding/norman/kata1/Task1.java | 56 ---- .../coding/norman/movie/Children.java | 37 --- .../coding/norman/movie/Customer.java | 77 ------ .../coding/norman/movie/Movie.java | 32 --- .../coding/norman/movie/NewRelease.java | 31 --- .../coding/norman/movie/Regular.java | 42 --- .../coding/norman/movies/Children.java | 32 +++ .../coding/norman/movies/Customer.java | 79 ++++++ .../coding/norman/movies/Movie.java | 43 ++++ .../coding/norman/movies/NewRelease.java | 41 +++ .../coding/norman/movies/Regular.java | 34 +++ .../norman/{movie => movies}/Rental.java | 31 ++- .../norman/multiples3and5/Multiply3and5.java | 35 +++ .../coding/norman/spinwords/SpinWords.java | 33 +++ .../coding/norman/Kata2/CodingTask2Test.java | 70 ----- .../coding/norman/average/AverageTest.java | 116 +++++++++ .../coding/norman/banck_ocr/BankOcrTest.java | 239 ++++++++++++++++++ .../norman/eanvalidator/EANValidatorTest.java | 101 ++++++++ .../norman/evaporator/EvaporatorTest.java | 45 ++++ .../HighestAndLowestTest.java | 183 ++++++++++++++ .../coding/norman/kata1/Task1Test.java | 43 ---- .../coding/norman/movies/ChildrenTest.java | 106 ++++++++ .../coding/norman/movies/CustomerTest.java | 46 ++++ .../coding/norman/movies/NewReleaseTest.java | 80 ++++++ .../coding/norman/movies/RegularTest.java | 80 ++++++ .../multiples3and5/Multiply3and5Test.java | 37 +++ .../norman/spinwords/SpinWordsTest.java | 93 +++++++ 38 files changed, 1755 insertions(+), 488 deletions(-) delete mode 100644 src/main/java/org/fundacionjala/coding/norman/Kata2/CodingTask2.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/average/Average.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/banck_ocr/Digit.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/banck_ocr/FileNumberBankOcr.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/banck_ocr/HistoryOneBankOcr.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/banck_ocr/HistoryThreeErrFall.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/banck_ocr/HistoryTwoChecksum.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/eanvalidator/EANValidator.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/evaporator/Evaporator.java delete mode 100644 src/main/java/org/fundacionjala/coding/norman/exam/Kata.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/highestandlowest/HighestAndLowest.java delete mode 100644 src/main/java/org/fundacionjala/coding/norman/kata1/Task1.java delete mode 100644 src/main/java/org/fundacionjala/coding/norman/movie/Children.java delete mode 100644 src/main/java/org/fundacionjala/coding/norman/movie/Customer.java delete mode 100644 src/main/java/org/fundacionjala/coding/norman/movie/Movie.java delete mode 100644 src/main/java/org/fundacionjala/coding/norman/movie/NewRelease.java delete mode 100644 src/main/java/org/fundacionjala/coding/norman/movie/Regular.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/movies/Children.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/movies/Customer.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/movies/Movie.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/movies/NewRelease.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/movies/Regular.java rename src/main/java/org/fundacionjala/coding/norman/{movie => movies}/Rental.java (51%) create mode 100644 src/main/java/org/fundacionjala/coding/norman/multiples3and5/Multiply3and5.java create mode 100644 src/main/java/org/fundacionjala/coding/norman/spinwords/SpinWords.java delete mode 100644 src/test/java/org/fundacionjala/coding/norman/Kata2/CodingTask2Test.java create mode 100644 src/test/java/org/fundacionjala/coding/norman/average/AverageTest.java create mode 100644 src/test/java/org/fundacionjala/coding/norman/banck_ocr/BankOcrTest.java create mode 100644 src/test/java/org/fundacionjala/coding/norman/eanvalidator/EANValidatorTest.java create mode 100644 src/test/java/org/fundacionjala/coding/norman/evaporator/EvaporatorTest.java create mode 100644 src/test/java/org/fundacionjala/coding/norman/highestandlowest/HighestAndLowestTest.java delete mode 100644 src/test/java/org/fundacionjala/coding/norman/kata1/Task1Test.java create mode 100644 src/test/java/org/fundacionjala/coding/norman/movies/ChildrenTest.java create mode 100644 src/test/java/org/fundacionjala/coding/norman/movies/CustomerTest.java create mode 100644 src/test/java/org/fundacionjala/coding/norman/movies/NewReleaseTest.java create mode 100644 src/test/java/org/fundacionjala/coding/norman/movies/RegularTest.java create mode 100644 src/test/java/org/fundacionjala/coding/norman/multiples3and5/Multiply3and5Test.java create mode 100644 src/test/java/org/fundacionjala/coding/norman/spinwords/SpinWordsTest.java diff --git a/src/main/java/org/fundacionjala/coding/norman/Kata2/CodingTask2.java b/src/main/java/org/fundacionjala/coding/norman/Kata2/CodingTask2.java deleted file mode 100644 index 666fa24..0000000 --- a/src/main/java/org/fundacionjala/coding/norman/Kata2/CodingTask2.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.fundacionjala.coding.norman.Kata2; - -/** - * Created by Administrator on 3/20/2017. - */ - -/** - * @author Norman - */ -public final class CodingTask2 { - private static final int LIMIT = 5; - - private static final String SPACE_DELIMITER = " "; - - /** - * Constructor. - */ - private CodingTask2() { - - } - - /** - * @param sentence String the origin - * @return sentence the change sentence - * @This function change the words the size major 5. - */ - public static String functionReverse(final String sentence) { - // String res = ""; - - // String s1=sentence; - String[] words = sentence.split(SPACE_DELIMITER); - // int cont=0; - // StringBuilder str=new StringBuilder(); - for (int i = 0; i < words.length; i++) { - //str.append(words[i]); - // str=new StringBuilder(words[i]); - if (words[i].length() >= LIMIT) { - words[i] = new StringBuilder(words[i]).reverse().toString(); - // words[i]=""+str.reverse(); - - - } - } - return String.join(" ", words); - //return res=mostrar(words); - - } - - -} diff --git a/src/main/java/org/fundacionjala/coding/norman/average/Average.java b/src/main/java/org/fundacionjala/coding/norman/average/Average.java new file mode 100644 index 0000000..7de332f --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/average/Average.java @@ -0,0 +1,30 @@ +package org.fundacionjala.coding.norman.average; + +import java.util.stream.IntStream; + +/** + * Created by NORMAN on 2/7/2017. + */ +public final class Average { + /** + * Contructor. + */ + private Average() { + + } + + /** + * average to array. + * + * @param numbers array. + * @return array. + */ + + public static double[] averages(final int[] numbers) { + return (numbers == null || numbers.length <= 1) + ? new double[]{} + : IntStream.range(0, numbers.length - 1) + .mapToDouble(i -> (numbers[i] + numbers[i + 1]) / 2.0) + .toArray(); + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/banck_ocr/Digit.java b/src/main/java/org/fundacionjala/coding/norman/banck_ocr/Digit.java new file mode 100644 index 0000000..c0b8909 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/banck_ocr/Digit.java @@ -0,0 +1,8 @@ +package org.fundacionjala.coding.norman.banck_ocr; + +/** + * Created by NORMAN on 2/7/2017. + */ +public enum Digit { + CERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE +} diff --git a/src/main/java/org/fundacionjala/coding/norman/banck_ocr/FileNumberBankOcr.java b/src/main/java/org/fundacionjala/coding/norman/banck_ocr/FileNumberBankOcr.java new file mode 100644 index 0000000..5348f1b --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/banck_ocr/FileNumberBankOcr.java @@ -0,0 +1,84 @@ +package org.fundacionjala.coding.norman.banck_ocr; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class FileNumberBankOcr { + private Map numberMap; + + /** + * constructor. + */ + FileNumberBankOcr() { + numberMap = new HashMap(); + fillNumber(); + + } + + /** + * method fill number digite. + */ + public void fillNumber() { + numberMap.put(Digit.CERO.ordinal(), + " _ " + + "| |" + + "|_|"); + numberMap.put(Digit.ONE.ordinal(), + " |" + + " |" + + " |"); + numberMap.put(Digit.TWO.ordinal(), + " _ " + + " _|" + + "|_ "); + numberMap.put(Digit.THREE.ordinal(), + "__ " + + " _|" + + "__|"); + numberMap.put(Digit.FOUR.ordinal(), + " " + + "|_|" + + " |"); + numberMap.put(Digit.FIVE.ordinal(), + " __" + + "|__" + + " __|"); + numberMap.put(Digit.SIX.ordinal(), + " __" + + "|__" + + "|__|"); + numberMap.put(Digit.SEVEN.ordinal(), + "__ " + + " |" + + " |"); + numberMap.put(Digit.EIGHT.ordinal(), + " _ " + + "|_|" + + "|_|"); + numberMap.put(Digit.NINE.ordinal(), + " _ " + + "|_|" + + " _|"); + } + + /** + * @param lineNumber this is string parameter. + * @return String. + */ + public String comparation(final String lineNumber) { + Iterator> it = numberMap.entrySet().iterator(); + String resulValue = "?"; + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().toString().equalsIgnoreCase(lineNumber)) { + resulValue = entry.getKey().toString(); + } + } + + return resulValue; + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/banck_ocr/HistoryOneBankOcr.java b/src/main/java/org/fundacionjala/coding/norman/banck_ocr/HistoryOneBankOcr.java new file mode 100644 index 0000000..efc7a3c --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/banck_ocr/HistoryOneBankOcr.java @@ -0,0 +1,29 @@ +package org.fundacionjala.coding.norman.banck_ocr; + +import java.util.List; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class HistoryOneBankOcr extends FileNumberBankOcr { + /** + * This is my constructor BankOCR. + */ + public HistoryOneBankOcr() { + super(); + + } + + /** + * @param lines this is mi data insert lines. + * @return String return string in format digit. + * change y + */ + public String verificationLineNumber(final List lines) { + StringBuilder resulta = new StringBuilder(); + for (String line : lines) { + resulta.append(super.comparation(line)); + } + return resulta.toString(); + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/banck_ocr/HistoryThreeErrFall.java b/src/main/java/org/fundacionjala/coding/norman/banck_ocr/HistoryThreeErrFall.java new file mode 100644 index 0000000..e627e81 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/banck_ocr/HistoryThreeErrFall.java @@ -0,0 +1,23 @@ +package org.fundacionjala.coding.norman.banck_ocr; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class HistoryThreeErrFall extends HistoryTwoChecksum { + + /** + * this is my constructor 12/03/2017. + */ + public HistoryThreeErrFall() { + super(); + } + + /** + * @param dateNamber parameter. + * @return ResultErrIll. + * this is my constructor 12/03/2017. + */ + public String verificateNumber(final String dateNamber) { + return (dateNamber.matches("(.*)[?](.*)") ? "ILL" : (checkSumAcount(dateNamber) != 0) ? "ERR" : "OK"); + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/banck_ocr/HistoryTwoChecksum.java b/src/main/java/org/fundacionjala/coding/norman/banck_ocr/HistoryTwoChecksum.java new file mode 100644 index 0000000..ce10091 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/banck_ocr/HistoryTwoChecksum.java @@ -0,0 +1,34 @@ +package org.fundacionjala.coding.norman.banck_ocr; + +import java.util.Arrays; +import java.util.List; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class HistoryTwoChecksum extends FileNumberBankOcr { + + private int multiplyByNine = 9; + private static final int MODULUS_FACTOR = 11; + + /** + * HistoryTwoChecksum. + */ + public HistoryTwoChecksum() { + super(); + } + + /** + * @param accountNumber parameter. + * @return int. + */ + public int checkSumAcount(final String accountNumber) { + List listaCadena = Arrays.asList(accountNumber.split("")); + int suma = 0; + for (String dato : listaCadena) { + suma += Integer.parseInt(dato) * multiplyByNine--; + } + return suma % MODULUS_FACTOR; + + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/eanvalidator/EANValidator.java b/src/main/java/org/fundacionjala/coding/norman/eanvalidator/EANValidator.java new file mode 100644 index 0000000..55d585d --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/eanvalidator/EANValidator.java @@ -0,0 +1,40 @@ +package org.fundacionjala.coding.norman.eanvalidator; + +/** + * Created by NORMAN on 2/7/2017. + */ +public final class EANValidator { + private static final int ODD_DIGIT_MULTIPLIER = 3; + private static final int DIVISIBILITY_FACTOR = 10; + + /** + * Constructor private. + */ + + private EANValidator() { + } + + /** + * Takes an string number to verify it is checksum it's correct. + * + * @param eAN String number with exactly 13 digits. + * @return true if the checksum is ok. + */ + + static boolean validate(final String eAN) { + int sum = 0; + + + for (int i = 1; i < eAN.length(); i++) { + int numericValue = Character.getNumericValue(eAN.charAt(i - 1)); + sum += i % 2 == 0 ? numericValue * ODD_DIGIT_MULTIPLIER : numericValue; + } + + int module = sum % DIVISIBILITY_FACTOR; + int check = module != 0 ? DIVISIBILITY_FACTOR - module : 0; + + return check == Character.getNumericValue(eAN.charAt(eAN.length() - 1)); + + } + +} diff --git a/src/main/java/org/fundacionjala/coding/norman/evaporator/Evaporator.java b/src/main/java/org/fundacionjala/coding/norman/evaporator/Evaporator.java new file mode 100644 index 0000000..3b8cd30 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/evaporator/Evaporator.java @@ -0,0 +1,34 @@ +package org.fundacionjala.coding.norman.evaporator; + +/** + * Created by NORMAN on 2/7/2017. + */ +public final class Evaporator { + + private static final int INT = 100; + + /** + * Contructor. + */ + private Evaporator() { + + } + + /** + * method calculate time in days when evaporate the liquid. + * + * @param cant cant of liquid. + * @param porcentaje porcentage evaporation. + * @param umbral limit the evaporation in porcentage. + * @return cant days. + */ + public static int evaporator(final double cant, final double porcentaje, final double umbral) { + int res = 0; + double aux = INT; + while (aux > umbral) { + aux -= porcentaje * aux / INT; + res++; + } + return res; + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/exam/Kata.java b/src/main/java/org/fundacionjala/coding/norman/exam/Kata.java deleted file mode 100644 index 2b34bb2..0000000 --- a/src/main/java/org/fundacionjala/coding/norman/exam/Kata.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.fundacionjala.coding.norman.exam; - -/** - * Created by Norman on 3/23/2017. - */ - -public final class Kata { - /** - * constructor private. - */ - private Kata() { - } - - /** - * average. - * - * @return double[] of list. - * @param input list. - */ - public static double[] averages(final int[] input) { - double[] res; - if (input != null && input.length != 0 && input.length != 1) { - res = new double[input.length - 1]; - // } - //if(input.length!=0&&input.length!=1&&input!=null){ - - for (int i = 0; i < input.length - 1; i++) { - int contAux = i + 1; - // int indice=i; - res[i] = ((double) input[i] + (double) input[contAux]) / 2; - } - } else { - return new double[0]; - } - //} - - return res; - } -} diff --git a/src/main/java/org/fundacionjala/coding/norman/highestandlowest/HighestAndLowest.java b/src/main/java/org/fundacionjala/coding/norman/highestandlowest/HighestAndLowest.java new file mode 100644 index 0000000..2c1c4a0 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/highestandlowest/HighestAndLowest.java @@ -0,0 +1,30 @@ +package org.fundacionjala.coding.norman.highestandlowest; + +import java.util.Arrays; +import java.util.stream.Stream; + +/** + * Created by NORMAN on 2/7/2017. + */ +public final class HighestAndLowest { + /** + * Private constructor. + */ + private HighestAndLowest() { + } + + /** + * The method return the highest and lowest value of a number array. + * + * @param numbers is the String of numbers. + * @return a String with the highest and lowest values. + */ + static String highAndLowest(final String numbers) { + + + int[] digits = Stream.of(numbers.split(" ")).mapToInt(Integer::parseInt).toArray(); + Arrays.sort(digits); + + return String.format("%d %d", digits[digits.length - 1], digits[0]); + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/kata1/Task1.java b/src/main/java/org/fundacionjala/coding/norman/kata1/Task1.java deleted file mode 100644 index efa6373..0000000 --- a/src/main/java/org/fundacionjala/coding/norman/kata1/Task1.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.fundacionjala.coding.norman.kata1; - -/** - * Norman. - * - */ -public final class Task1 { - /** - * Validate a given EAN-Code. Return true if the given EAN-Code is valid, otherwise false. - * You can assume the given code is syntactically valid, i.e. it only consists of numbers and it exactly - * has a length of 13 characters. - * Examples - * EANValidator.validate("4003301018398") // True - * EANValidator.validate("4003301018392") // False - */ - - - private static final int DIGIT_MULTIPLIER = 3; - private static final int DIVISIBILITY_FACTOR = 10; - - - /** - * Constructor private. - */ - - private Task1() { - } - - /** - * Takes an string number to verify it is checksum it's correct. - * - * @param eAN String number with exactly 13 digits. - * @return true if the checksum is ok. - */ - - public static boolean validate(final String eAN) { - int sum = 0; - - - for (int i = 1; i < eAN.length(); i++) { - int numericValue = Character.getNumericValue(eAN.charAt(i - 1)); - sum += i % 2 == 0 ? numericValue * DIGIT_MULTIPLIER : numericValue; - } - - int module = sum % DIVISIBILITY_FACTOR; - int check = module != 0 ? DIVISIBILITY_FACTOR - module : 0; - - return check == Character.getNumericValue(eAN.charAt(eAN.length() - 1)); - - } - - -} - - - diff --git a/src/main/java/org/fundacionjala/coding/norman/movie/Children.java b/src/main/java/org/fundacionjala/coding/norman/movie/Children.java deleted file mode 100644 index 7a5970f..0000000 --- a/src/main/java/org/fundacionjala/coding/norman/movie/Children.java +++ /dev/null @@ -1,37 +0,0 @@ - -/** - * Created by Norman on 3/21/2017. - */ -public class Children extends Movie { - private static final int LIMITNEWCHILD = 3; - private static final double PRICE = 1.5; - - /** - * contructor children. - * - * @param title the name - */ - public Children(final String title) { - super(title); - } - - @Override - public double calculateAmount(final int daysRented) { - // double amount = PRICE; - // if (daysRented > LIMITNEWCHILD) { - // amount += (daysRented - LIMITNEWCHILD) * PRICE; - // } - // return amount; - //sum += i % 2 == 0 ? numericValue * DIGIT_MULTIPLIER : numericValue; - return daysRented > LIMITNEWCHILD ? ((daysRented - LIMITNEWCHILD) * PRICE) + PRICE : PRICE; - } - - /** - * @param daysRented . - * return double of calculateFrequentRenterPoints. - */ - @Override - public int calculateFrequentRenterPoints(final int daysRented) { - return 1; - } -} diff --git a/src/main/java/org/fundacionjala/coding/norman/movie/Customer.java b/src/main/java/org/fundacionjala/coding/norman/movie/Customer.java deleted file mode 100644 index 16c4724..0000000 --- a/src/main/java/org/fundacionjala/coding/norman/movie/Customer.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.fundacionjala.coding.norman.movie; - -import java.util.ArrayList; -import java.util.List; - - -/** - * This is the class Customer of rental movie. - */ -public class Customer { - private String nameCustomer; - private List rentalsCustomer; - - /** - * @param nameCustomer String with words. - * Constructor. - */ - Customer(final String nameCustomer) { - this.nameCustomer = nameCustomer; - rentalsCustomer = new ArrayList<>(); - } - - /** - * @param rental String with words. - */ - public void addRental(final Rental rental) { - rentalsCustomer.add(rental); - } - - /** - * @return the nameCustomer string. - */ - public String getName() { - return this.nameCustomer; - } - - /** - * @return the string. - */ - public String generateDetail() { - StringBuffer result = new StringBuffer(); - result.append("Rental Record for " + getName() + "\n"); - for (Rental rental : rentalsCustomer) { - result.append("\t" + rental.getMovie().getTitle() + "\t"); - result.append(rental.calculateAmount() + "\n"); - } - result.append("Amount owed is " + calculateTotalAmount() + "\n"); - result.append("You earned " + calculateTotalFrequentRenterPoints() + " frequent renter points"); - return result.toString(); - } - /** - * @return double the TotalAmount. - */ - public double calculateTotalAmount() { -// double totalAmount = 0; -// for (Rental rental : rentalsCustomer) { -// totalAmount += rental.calculateAmount(); -// } -// return totalAmount; - return rentalsCustomer.stream() - .mapToDouble(Rental::calculateAmount) - .sum(); - } - /** - * @return int the Total of FrequentRenterPoints. - */ - public int calculateTotalFrequentRenterPoints() { -// int totalFrequentRenterPoints = 0; -// for (Rental rental : rentalsCustomer) { -// totalFrequentRenterPoints += rental.calculateFrequentRenterPoint(); -// } -// return totalFrequentRenterPoints; - return rentalsCustomer.stream() - .mapToInt(rental -> rental.calculateFrequentRenterPoint()) - .sum(); - } -} diff --git a/src/main/java/org/fundacionjala/coding/norman/movie/Movie.java b/src/main/java/org/fundacionjala/coding/norman/movie/Movie.java deleted file mode 100644 index dd1aed7..0000000 --- a/src/main/java/org/fundacionjala/coding/norman/movie/Movie.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.fundacionjala.coding.norman.movie; - -/** - * Created by Administrator on 3/21/2017. - */ -public abstract class Movie { - private String title; - - /** - * @param title of movie. - */ - public Movie(final String title) { - this.title = title; - } - /** - * @param daysRented int number. - * @return calculateAmount. - */ - public abstract double calculateAmount(int daysRented); - /** - * @param daysRented int days. - * @return calculateFrequentRenterPoint . - */ - public abstract int calculateFrequentRenterPoints(int daysRented); - /** - * - * @return getTitle. - */ - public String getTitle() { - return title; - } -} diff --git a/src/main/java/org/fundacionjala/coding/norman/movie/NewRelease.java b/src/main/java/org/fundacionjala/coding/norman/movie/NewRelease.java deleted file mode 100644 index af2bc35..0000000 --- a/src/main/java/org/fundacionjala/coding/norman/movie/NewRelease.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.fundacionjala.coding.norman.movie; - -/** - * Created by Administrator on 3/21/2017. - */ -public class NewRelease extends Movie { - - private static final int LIMITNEWCHILD = 3; - /** - * contructor NewRelease. - * @param title string title. - */ - public NewRelease(final String title) { - super(title); - } - /** - * @param daysRented . - * @return double of calculateAmount. - */ - @Override - public double calculateAmount(final int daysRented) { - return daysRented * LIMITNEWCHILD; - } - /** - * @return calculateFrequentRenterPoint int. - */ - @Override - public int calculateFrequentRenterPoints(final int daysRented) { - return daysRented > 1 ? 2 : 1; - } -} diff --git a/src/main/java/org/fundacionjala/coding/norman/movie/Regular.java b/src/main/java/org/fundacionjala/coding/norman/movie/Regular.java deleted file mode 100644 index 2461a9c..0000000 --- a/src/main/java/org/fundacionjala/coding/norman/movie/Regular.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.fundacionjala.coding.norman.movie; - -/** - * Created by Administrator on 3/21/2017. - */ -public class Regular extends Movie { - - private static final double PRICE = 1.5; - - private static final int LIMITREGULAR = 2; - - /** - * Constructor regular. - * - * @param title string title. - */ - public Regular(final String title) { - super(title); - } - - /** - * @param daysRented int days. - * @return double of calculateAmount. - */ - @Override - public double calculateAmount(final int daysRented) { - // double amount = LIMITREGULAR; - // if (daysRented > LIMITREGULAR) { - // amount += (daysRented - LIMITREGULAR) * PRICE; - // } - // return amount; - return daysRented > LIMITREGULAR ? ((daysRented - LIMITREGULAR) * PRICE) + LIMITREGULAR : LIMITREGULAR; - } - - /** - * @return calculateFrequentRenterPoint int. - */ - @Override - public int calculateFrequentRenterPoints(final int daysRented) { - return 1; - } -} diff --git a/src/main/java/org/fundacionjala/coding/norman/movies/Children.java b/src/main/java/org/fundacionjala/coding/norman/movies/Children.java new file mode 100644 index 0000000..36f31fa --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/movies/Children.java @@ -0,0 +1,32 @@ +package org.fundacionjala.coding.norman.movies; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class Children extends Movie { + private static final int LIMIT_DAYS_TO_RENT_CHILDREN_MOVIE = 3; + private static final double NO_RELEASE_MOVIE_FEE = 1.5; + + /** + * Children constructor. + * + * @param title of String type. + */ + Children(final String title) { + super(title); + } + + @Override + public double calculateAmount(final int daysRented) { + double amount = NO_RELEASE_MOVIE_FEE; + if (daysRented > LIMIT_DAYS_TO_RENT_CHILDREN_MOVIE) { + amount += (daysRented - LIMIT_DAYS_TO_RENT_CHILDREN_MOVIE) * NO_RELEASE_MOVIE_FEE; + } + return amount; + } + + @Override + public int calculateFrequentRenterPoints(final int daysRented) { + return 1; + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/movies/Customer.java b/src/main/java/org/fundacionjala/coding/norman/movies/Customer.java new file mode 100644 index 0000000..135fbd0 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/movies/Customer.java @@ -0,0 +1,79 @@ +package org.fundacionjala.coding.norman.movies; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by NORMAN on 2/7/2017. + */ + +class Customer { + private String nameCustomer; + private List rentalsCustomer; + + /** + * @param nameCustomer String with words. + * Constructor. + */ + Customer(final String nameCustomer) { + this.nameCustomer = nameCustomer; + rentalsCustomer = new ArrayList<>(); + } + + /** + * @param rental String with words. + */ + void addRental(final Rental rental) { + rentalsCustomer.add(rental); + } + + + /** + * @return the string. + */ + String generateDetail() { + StringBuilder result = new StringBuilder(); + result.append("Rental Record for ").append(getName()).append("\n"); + for (Rental rental : rentalsCustomer) { + result.append("\t").append(rental.getMovie().getTitle()).append("\t"); + result.append(rental.calculateAmount()).append("\n"); + } + result.append("Amount owed is ").append(calculateTotalAmount()).append("\n"); + result.append("You earned ").append(calculateTotalFrequentRenterPoints()).append(" frequent renter points"); + return result.toString(); + } + + /** + * This method calculates the total amount of the rented movies. + * + * @return the total amount. + */ + private double calculateTotalAmount() { + return rentalsCustomer.stream() + .mapToDouble(Rental::calculateAmount) + .sum(); + } + + /** + * This method calculates the total frequent points of rented movies. + * + * @return total frequent renter points. + */ + private int calculateTotalFrequentRenterPoints() { + return rentalsCustomer.stream() + .mapToInt(Rental::calculateFrequentRenterPoint) + .sum(); + } + /** + * @return the nameCustomer string. + */ + private String getName() { + return this.nameCustomer; + } + /** + * @return the rentalCustomer List. + */ + public List getRentalCustomer() { + return this.rentalsCustomer; + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/movies/Movie.java b/src/main/java/org/fundacionjala/coding/norman/movies/Movie.java new file mode 100644 index 0000000..8b90c59 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/movies/Movie.java @@ -0,0 +1,43 @@ +package org.fundacionjala.coding.norman.movies; + +/** + * Created by NORMAN on 2/7/2017. + */ +public abstract class Movie { + private String title; + + /** + * Movie constructor. + * + * @param title of String type. + */ + Movie(final String title) { + this.title = title; + } + + /** + * Abstract method to calculate the amount of a rented movie. + * + * @param daysRented of int type. + * @return the amount of a rented movie. + */ + public abstract double calculateAmount(int daysRented); + + /** + * Abstract method to calculate the frequent renter points + * of a rented movie. + * + * @param daysRented of int type. + * @return the frequent renter points. + */ + public abstract int calculateFrequentRenterPoints(int daysRented); + + /** + * This method returns the title of a movie. + * + * @return the title of the movie. + */ + String getTitle() { + return title; + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/movies/NewRelease.java b/src/main/java/org/fundacionjala/coding/norman/movies/NewRelease.java new file mode 100644 index 0000000..36b6c20 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/movies/NewRelease.java @@ -0,0 +1,41 @@ +package org.fundacionjala.coding.norman.movies; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class NewRelease extends Movie { + + private static final int LIMIT_DAYS_TO_RENT_NEW_RELEASE_MOVIE = 3; + + /** + * NewRelease constructor. + * + * @param title of type String. + */ + NewRelease(final String title) { + super(title); + } + + /** + * This method calculates the amount of a new release rented movie. + * + * @param daysRented of int type. + * @return the amount of a new release rented movie. + */ + @Override + public double calculateAmount(final int daysRented) { + return daysRented * LIMIT_DAYS_TO_RENT_NEW_RELEASE_MOVIE; + } + + /** + * This method calculates the frequent renter points + * of a new release rented movie. + * + * @param daysRented of int type. + * @return 1 or 2. + */ + @Override + public int calculateFrequentRenterPoints(final int daysRented) { + return daysRented > 1 ? 2 : 1; + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/movies/Regular.java b/src/main/java/org/fundacionjala/coding/norman/movies/Regular.java new file mode 100644 index 0000000..180f9e0 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/movies/Regular.java @@ -0,0 +1,34 @@ +package org.fundacionjala.coding.norman.movies; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class Regular extends Movie { + + private static final double NO_RELEASE_MOVIE_FEE = 1.5; + + private static final int LIMIT_DAYS_TO_RENT_REGULAR_MOVIE = 2; + + /** + * Regular constructor. + * + * @param title of String type. + */ + Regular(final String title) { + super(title); + } + + @Override + public double calculateAmount(final int daysRented) { + double amount = LIMIT_DAYS_TO_RENT_REGULAR_MOVIE; + if (daysRented > LIMIT_DAYS_TO_RENT_REGULAR_MOVIE) { + amount += (daysRented - LIMIT_DAYS_TO_RENT_REGULAR_MOVIE) * NO_RELEASE_MOVIE_FEE; + } + return amount; + } + + @Override + public int calculateFrequentRenterPoints(final int daysRented) { + return 1; + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/movie/Rental.java b/src/main/java/org/fundacionjala/coding/norman/movies/Rental.java similarity index 51% rename from src/main/java/org/fundacionjala/coding/norman/movie/Rental.java rename to src/main/java/org/fundacionjala/coding/norman/movies/Rental.java index 638b7f1..9271f79 100644 --- a/src/main/java/org/fundacionjala/coding/norman/movie/Rental.java +++ b/src/main/java/org/fundacionjala/coding/norman/movies/Rental.java @@ -1,14 +1,18 @@ -package org.fundacionjala.coding.norman.movie; +package org.fundacionjala.coding.norman.movies; + /** - * Created by reinaldo on 11/03/2017. + * Created by NORMAN on 2/7/2017. */ + class Rental { private Movie movie; private int daysRented; /** - * @param movie Movie. - * @param daysRented DaysRented. + * Rental movie's constructor. + * + * @param movie receives the movie. + * @param daysRented receives the movie's days rented. */ Rental(final Movie movie, final int daysRented) { this.movie = movie; @@ -16,31 +20,36 @@ class Rental { } /** - * @return the daysRented. + * Getter method to obtain days a movies was rented. + * + * @return movies days rented. */ public int getDaysRented() { return daysRented; } /** - * @return movie object. + * Getter method to obtain the movie information. + * + * @return the movie object. */ - public Movie getMovie() { - return this.movie; + Movie getMovie() { + return movie; } /** * @return price object. */ - public double calculateAmount() { + double calculateAmount() { return movie.calculateAmount(daysRented); } /** * @return calculateFrequentRenterPoint int. */ - public int calculateFrequentRenterPoint() { + int calculateFrequentRenterPoint() { return movie.calculateFrequentRenterPoints(daysRented); } -} + +} diff --git a/src/main/java/org/fundacionjala/coding/norman/multiples3and5/Multiply3and5.java b/src/main/java/org/fundacionjala/coding/norman/multiples3and5/Multiply3and5.java new file mode 100644 index 0000000..0dabf5e --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/multiples3and5/Multiply3and5.java @@ -0,0 +1,35 @@ +package org.fundacionjala.coding.norman.multiples3and5; + +/** + * Created by NORMAN on 2/7/2017. + */ +public final class Multiply3and5 { + + public static final int MULTIPLY_3 = 3; + public static final int MULTIPLY_5 = 5; + + /** + * Contrusctor. + */ + private Multiply3and5() { + + } + + /** + * method plus number multiply 3 and 5. + * + * @param number limit to calculate multiply. + * @return sum of multiply. + */ + public static int solution(final int number) { + + int res = 0; + for (int i = 1; i < number; i++) { + if (i % MULTIPLY_3 == 0 || i % MULTIPLY_5 == 0) { + res += i; + } + } + return res; + + } +} diff --git a/src/main/java/org/fundacionjala/coding/norman/spinwords/SpinWords.java b/src/main/java/org/fundacionjala/coding/norman/spinwords/SpinWords.java new file mode 100644 index 0000000..10313c2 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/spinwords/SpinWords.java @@ -0,0 +1,33 @@ +package org.fundacionjala.coding.norman.spinwords; + +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * Created by NORMAN on 2/7/2017. + */ +public final class SpinWords { + private static final int LIMIT = 5; + + private static final String SPACE_DELIMITER = " "; + + /** + * Constructor private. + */ + private SpinWords() { + } + + /** + * Takes in a string of one or more words, and returns the same string, + * but with all five or more letter words reversed. + * + * @param sentence String with words. + * @return the same string, but with all five or more letter words reversed. + */ + public static String spinWords(final String sentence) { + return Stream.of(sentence.split(SPACE_DELIMITER)) + .map(word -> word.length() >= LIMIT ? new StringBuilder(word).reverse().toString() : word) + .collect(Collectors.joining(SPACE_DELIMITER)); + } + +} diff --git a/src/test/java/org/fundacionjala/coding/norman/Kata2/CodingTask2Test.java b/src/test/java/org/fundacionjala/coding/norman/Kata2/CodingTask2Test.java deleted file mode 100644 index 7a05c65..0000000 --- a/src/test/java/org/fundacionjala/coding/norman/Kata2/CodingTask2Test.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.fundacionjala.coding.norman.Kata2; - -//import org.junit.jupiter.api.Test; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -// import org.junit.jupiter.api.Test; - - -/** - * Created by Administrator on 3/20/2017. - */ - -public class CodingTask2Test { - - - /** - * Test when testValidateReverse2Words. - */ - @Test - public void testValidateReverse2Words() { - // given: - final String stringReverse = "Hey fellow warriors"; - - // when: - final String actualResult = CodingTask2.functionReverse(stringReverse); - - // then: - final String expectedResult = "Hey wollef sroirraw"; - assertEquals(expectedResult, actualResult); - } - - /** - * Test when testValidateNoReverse. - */ - @Test - public void testValidateNoReverse() { - // given: - final String stringReverse = "This is a test"; - - // when: - final String actualResult = CodingTask2.functionReverse(stringReverse); - - // then: - assertEquals(stringReverse, actualResult); - } - - /** - * Test when testValidateReverse1WordInMidle. - */ - @Test - public void testValidateReverse1WordInMidle() { - // given: - final String stringReverse = "This is another test"; - - // when: - final String actualResult = CodingTask2.functionReverse(stringReverse); - - // then: - final String expectedResult = "This is rehtona test"; - assertEquals(expectedResult, actualResult); - } - - - //spinWords( "Hey fellow warriors" ) => returns "Hey wollef sroirraw" - //spinWords( "This is a test") => returns "This is a test" - //spinWords( "This is another test" )=> returns "This is rehtona test" - -} diff --git a/src/test/java/org/fundacionjala/coding/norman/average/AverageTest.java b/src/test/java/org/fundacionjala/coding/norman/average/AverageTest.java new file mode 100644 index 0000000..d8ecab8 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/norman/average/AverageTest.java @@ -0,0 +1,116 @@ +package org.fundacionjala.coding.norman.average; + +import org.junit.Test; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.Arrays; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertEquals; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class AverageTest { + + /** + * Constructor test. + * @throws Exception exception. + */ + @Test + public void testConstructorIsPrivate() throws Exception { + Constructor constructor = Average.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + /** + * The method verifies test1. + */ + @Test + public void test1() { + final int[] arrayNumbers = new int[]{2, 2, 2, 2, 2}; + + final double[] actualResult = Average.averages(arrayNumbers); + + final double[] expectedResult = new double[]{2, 2, 2, 2}; + + assertEquals(Arrays.toString(expectedResult), Arrays.toString(actualResult)); + } + + /** + * The method verifies test2. + */ + @Test + public void test2() { + final int[] arrayNumbers = new int[]{2, -2, 2, -2, 2}; + + final double[] actualResult = Average.averages(arrayNumbers); + + final double[] expectedResult = new double[]{0, 0, 0, 0}; + + assertEquals(Arrays.toString(expectedResult), Arrays.toString(actualResult)); + } + + + /** + * The method verifies test3. + */ + @Test + public void test3() { + + final int[] arrayNumbers = new int[]{1, 3, 5, 1, -10}; + + final double[] actualResult = Average.averages(arrayNumbers); + + final double[] expectedResult = new double[]{2, 4, 3, -4.5}; + + assertEquals(Arrays.toString(expectedResult), Arrays.toString(actualResult)); + } + + + /** + * The method verifies test4. + */ + @Test + public void test4() { + + final int[] arrayNumbers = new int[]{}; + + final double[] actualResult = Average.averages(arrayNumbers); + + final double[] expectedResult = new double[]{}; + + assertEquals(Arrays.toString(expectedResult), Arrays.toString(actualResult)); + } + + /** + * The method verifies test5. + */ + @Test + public void test5() { + + final int[] arrayNumbers = new int[]{1}; + + final double[] actualResult = Average.averages(arrayNumbers); + + final double[] expectedResult = new double[]{}; + + assertEquals(Arrays.toString(expectedResult), Arrays.toString(actualResult)); + } + + /** + * The method verifies test6. + */ + @Test + public void test6() { + final int[] arrayNumbers = null; + + final double[] actualResult = Average.averages(arrayNumbers); + + final double[] expectedResult = new double[]{}; + + assertEquals(Arrays.toString(expectedResult), Arrays.toString(actualResult)); + } +} diff --git a/src/test/java/org/fundacionjala/coding/norman/banck_ocr/BankOcrTest.java b/src/test/java/org/fundacionjala/coding/norman/banck_ocr/BankOcrTest.java new file mode 100644 index 0000000..45801eb --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/norman/banck_ocr/BankOcrTest.java @@ -0,0 +1,239 @@ +package org.fundacionjala.coding.norman.banck_ocr; + + +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class BankOcrTest { + /** + * Test if testBankOcrWhenScannedNumbersCero. + */ + @Test + public void testBankOcrWhenScannedNumbersCero() { + // given: + List insertLineFour = Arrays.asList( + " _ " + + "| |" + + "|_|" + ); + + // when: + HistoryOneBankOcr bankOcr = new HistoryOneBankOcr(); + String actualResult = bankOcr.verificationLineNumber(insertLineFour); + + // then: + String expectedResult = "0"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test if testBankOcrWhenScannedNumbersCeroToNine. + */ + @Test + public void testBankOcrWhenScannedNumbersCeroToNine() { + // given: + List insertLineFour = Arrays.asList( + " _ " + + "| |" + + "|_|", + + " |" + + " |" + + " |", + + " _ " + + " _|" + + "|_ ", + + "__ " + + " _|" + + "__|", + + " " + + "|_|" + + " |", + + " __" + + "|__" + + " __|", + + " __" + + "|__" + + "|__|", + + "__ " + + " |" + + " |", + + " _ " + + "|_|" + + "|_|", + + " _ " + + "|_|" + + " _|" + ); + + // when: + HistoryOneBankOcr bankOcr = new HistoryOneBankOcr(); + String actualResult = bankOcr.verificationLineNumber(insertLineFour); + + // then: + String expectedResult = "0123456789"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test if testBankOcrWhenScannedNumbersFiveIsErrorandEight. + */ + @Test + public void testBankOcrWhenScannedNumbersFiveIsErrorandEight() { + // given: + List insertLineFour = Arrays.asList( + " _ " + + "| |" + + "|_|", + + " |" + + " |" + + " |", + + " _ " + + " _|" + + "|_ ", + + "__ " + + " _|" + + "__|", + + " " + + "|_|" + + " |", + + ":>", + + " __" + + "|__" + + "|__|", + + "__ " + + " |" + + " |", + + "g", + + " _ " + + "|_|" + + " _|" + ); + + // when: + HistoryOneBankOcr bankOcr = new HistoryOneBankOcr(); + String actualResult = bankOcr.verificationLineNumber(insertLineFour); + + // then: + String expectedResult = "01234?67?9"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test if testBankOcrWhenScannedNumbersFiveIsOk. + */ + @Test + public void testHistoryThreTwoChecksumWentTheOK() { + // given: + final String sentence = "457508000"; + + // when: + final String expectedResult = "OK"; + HistoryThreeErrFall historyTwo = new HistoryThreeErrFall(); + String actualResult = historyTwo.verificateNumber(sentence); + + assertEquals(expectedResult, actualResult); + } + + /** + * Test if testHistoryThreeWhenIsErr. + */ + @Test + public void testHistoryThreeWhenIsErr() { + // given: + final String sentence = "664371495"; + + // when: + final String expectedResult = "ERR"; + HistoryThreeErrFall historyTwo = new HistoryThreeErrFall(); + String actualResult = historyTwo.verificateNumber(sentence); + + assertEquals(expectedResult, actualResult); + } + + /** + * Test if testHistoryThreeWhenIsIll. + */ + @Test + public void testHistoryThreeWhenIsILL() { + // given: + final String sentence = "664371?95"; + + // when: + final String expectedResult = "ILL"; + HistoryThreeErrFall historyTwo = new HistoryThreeErrFall(); + String actualResult = historyTwo.verificateNumber(sentence); + + assertEquals(expectedResult, actualResult); + } + + /** + * Test if testBankOcrWhenScannedNumbersFiveIsErrorandEight. + */ + @Test + public void testHistoryTwoChecksumWentTheChecksumIsCero() { + // given: + final String sentence = "457508000"; + + // when: + final int expectedResult = 0; + HistoryTwoChecksum historyTwo = new HistoryTwoChecksum(); + final int actualResult = historyTwo.checkSumAcount(sentence); + + assertEquals(expectedResult, actualResult); + } + + /** + * Test if testBankOcrWhenScannedNumbersFiveIsErrorandEight. + */ + @Test + public void testHistoryTwoChecksumWentTheChecksumIsnotCero() { + // given: + final String sentence = "664371495"; + + // when: + final int expectedResult = 0; + HistoryTwoChecksum historyTwo = new HistoryTwoChecksum(); + final int actualResult = historyTwo.checkSumAcount(sentence); + + assertTrue(expectedResult != actualResult); + } + + /** + * This verified the map. + */ + @Test + public void whenCompareToString() { + String line = " _ " + + "| |" + + "|_|"; + FileNumberBankOcr fileNumberBankOcr = new FileNumberBankOcr(); + String resulActual = fileNumberBankOcr.comparation(line); + assertEquals("0", resulActual); + } +} diff --git a/src/test/java/org/fundacionjala/coding/norman/eanvalidator/EANValidatorTest.java b/src/test/java/org/fundacionjala/coding/norman/eanvalidator/EANValidatorTest.java new file mode 100644 index 0000000..3124ca2 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/norman/eanvalidator/EANValidatorTest.java @@ -0,0 +1,101 @@ +package org.fundacionjala.coding.norman.eanvalidator; + +import org.junit.Test; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class EANValidatorTest { + /** + * Constructor test. + * @throws Exception exception. + */ + @Test + public void testConstructorIsPrivate() throws Exception { + Constructor constructor = EANValidator.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + /** + * Test when the EAN string number has exactly 13 digits. + */ + @Test + public void testCheckLengthWhenTheEANStringNumberHasExactly13Digits() { + // given: + final String eanStringNumber = "4003301018398"; + + // when: + final boolean actualResult = eanStringNumber.length() == 13; + + // then: + assertTrue(actualResult); + } + + /** + * Test when the EAN string number has less than 13 digits. + */ + @Test + public void testCheckLengthWhenTheEANStringNumberHasLessThan13Digits() { + // given: + final String eanStringNumber = "400330101839"; + + // when: + final boolean actualResult = eanStringNumber.length() < 13; + + // then: + assertTrue(actualResult); + } + + /** + * Test when the EAN string number has more than 13 digits. + */ + @Test + public void testCheckLengthTheEANStringNumberHasMoreThan13Digits() { + // given: + final String eanStringNumber = "40033010183980"; + + // when: + final boolean actualResult = eanStringNumber.length() > 13; + + // then: + assertTrue(actualResult); + } + + /** + * Test when the EAN string number checksum is different from 0. + */ + @Test + public void testValidateTheCheckSumIsDifferentFromZero() { + // given: + final String eanStringNumber = "4003301018398"; + + // when: + final boolean actualResult = EANValidator.validate(eanStringNumber); + + // then: + assertTrue(actualResult); + } + + /** + * Test when the EAN string number checksum is equal to 0. + */ + @Test + public void testValidateTheCheckSumIsEqualToZero() { + // given: + final String eanStringNumber = "4003301018392"; + + // when: + final boolean actualResult = EANValidator.validate(eanStringNumber); + + // then: + assertFalse(actualResult); + } + +} diff --git a/src/test/java/org/fundacionjala/coding/norman/evaporator/EvaporatorTest.java b/src/test/java/org/fundacionjala/coding/norman/evaporator/EvaporatorTest.java new file mode 100644 index 0000000..a62a043 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/norman/evaporator/EvaporatorTest.java @@ -0,0 +1,45 @@ +package org.fundacionjala.coding.norman.evaporator; + +import org.junit.Test; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertEquals; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class EvaporatorTest { + + /** + * Constructor test. + * @throws Exception exception. + */ + @Test + public void testConstructorIsPrivate() throws Exception { + Constructor constructor = Evaporator.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + + /** + * Test to work correctly. + */ + @Test + public void testEvaporatorOne() { + assertEquals(22, Evaporator.evaporator(10, 10, 10)); + assertEquals(29, Evaporator.evaporator(10, 10, 5)); + assertEquals(59, Evaporator.evaporator(100, 5, 5)); + assertEquals(37, Evaporator.evaporator(50, 12, 1)); + assertEquals(31, Evaporator.evaporator(47.5, 8, 8)); + assertEquals(459, Evaporator.evaporator(100, 1, 1)); + assertEquals(459, Evaporator.evaporator(10, 1, 1)); + assertEquals(299, Evaporator.evaporator(100, 1, 5)); + + } + + +} diff --git a/src/test/java/org/fundacionjala/coding/norman/highestandlowest/HighestAndLowestTest.java b/src/test/java/org/fundacionjala/coding/norman/highestandlowest/HighestAndLowestTest.java new file mode 100644 index 0000000..fd22beb --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/norman/highestandlowest/HighestAndLowestTest.java @@ -0,0 +1,183 @@ +package org.fundacionjala.coding.norman.highestandlowest; + +import org.junit.Test; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertEquals; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class HighestAndLowestTest { + + /** + * Constructor test. + * @throws Exception exception. + */ + @Test + public void testConstructorIsPrivate() throws Exception { + Constructor constructor = HighestAndLowest.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + /** + * The method verifies test1. + */ + @Test + public void test1() { + final String numbers = "1 2 3 4 5"; + + final String actualResult = HighestAndLowest.highAndLowest(numbers); + + final String expectedResult = "5 1"; + + assertEquals(expectedResult, actualResult); + } + + /** + * The method verifies test2. + */ + @Test + public void test2() { + final String numbers = "1 2 -3 4 5"; + + final String actualResult = HighestAndLowest.highAndLowest(numbers); + + final String expectedResult = "5 -3"; + + assertEquals(expectedResult, actualResult); + } + + + /** + * The method verifies test3. + */ + @Test + public void test3() { + final String numbers = "1 9 3 4 -5"; + + final String actualResult = HighestAndLowest.highAndLowest(numbers); + + final String expectedResult = "9 -5"; + + assertEquals(expectedResult, actualResult); + } + + /** + * The method verifies test4. + */ + @Test + public void test4() { + final String numbers = "4 5 29 54 4 0 -214 542 -64 1 -3 6 -6"; + + final String actualResult = HighestAndLowest.highAndLowest(numbers); + + final String expectedResult = "542 -214"; + + assertEquals(expectedResult, actualResult); + } + + /** + * The method verifies test5. + */ + @Test + public void test5() { + final String numbers = "1 -1"; + + final String actualResult = HighestAndLowest.highAndLowest(numbers); + + final String expectedResult = "1 -1"; + + assertEquals(expectedResult, actualResult); + } + + /** + * The method verifies test6. + */ + @Test + public void test6() { + final String numbers = "1 1"; + + final String actualResult = HighestAndLowest.highAndLowest(numbers); + + final String expectedResult = "1 1"; + + assertEquals(expectedResult, actualResult); + } + + /** + * The method verifies test7. + */ + @Test + public void test7() { + final String numbers = "-1 -1"; + + final String actualResult = HighestAndLowest.highAndLowest(numbers); + + final String expectedResult = "-1 -1"; + + assertEquals(expectedResult, actualResult); + } + + /** + * The method verifies test8. + */ + @Test + public void test8() { + final String numbers = "1 -1 0"; + + final String actualResult = HighestAndLowest.highAndLowest(numbers); + + final String expectedResult = "1 -1"; + + assertEquals(expectedResult, actualResult); + } + + /** + * The method verifies test9. + */ + @Test + public void test9() { + final String numbers = "1 1 0"; + + final String actualResult = HighestAndLowest.highAndLowest(numbers); + + final String expectedResult = "1 0"; + + assertEquals(expectedResult, actualResult); + } + + /** + * The method verifies test10. + */ + @Test + public void test10() { + final String numbers = "-1 -1 0"; + + final String actualResult = HighestAndLowest.highAndLowest(numbers); + + final String expectedResult = "0 -1"; + + assertEquals(expectedResult, actualResult); + } + + /** + * The method verifies test11. + */ + @Test + public void test11() { + final String numbers = "42"; + + final String actualResult = HighestAndLowest.highAndLowest(numbers); + + final String expectedResult = "42 42"; + + assertEquals(expectedResult, actualResult); + } + + +} diff --git a/src/test/java/org/fundacionjala/coding/norman/kata1/Task1Test.java b/src/test/java/org/fundacionjala/coding/norman/kata1/Task1Test.java deleted file mode 100644 index 0b9f869..0000000 --- a/src/test/java/org/fundacionjala/coding/norman/kata1/Task1Test.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.fundacionjala.coding.norman.kata1; - - -import org.junit.Test; - -import static org.junit.Assert.assertTrue; -/** - * Test kata2. - */ -public class Task1Test { - - /** - * Test when the EAN string number checksum is different from 0. - */ - @Test - public void testValidateTheCheckSumIsDifferentFromZero() { - // given: - final String eanStringNumber = "4003301018398"; - - // when: - final boolean actualResult = Task1.validate(eanStringNumber); - - // then: - assertTrue(actualResult); - } - - /** - * Test when the EAN string number checksum is equal to 0. - */ - @Test - public void testValidateTheCheckSumIsEqualToZero() { - // given: - final String eanStringNumber = "4003301018392"; - - // when: - final boolean actualResult = Task1.validate(eanStringNumber); - - // then: - assertTrue(!actualResult); - } - } - - diff --git a/src/test/java/org/fundacionjala/coding/norman/movies/ChildrenTest.java b/src/test/java/org/fundacionjala/coding/norman/movies/ChildrenTest.java new file mode 100644 index 0000000..3807c36 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/norman/movies/ChildrenTest.java @@ -0,0 +1,106 @@ +package org.fundacionjala.coding.norman.movies; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class ChildrenTest { + /** + * Test to verify the amount if the rented days + * for a Children movie is less than 3 e.g. 1 + */ + private Movie childrenInstance; + + /** + * create children movie. + */ + @Before + public void before() { + childrenInstance = new Children("Test"); + } + + /** + * test days is less 13. + */ + @Test + public void testCalculateAmountWhenTheRentedDaysIsLessThanThree() { + // given: + + // when: + final double actualResult = childrenInstance.calculateAmount(1); + + // then + final double expectedResult = 1.5; + assertEquals(0, expectedResult, actualResult); + } + + /** + * Test to verify the amount if the rented days + * for a Children movie is greater than 3 e.g. 10 + */ + @Test + public void testCalculateAmountWhenTheRentedDaysIsGreaterThanThree() { + // given: + + // when: + final double actualResult = childrenInstance.calculateAmount(10); + + // then: + final double expectedResult = 10.5; + assertEquals(0, expectedResult, actualResult); + } + + /** + * Test to verify the frequent renter points for a Children movie + * is 1 for different rented days. + */ + @Test + public void testCalculateFrequentRenterPointsVerifyTheResultIsOne() { + // given: + + // when: + final int actualResultOne = childrenInstance.calculateFrequentRenterPoints(1); + + // then: + final int expectedResultOne = 1; + assertEquals(expectedResultOne, actualResultOne); + + // given: childrenInstance + + // when: + final int actualResultTwo = childrenInstance.calculateFrequentRenterPoints(3); + + // then: + final int expectedResultTwo = 1; + assertEquals(expectedResultTwo, actualResultTwo); + + // give: childrenInstance + + // when: + final int actualResultThree = childrenInstance.calculateFrequentRenterPoints(1000); + + // then: + final int expectedResultThree = 1; + assertEquals(actualResultThree, expectedResultThree); + } + + /** + * test getRental. + */ + @Test + public void getRental() { + + + Movie movie = new Children("Rental"); + + Rental movieRental = new Rental(movie, 12); + int resultExpected = movieRental.getDaysRented(); + + assertEquals(12, resultExpected); + + } +} diff --git a/src/test/java/org/fundacionjala/coding/norman/movies/CustomerTest.java b/src/test/java/org/fundacionjala/coding/norman/movies/CustomerTest.java new file mode 100644 index 0000000..9e572b6 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/norman/movies/CustomerTest.java @@ -0,0 +1,46 @@ +package org.fundacionjala.coding.norman.movies; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + + +/** + * Created by NORMAN on 2/7/2017. + */ +public class CustomerTest { + /** + * aAdd movie to list. + */ + @Test + public void addRental() { + Customer customer = new Customer("pepe"); + Children children = new Children("ddd"); + Rental rental = new Rental(children, 2); + + customer.addRental(rental); + + assertTrue(customer.getRentalCustomer().size() > 0); + + } + + /** + * Create String of movies rented. + */ + + @Test + public void generateDetail() { + Customer customer = new Customer("pepe"); + Children children = new Children("chuqui"); + Rental rental = new Rental(children, 2); + + customer.addRental(rental); + String espectedResult = customer.generateDetail(); + System.out.println(espectedResult); + assertEquals("Rental Record for pepe\n" + "\tchuqui\t1.5\n" + + "Amount owed is 1.5\n" + "You earned 1 frequent renter points", espectedResult); + + } + +} diff --git a/src/test/java/org/fundacionjala/coding/norman/movies/NewReleaseTest.java b/src/test/java/org/fundacionjala/coding/norman/movies/NewReleaseTest.java new file mode 100644 index 0000000..0cd0807 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/norman/movies/NewReleaseTest.java @@ -0,0 +1,80 @@ +package org.fundacionjala.coding.norman.movies; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class NewReleaseTest { + + /** + * Test to verify the amount if the rented days + * for a NewRelease movie is less than 3 e.g. 1 + */ + @Test + public void testCalculateAmountWhenTheRentedDaysIsLessThanThree() { + // given: + NewRelease newReleaseInstance = new NewRelease("Test"); + + // when: + final double actualResult = newReleaseInstance.calculateAmount(1); + + // then + final double expectedResult = 3; + assertEquals(0, expectedResult, actualResult); + } + + /** + * Test to verify the amount if the rented days + * for a NewRelease movie is greater than 3 e.g. 10 + */ + @Test + public void testCalculateAmountWhenTheRentedDaysIsGreaterThanThree() { + // given: + NewRelease newReleaseInstance = new NewRelease("Test"); + + // when: + final double actualResult = newReleaseInstance.calculateAmount(10); + + // then: + final double expectedResult = 30; + assertEquals(0, expectedResult, actualResult); + } + + /** + * Test to verify the frequent renter points for a NewRelease movie + * is 1 for different rented days. + */ + @Test + public void testCalculateFrequentRenterPointsVerifyTheResultIsOne() { + // given: + NewRelease newReleaseInstance = new NewRelease("Test"); + + // when: + final int actualResultOne = newReleaseInstance.calculateFrequentRenterPoints(1); + + // then: + final int expectedResultOne = 1; + assertEquals(expectedResultOne, actualResultOne); + + // given: newReleaseInstance + + // when: + final int actualResultTwo = newReleaseInstance.calculateFrequentRenterPoints(3); + + // then: + final int expectedResultTwo = 2; + assertEquals(expectedResultTwo, actualResultTwo); + + // give: newReleaseInstance + + // when: + final int actualResultThree = newReleaseInstance.calculateFrequentRenterPoints(1000); + + // then: + final int expectedResultThree = 2; + assertEquals(actualResultThree, expectedResultThree); + } +} diff --git a/src/test/java/org/fundacionjala/coding/norman/movies/RegularTest.java b/src/test/java/org/fundacionjala/coding/norman/movies/RegularTest.java new file mode 100644 index 0000000..07e8322 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/norman/movies/RegularTest.java @@ -0,0 +1,80 @@ +package org.fundacionjala.coding.norman.movies; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class RegularTest { + + /** + * Test to verify the amount if the rented days + * for a Regular movie is less than 2 e.g. 1 + */ + @Test + public void testCalculateAmountWhenTheRentedDaysIsLessThanThree() { + // given: + Regular regularInstance = new Regular("Test"); + + // when: + final double actualResult = regularInstance.calculateAmount(1); + + // then + final double expectedResult = 2; + assertEquals(0, expectedResult, actualResult); + } + + /** + * Test to verify the amount if the rented days + * for a Regular movie is greater than 2 e.g. 10 + */ + @Test + public void testCalculateAmountWhenTheRentedDaysIsGreaterThanThree() { + // given: + Regular regularInstance = new Regular("Test"); + + // when: + final double actualResult = regularInstance.calculateAmount(10); + + // then: + final double expectedResult = 14; + assertEquals(0, expectedResult, actualResult); + } + + /** + * Test to verify the frequent renter points for a Regular movie + * is 1 for different rented days. + */ + @Test + public void testCalculateFrequentRenterPointsVerifyTheResultIsOne() { + // given: + Regular regularInstance = new Regular("Test"); + + // when: + final int actualResultOne = regularInstance.calculateFrequentRenterPoints(1); + + // then: + final int expectedResultOne = 1; + assertEquals(expectedResultOne, actualResultOne); + + // given: regularInstance + + // when: + final int actualResultTwo = regularInstance.calculateFrequentRenterPoints(3); + + // then: + final int expectedResultTwo = 1; + assertEquals(expectedResultTwo, actualResultTwo); + + // give: regularInstance + + // when: + final int actualResultThree = regularInstance.calculateFrequentRenterPoints(1000); + + // then: + final int expectedResultThree = 1; + assertEquals(actualResultThree, expectedResultThree); + } +} diff --git a/src/test/java/org/fundacionjala/coding/norman/multiples3and5/Multiply3and5Test.java b/src/test/java/org/fundacionjala/coding/norman/multiples3and5/Multiply3and5Test.java new file mode 100644 index 0000000..edb7903 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/norman/multiples3and5/Multiply3and5Test.java @@ -0,0 +1,37 @@ +package org.fundacionjala.coding.norman.multiples3and5; + +import org.junit.Test; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertEquals; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class Multiply3and5Test { + + /** + * Constructor test. + * @throws Exception exception. + */ + @Test + public void testConstructorIsPrivate() throws Exception { + Constructor constructor = Multiply3and5.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + /** + * Test of multiply 3 and 5. + */ + @Test + public void test() { + assertEquals(23, Multiply3and5.solution(10)); + assertEquals(78, Multiply3and5.solution(20)); + assertEquals(9168, Multiply3and5.solution(200)); + } + +} diff --git a/src/test/java/org/fundacionjala/coding/norman/spinwords/SpinWordsTest.java b/src/test/java/org/fundacionjala/coding/norman/spinwords/SpinWordsTest.java new file mode 100644 index 0000000..7964b25 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/norman/spinwords/SpinWordsTest.java @@ -0,0 +1,93 @@ +package org.fundacionjala.coding.norman.spinwords; + +import org.junit.Test; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertEquals; + +/** + * Created by NORMAN on 2/7/2017. + */ +public class SpinWordsTest { + + /** + * Constructor test. + * @throws Exception exception. + */ + + @Test + public void testConstructorIsPrivate() throws Exception { + Constructor constructor = SpinWords.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + /** + * Test when sentence has words with more than 5 characters. + */ + @Test + public void testSpinWordsWhenSentenceHasWordsWithMoreThanFiveCharacters() { + // given: + final String sentence = "Hey fellow warriors"; + + // when: + final String actualResult = SpinWords.spinWords(sentence); + + // then: + final String expectedResult = "Hey wollef sroirraw"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test when sentence doesn't have words with more than 5 characters. + */ + @Test + public void testSpinWordsWhenSentenceDoesNotHaveWordsWithMoreThanFiveCharacters() { + // given: + final String sentence = "This is a test"; + + // when: + final String actualResult = SpinWords.spinWords(sentence); + + // then: + final String expectedResult = "This is a test"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test when sentence has words with 5 characters. + */ + @Test + public void testSpinWordsWhenSentenceHasWordsWithFiveCharacters() { + // given: + final String sentence = "This is a table"; + + // when: + final String actualResult = SpinWords.spinWords(sentence); + + // then: + final String expectedResult = "This is a elbat"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test when sentence has one just word. + */ + @Test + public void testSpinWordsWhenSentenceHasOneWord() { + // given: + final String sentence = "Welcome"; + + // when: + final String actualResult = SpinWords.spinWords(sentence); + + // then: + final String expectedResult = "emocleW"; + assertEquals(expectedResult, actualResult); + } + + +} From 80f5d9bd92104dddf78b3f0d031d5c47e9bf7661 Mon Sep 17 00:00:00 2001 From: 666nonak666 Date: Sat, 8 Jul 2017 15:31:56 +0000 Subject: [PATCH 8/8] test release --- .../coding/norman/movies/NewReleaseTest.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/fundacionjala/coding/norman/movies/NewReleaseTest.java b/src/test/java/org/fundacionjala/coding/norman/movies/NewReleaseTest.java index 0cd0807..0aa25f9 100644 --- a/src/test/java/org/fundacionjala/coding/norman/movies/NewReleaseTest.java +++ b/src/test/java/org/fundacionjala/coding/norman/movies/NewReleaseTest.java @@ -1,13 +1,25 @@ package org.fundacionjala.coding.norman.movies; +import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * Created by NORMAN on 2/7/2017. */ public class NewReleaseTest { + private Movie newReleaseInstance; + + /** + * create NewRelease movie. + */ + @Before + public void before() { + newReleaseInstance = new NewRelease("Test"); + } + /** * Test to verify the amount if the rented days @@ -16,14 +28,14 @@ public class NewReleaseTest { @Test public void testCalculateAmountWhenTheRentedDaysIsLessThanThree() { // given: - NewRelease newReleaseInstance = new NewRelease("Test"); // when: final double actualResult = newReleaseInstance.calculateAmount(1); // then final double expectedResult = 3; - assertEquals(0, expectedResult, actualResult); + assertTrue(expectedResult - actualResult == 0); + } /** @@ -33,14 +45,13 @@ public void testCalculateAmountWhenTheRentedDaysIsLessThanThree() { @Test public void testCalculateAmountWhenTheRentedDaysIsGreaterThanThree() { // given: - NewRelease newReleaseInstance = new NewRelease("Test"); // when: final double actualResult = newReleaseInstance.calculateAmount(10); // then: final double expectedResult = 30; - assertEquals(0, expectedResult, actualResult); + assertTrue(expectedResult - actualResult == 0); } /** @@ -50,7 +61,6 @@ public void testCalculateAmountWhenTheRentedDaysIsGreaterThanThree() { @Test public void testCalculateFrequentRenterPointsVerifyTheResultIsOne() { // given: - NewRelease newReleaseInstance = new NewRelease("Test"); // when: final int actualResultOne = newReleaseInstance.calculateFrequentRenterPoints(1);