diff --git a/src/main/java/org/fundacionjala/coding/Fernando/StringInv/StringInv.java b/src/main/java/org/fundacionjala/coding/Fernando/StringInv/StringInv.java new file mode 100644 index 0000000..e857b1b --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/Fernando/StringInv/StringInv.java @@ -0,0 +1,36 @@ +package org.fundacionjala.coding.Fernando.StringInv; + +/** + * Write a description of class StringInv here. + * + * @author (your name) + * @version (a version number or a date) + */ +public final class StringInv { + + static final int MAJOR_FIVE_LETTERS = 5; + + /** + * Constructor StringInv. + */ + private StringInv() { + } + + /** + * @param text param. + * @return String param. + */ + public static String stringInv(final String text) { + int pos = 0; + String[] parts = text.split(" "); + while (pos < parts.length) { + if (parts[pos].length() > MAJOR_FIVE_LETTERS) { + parts[pos] = new StringBuilder(parts[pos]).reverse().toString(); + } + pos++; + } + return String.join(" ", parts); + + } + +} diff --git a/src/main/java/org/fundacionjala/coding/Fernando/average/Average.java b/src/main/java/org/fundacionjala/coding/Fernando/average/Average.java new file mode 100644 index 0000000..3526fb8 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/Fernando/average/Average.java @@ -0,0 +1,43 @@ +package org.fundacionjala.coding.Fernando.average; + +/** + * Write a description of class Average here. + * + * @author (your name) + * @version (a version number or a date) + */ +public final class Average { + + /** + * Constructor Average. + */ + private Average() { + } + + /** + * @param num the method has a int value. + * @return double value. + */ + public static double[] average(final int[] num) { + double[] res = {}; + if (num != null && num.length != 0) { + return average(num, 0); + } + return res; + } + + /** + * @param num the method has a int value. + * @param pos1 param. + * @return double value. + */ + private static double[] average(final int[] num, final int pos1) { + double[] res = new double[num.length - 1]; + for (int pos = 0; pos < num.length - 1; pos++) { + double prom = (double) (num[pos] + num[pos + 1]) / 2; + res[pos] = prom; + } + return res; + + } +} diff --git a/src/main/java/org/fundacionjala/coding/Fernando/bankOCR/BankOCR.java b/src/main/java/org/fundacionjala/coding/Fernando/bankOCR/BankOCR.java new file mode 100644 index 0000000..1acee84 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/Fernando/bankOCR/BankOCR.java @@ -0,0 +1,142 @@ +package org.fundacionjala.coding.Fernando.bankOCR; + +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +/** + * Created by PC on 24/06/2017. + */ +public final class BankOCR { + + private static final int ZERO = 0; + private static final int ONE = 1; + private static final int TWO = 2; + private static final int THREE = 3; + private static final int FOUR = 4; + private static final int FIVE = 5; + private static final int SIX = 6; + private static final int SEVEN = 7; + private static final int EIGHT = 8; + private static final int NINE = 9; + private static final Map MAP = new HashMap<>(); + static final int VALIDATOR = 11; + + static { + MAP.put(ZERO, + " _ " + + "| |" + + "|_|"); + MAP.put(ONE, + " " + + " |" + + " |"); + MAP.put(TWO, + " _ " + + " _|" + + "|_ "); + MAP.put(THREE, + "__ " + + " _|" + + "__|"); + MAP.put(FOUR, + " " + + "|_|" + + " |"); + MAP.put(FIVE, + " _ " + + "|_ " + + " _|"); + MAP.put(SIX, + " _ " + + "|_ " + + "|_|"); + MAP.put(SEVEN, + "__ " + + " |" + + " |"); + MAP.put(EIGHT, + " _ " + + "|_|" + + "|_|"); + MAP.put(NINE, + " _ " + + "|_|" + + " _|"); + } + + /** + * Constructor bankOCR. + */ + private BankOCR() { + + } + + /** + * @param value of string numbers. + * @return String of value number. + */ + private static String getMapKey(final String value) { + String res = "?"; + for (Map.Entry entry : MAP.entrySet()) { + if (entry.getValue().equals(value)) { + res = entry.getKey().toString(); + } + } + return res; + } + + /** + * @param cad value of string numbers. + * @return String to get the all numbers. + */ + public static String parseDigit(final String[] cad) { + String res = ""; + StringBuilder value = new StringBuilder(); + for (String data : cad) { + res = value.append(getMapKey(data)).toString(); + } + + return res; + } + + /** + * @param cad value of string numbers. + * @return String to get the ERR o ILL error result. + */ + public static String accountStatus(final String cad) { + String res = ""; + if (!digit(cad)) { + res = "ILL"; + } else if (!validAccountNumbers(cad)) { + res = "ERR"; + } + return res; + } + + /** + * @param data value of string numbers. + * @return boolean to get if is a valid digit. + */ + private static boolean digit(final String data) { + return Stream.of(data.split("")). + filter(a -> Character.isDigit(a.charAt(0))).count() > 0; + } + + /** + * @param input String value. + * @return boolean valor if is valid account number. + */ + public static boolean validAccountNumbers(final String input) { + int suma = 0; + for (int i = input.length() - 1; i >= 0; i--) { + int multiplier = 1; + int x = (int) (input.charAt(i)) * multiplier; + suma += x; + multiplier++; + } + return suma % VALIDATOR == 0; + } + +} + diff --git a/src/main/java/org/fundacionjala/coding/Fernando/checkSum/CheckSum.java b/src/main/java/org/fundacionjala/coding/Fernando/checkSum/CheckSum.java new file mode 100644 index 0000000..50bb16c --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/Fernando/checkSum/CheckSum.java @@ -0,0 +1,51 @@ +package org.fundacionjala.coding.Fernando.checkSum; + +/** + * Write a description of class checkSum here. + * + * @author (your name) + * @version (a version number or a date) + */ +public final class CheckSum { + static final int THREE = 3; + static final int ONE = 1; + static final int TEN = 10; + static final int TWO = 2; + static final int EIGHT = 8; + static final int ZERO = 0; + static final int SIZEVALUE = 13; + + /** + * Constructor checksum. + */ + private CheckSum() { + + } + + /** + * @param value data. + * @return boolean of cant values. + */ + public static boolean canValues(final String value) { + int sum = ZERO; + if (value.length() != SIZEVALUE) { + return false; + } + for (int i = ONE; i < value.length(); i++) { + int num = Character.getNumericValue(value.charAt(i - 1)); + sum += i % 2 == 0 ? num * THREE : num; + } + return validNum(sum) == Character.getNumericValue(value.charAt(value.length() - 1)); + } + + /** + * @param sum of values. + * @return int of number valid. + */ + public static int validNum(final int sum) { + int result = sum % TEN; + return result != 0 ? TEN - result : 0; + + } + +} diff --git a/src/main/java/org/fundacionjala/coding/Fernando/evaporator/Evaporator.java b/src/main/java/org/fundacionjala/coding/Fernando/evaporator/Evaporator.java new file mode 100644 index 0000000..da1ff8a --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/Fernando/evaporator/Evaporator.java @@ -0,0 +1,34 @@ +package org.fundacionjala.coding.Fernando.evaporator; + +/** + * Created by Administrator on 6/28/2017. + */ +public final class Evaporator { + + private static final int PERCENTAGE_TOTAL = 100; + + /** + * Constructor evaporator kata. + */ + private Evaporator() { + } + + /** + * @param content content containing. + * @param evapPerDay evaporation day. + * @param limit limit. + * @return life of an evaporator containing gas. + */ + + public static int evaporator(final double content, final double evapPerDay, final double limit) { + int res = 0; + double reduceConten = content; + double limitContent = content * limit / PERCENTAGE_TOTAL; + while (reduceConten >= limitContent) { + reduceConten = reduceConten - (reduceConten * evapPerDay / PERCENTAGE_TOTAL); + res++; + } + return res; + } +} + diff --git a/src/main/java/org/fundacionjala/coding/Fernando/haghestandlowest/HighAndLow.java b/src/main/java/org/fundacionjala/coding/Fernando/haghestandlowest/HighAndLow.java new file mode 100644 index 0000000..c7ed403 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/Fernando/haghestandlowest/HighAndLow.java @@ -0,0 +1,36 @@ +package org.fundacionjala.coding.Fernando.haghestandlowest; + +/** + * Created by PC on 24/06/2017. + */ +public final class HighAndLow { + + /** + * Method constructor. + */ + private HighAndLow() { + } + + /** + * This method get the high and low number. + * + * @param numbers to get the high and low number. + * @return String method. + */ + static String highAndLowest(final String numbers) { + String[] value = numbers.split(" "); + int majorNumber = Integer.parseInt(value[0]); + int minorNumber = majorNumber; + for (String res : value) { + int num = Integer.parseInt(res); + if (num > majorNumber) { + majorNumber = Integer.parseInt(res); + } + if (num < minorNumber) { + minorNumber = Integer.parseInt(res); + } + } + + return String.format("%d %d", majorNumber, minorNumber); + } +} diff --git a/src/main/java/org/fundacionjala/coding/Fernando/movies/Children.java b/src/main/java/org/fundacionjala/coding/Fernando/movies/Children.java new file mode 100644 index 0000000..950fc03 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/Fernando/movies/Children.java @@ -0,0 +1,39 @@ +package org.fundacionjala.coding.Fernando.movies; + +/** + * 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; + private static final int RENT_ONE_DAY = 1; + + /** + * @param title param. + */ + public Children(final String title) { + super(title); + } + + /** + * @param daysRented param. + * @return double value. + */ + @Override + public double calculateAmount(final int daysRented) { + double amount = PRICE; + if (daysRented > LIMITNEWCHILD) { + amount += (daysRented - LIMITNEWCHILD) * PRICE; + } + return amount; + } + + /** + * @param daysRented param. + * @return int value. + */ + @Override + public int calculateFrequentRenterPoints(final int daysRented) { + return RENT_ONE_DAY; + } +} diff --git a/src/main/java/org/fundacionjala/coding/Fernando/movies/Customer.java b/src/main/java/org/fundacionjala/coding/Fernando/movies/Customer.java new file mode 100644 index 0000000..be257cb --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/Fernando/movies/Customer.java @@ -0,0 +1,68 @@ +package org.fundacionjala.coding.Fernando.movies; + +import java.util.ArrayList; +import java.util.List; + +/** + * This is the class Customer of rental movies. + */ +public class Customer { + private String nameCustomer; + private List rentalsCustomer; + + /** + * @param nameCustomer String with words. + * Constructor. + */ + public 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() { + StringBuilder result = new StringBuilder(); + result.append(String.format("Rental Record for %s %n", getName())); + for (Rental rental : rentalsCustomer) { + result.append(String.format("\t %s \t", rental.getMovie().getTitle())); + result.append(String.format("%f %n", rental.calculateAmount())); + } + result.append(String.format("Amount owed is %f %n", calculateTotalAmount())); + result.append(String.format("You earned %d frequent renter points", calculateTotalFrequentRenterPoints())); + return result.toString(); + } + + /** + * @return double value. + */ + public double calculateTotalAmount() { + return rentalsCustomer.stream() + .mapToDouble(Rental::calculateAmount) + .sum(); + } + + /** + * @return int value. + */ + public int calculateTotalFrequentRenterPoints() { + return rentalsCustomer.stream() + .mapToInt(rental -> rental.calculateFrequentRenterPoint()) + .sum(); + } +} diff --git a/src/main/java/org/fundacionjala/coding/Fernando/movies/Movie.java b/src/main/java/org/fundacionjala/coding/Fernando/movies/Movie.java new file mode 100644 index 0000000..c64df4f --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/Fernando/movies/Movie.java @@ -0,0 +1,34 @@ +package org.fundacionjala.coding.Fernando.movies; + +/** + * Created by Administrator on 3/21/2017. + */ +public abstract class Movie { + private String title; + + /** + * @param title param. + */ + public Movie(final String title) { + this.title = title; + } + + /** + * @param daysRented param. + * @return double value. + */ + public abstract double calculateAmount(int daysRented); + + /** + * @param daysRented param. + * @return int value. + */ + public abstract int calculateFrequentRenterPoints(int daysRented); + + /** + * @return String value. + */ + public String getTitle() { + return title; + } +} diff --git a/src/main/java/org/fundacionjala/coding/Fernando/movies/NewRelease.java b/src/main/java/org/fundacionjala/coding/Fernando/movies/NewRelease.java new file mode 100644 index 0000000..18b9c31 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/Fernando/movies/NewRelease.java @@ -0,0 +1,34 @@ +package org.fundacionjala.coding.Fernando.movies; + +/** + * Created by Administrator on 3/21/2017. + */ +public class NewRelease extends Movie { + + private static final int LIMITNEWCHILD = 3; + + /** + * @param title param. + */ + public NewRelease(final String title) { + super(title); + } + + /** + * @param daysRented param. + * @return double value. + */ + @Override + public double calculateAmount(final int daysRented) { + return daysRented * LIMITNEWCHILD; + } + + /** + * @param daysRented param. + * @return Children value. + */ + @Override + public int calculateFrequentRenterPoints(final int daysRented) { + return daysRented > 1 ? 2 : 1; + } +} diff --git a/src/main/java/org/fundacionjala/coding/Fernando/movies/Regular.java b/src/main/java/org/fundacionjala/coding/Fernando/movies/Regular.java new file mode 100644 index 0000000..8ecba2d --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/Fernando/movies/Regular.java @@ -0,0 +1,40 @@ +package org.fundacionjala.coding.Fernando.movies; + +/** + * 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; + + /** + * @param title param. + */ + public Regular(final String title) { + super(title); + } + + /** + * @param daysRented param. + * @return double value. + */ + @Override + public double calculateAmount(final int daysRented) { + double amount = LIMITREGULAR; + if (daysRented > LIMITREGULAR) { + amount += (daysRented - LIMITREGULAR) * PRICE; + } + return amount; + } + + /** + * @param daysRented param. + * @return int value. + */ + @Override + public int calculateFrequentRenterPoints(final int daysRented) { + return 1; + } +} diff --git a/src/main/java/org/fundacionjala/coding/Fernando/movies/Rental.java b/src/main/java/org/fundacionjala/coding/Fernando/movies/Rental.java new file mode 100644 index 0000000..6cecf7d --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/Fernando/movies/Rental.java @@ -0,0 +1,47 @@ +package org.fundacionjala.coding.Fernando.movies; + +/** + * Created by Fernando. + */ +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 movies 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); + } +} + diff --git a/src/main/java/org/fundacionjala/coding/Fernando/multiples/Multiples.java b/src/main/java/org/fundacionjala/coding/Fernando/multiples/Multiples.java new file mode 100644 index 0000000..ebe2b9e --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/Fernando/multiples/Multiples.java @@ -0,0 +1,31 @@ +package org.fundacionjala.coding.Fernando.multiples; + +/** + * Created by PC on 24/06/2017. + */ +public final class Multiples { + + public static final int FIVE = 5; + private static final int THREE = 3; + + /** + * Constructor. + */ + private Multiples() { + } + + /** + * @param num parameter. + * @return int value multiples of 3 and 5. + */ + + public static int solution(final int num) { + int res = 0; + for (int i = 0; i < num; i++) { + if (i % THREE == 0 || i % FIVE == 0) { + res += i; + } + } + return res; + } +} diff --git a/src/test/java/org/fundacionjala/coding/Fernando/StringInv/StringInvTest.java b/src/test/java/org/fundacionjala/coding/Fernando/StringInv/StringInvTest.java new file mode 100644 index 0000000..bc01c51 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/Fernando/StringInv/StringInvTest.java @@ -0,0 +1,82 @@ +package org.fundacionjala.coding.Fernando.StringInv; + +import org.junit.Assert; +import org.junit.Test; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import static org.junit.Assert.assertEquals; + +/** + * The test class StringInvTest. + * + * @author (your name) + * @version (a version number or a date) + */ +public class StringInvTest { + + /** + * Test Constructor. + * @throws Exception if the constructor is not private. + */ + @Test + public void testStringInv() throws Exception { + Constructor evaporatorConstructor = StringInv.class.getDeclaredConstructor(); + Assert.assertTrue(Modifier.isPrivate(evaporatorConstructor.getModifiers())); + evaporatorConstructor.setAccessible(true); + evaporatorConstructor.newInstance(); + } + + + /** + * Test when sentence is empty. + */ + @Test + public void testWhenSentenceIsEmpty() { + + // given: + final String sentence = ""; + + // when: + final String actualResult = StringInv.stringInv(sentence); + + // then: + final String expectedResult = ""; + assertEquals(expectedResult, actualResult); + } + + /** + * Test when sentence has no words major to five. + */ + @Test + public void testWhenSentenceHasNoWordsMajorToFive() { + + // give: + final String sentence = "Hi guys how are you"; + + // when: + final String actualResult = StringInv.stringInv(sentence); + + // then: + final String expectedResult = "Hi guys how are you"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test when sentence has more than one word major that five. + */ + @Test + public void testWhenSentenceHasMoreThanOneWordMajorThatFive() { + + // give: + final String sentence = "Hey fellow warriors"; + + // when: + final String actualResult = StringInv.stringInv(sentence); + + // then: + final String expectedResult = "Hey wollef sroirraw"; + assertEquals(expectedResult, actualResult); + } +} diff --git a/src/test/java/org/fundacionjala/coding/Fernando/average/AverageTest.java b/src/test/java/org/fundacionjala/coding/Fernando/average/AverageTest.java new file mode 100644 index 0000000..38acd3f --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/Fernando/average/AverageTest.java @@ -0,0 +1,135 @@ +package org.fundacionjala.coding.Fernando.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; + +/** + * The test class AverageTest. + * + * @author (your name) + * @version (a version number or a date) + */ +public class AverageTest { + + /** + * Test Constructor. + * @throws Exception if the constructor is not private. + */ + @Test + public void testAverageConstructorIsPrivate() throws Exception { + Constructor constructor = Average.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + + /** + * Test to get the prom when we have 5 elements. + */ + @Test + public void testPromWhenHave5Elements() { + + // given: + final int[] num = {2, 2, 2, 2, 2}; + + // when: + final double[] actualResult = Average.average(num); + + // then: + final double[] expectedResult = {2.0, 2.0, 2.0, 2.0}; + assertEquals(Arrays.toString(expectedResult), Arrays.toString(actualResult)); + } + + /** + * Test to get the prom when we have differents elements. + */ + @Test + public void testPromWhenHaveDifferentData() { + + // given: + + final int[] num = {1, 3, 5, 1, -10}; + + // when: + final double[] actualResult = Average.average(num); + + // then: + final double[] expectedResult = {2.0, 4.0, 3.0, -4.5}; + assertEquals(Arrays.toString(expectedResult), Arrays.toString(actualResult)); + } + + /** + * Test to get the prom when we have the same elements. + */ + @Test + public void testPromWhenHaveTheSameData() { + + // given: + final int[] num = {2, -2, 2, -2, 2}; + + // when: + final double[] actualResult = Average.average(num); + + // then: + final double[] expectedResult = {0.0, 0.0, 0.0, 0.0}; + assertEquals(Arrays.toString(expectedResult), Arrays.toString(actualResult)); + } + + /** + * Test to get the prom when the array is null. + */ + @Test + public void testPromWhenTheArrayIsNull() { + + // given: + final int[] num = null; + + // when: + final double[] actualResult = Average.average(num); + + // then: + final double[] expectedResult = {}; + assertEquals(Arrays.toString(expectedResult), Arrays.toString(actualResult)); + } + + /** + * Test to get the prom when we have the array empty. + */ + @Test + public void testPromWhenTheArrayIsEmpty() { + + // give: + final int[] num = {}; + + // when: + final double[] actualResult = Average.average(num); + + // then: + final double[] expectedResult = {}; + + assertEquals(Arrays.toString(expectedResult), Arrays.toString(actualResult)); + } + + /** + * Test to get the prom when we have one element. + */ + @Test + public void testPromWhenTheArrayHasOneElement() { + + // given: + final int[] num = {2}; + + // when: + final double[] actualResult = Average.average(num); + + // then: + final double[] expectedResult = {}; + assertEquals(Arrays.toString(expectedResult), Arrays.toString(actualResult)); + } +} diff --git a/src/test/java/org/fundacionjala/coding/Fernando/bankOCR/BankOCRTest.java b/src/test/java/org/fundacionjala/coding/Fernando/bankOCR/BankOCRTest.java new file mode 100644 index 0000000..b37181e --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/Fernando/bankOCR/BankOCRTest.java @@ -0,0 +1,165 @@ +package org.fundacionjala.coding.Fernando.bankOCR; + +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; +import static org.junit.Assert.assertFalse; + +/** + * Created by PC on 24/06/2017. + */ +public class BankOCRTest { + + /** + * Test Constructor. + * @throws Exception if the constructor is not private. + */ + @Test + public void testBankOCRConstructorIsPrivate() throws Exception { + Constructor constructor = BankOCR.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + + /** + * Test the number. + */ + @Test + public void testToGetNumber() { + // given: + String[] data = { + " _ " + + "| |" + + "|_|", + + " " + + " |" + + " |", + + " _ " + + " _|" + + "|_ ", + + "__ " + + " _|" + + "__|", + + " " + + "|_|" + + " |", + + " _ " + + "|_ " + + " _|", + + " _ " + + "|_ " + + "|_|", + + "__ " + + " |" + + " |", + + " _ " + + "|_|" + + "|_|", + + " _ " + + "|_|" + + " _|" + }; + + // when: + final String actualResult = BankOCR.parseDigit(data); + + // then: + final String expectedResult = "0123456789"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test when values has different o wrong number. + */ + @Test + public void testWithWrongNumbers() { + // given: + String[] data = { + " _ " + + "| |" + + "|_|", + + " _ " + + "|_|" + + " _|", + + "Wrong number", + "", + " _ " + + "|_ " + + " _|" + }; + + // when: + final String actualResult = BankOCR.parseDigit(data); + + // then: + final String expectedResult = "09??5"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test with incorrect datas. + */ + @Test + public void testWithIncorrectDatas() { + // given: + String[] data = { + " " + + "|_|" + + " |", + + " _ " + + "|_ " + + " _|", + + " _ " + + "|_ " + + "|_|", + + "__ " + + " |" + + " |", + + }; + final String value = BankOCR.parseDigit(data); + + // when: + final boolean actualResult = BankOCR.validAccountNumbers(value); + + // then: + assertFalse(actualResult); + } + + /** + * Test when we get the result "ERR". + */ + @Test + public void testWithWrongDatas() { + // given: + String data = "021453789"; + + // when: + String actualResult = BankOCR.accountStatus(data); + + // then: + String expectedResult = "ERR"; + assertEquals(expectedResult, actualResult); + } + +} + diff --git a/src/test/java/org/fundacionjala/coding/Fernando/checkSum/CheckSumTest.java b/src/test/java/org/fundacionjala/coding/Fernando/checkSum/CheckSumTest.java new file mode 100644 index 0000000..7666ce2 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/Fernando/checkSum/CheckSumTest.java @@ -0,0 +1,75 @@ +package org.fundacionjala.coding.Fernando.checkSum; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertFalse; + +/** + * The test class CheckSumTest. + * + * @author (your name) + * @version (a version number or a date) + */ +public class CheckSumTest { + + /** + * Test Constructor. + * @throws Exception if the constructor is not private. + */ + @Test + public void testCheckSumConstructorIsPrivate() throws Exception { + Constructor constructor = CheckSum.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + + /** + * Test when sentence is empty. + */ + @Test + public void testWhenSentenceISEmpty() { + + // given: + final String sentence = "4003301018398"; + + // when: + final boolean actualResult = CheckSum.canValues(sentence); + + assertTrue(actualResult); + } + + /** + * Test when sentence has more than one word major that five. + */ + @Test + public void testWhenSentenceHasMoreThanOneWordMajorThatFive() { + + // given: + final String sentence = "1234567890200"; + + // when: + final boolean actualResult = CheckSum.canValues(sentence); + + assertFalse(actualResult); + } + + /** + * Test when sentence has more than one word major that five. + */ + @Test + public void testWhenSentenceHasLessThanThrerteenWords() { + + // given: + final String sentence = "123456789"; + + // when: + final boolean actualResult = CheckSum.canValues(sentence); + + assertFalse(actualResult); + } +} diff --git a/src/test/java/org/fundacionjala/coding/Fernando/evaporator/EvaporatorTest.java b/src/test/java/org/fundacionjala/coding/Fernando/evaporator/EvaporatorTest.java new file mode 100644 index 0000000..e36b816 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/Fernando/evaporator/EvaporatorTest.java @@ -0,0 +1,93 @@ +package org.fundacionjala.coding.Fernando.evaporator; + +import org.junit.Test; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Created by PC on 28/06/2017. + */ +public class EvaporatorTest { + + /** + * Test one. + */ + @Test + public void testEvaporatorOne() { + assertEquals(22, Evaporator.evaporator(10, 10, 10)); + } + + /** + * Test two. + */ + @Test + public void testEvaporatorTwo() { + assertEquals(29, Evaporator.evaporator(10, 10, 5)); + } + + /** + * Test three. + */ + @Test + public void testEvaporatorThree() { + assertEquals(59, Evaporator.evaporator(100, 5, 5)); + } + + /** + * Test four. + */ + @Test + public void testEvaporatorFour() { + assertEquals(37, Evaporator.evaporator(50, 12, 1)); + } + + /** + * Test five. + */ + @Test + public void testEvaporatorFive() { + assertEquals(31, Evaporator.evaporator(47.5, 8, 8)); + } + + /** + * Test six. + */ + @Test + public void testEvaporatorSix() { + assertEquals(459, Evaporator.evaporator(100, 1, 1)); + } + + /** + * Test seven. + */ + @Test + public void testEvaporatorSeven() { + assertEquals(459, Evaporator.evaporator(10, 1, 1)); + } + + /** + * Test eight. + */ + @Test + public void testEvaporatorEight() { + assertEquals(299, Evaporator.evaporator(100, 1, 5)); + } + + /** + * Test constructor. + * @throws Exception exception. + */ + @Test + public void testConstructorIsPrivate() throws Exception { + Constructor constructor = Evaporator.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +} + + diff --git a/src/test/java/org/fundacionjala/coding/Fernando/haghestandlowest/HighAndLowTest.java b/src/test/java/org/fundacionjala/coding/Fernando/haghestandlowest/HighAndLowTest.java new file mode 100644 index 0000000..92902b5 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/Fernando/haghestandlowest/HighAndLowTest.java @@ -0,0 +1,93 @@ +package org.fundacionjala.coding.Fernando.haghestandlowest; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; + +import static junit.framework.TestCase.assertTrue; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +/** + * Created by PC on 25/06/2017. + */ +public class HighAndLowTest { + + /** + * Test Constructor. + * @throws Exception if the constructor is not private. + */ + @Test + public void testHighAndLowConstructorIsPrivate() throws Exception { + Constructor constructor = HighAndLow.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + + /** + * Some Test. + */ + @Test + public void someTest() { + assertThat(HighAndLow.highAndLowest("4 5 29 54 4 0 -214 542 -64 1 -3 6 -6"), is("542 -214")); + } + + /** + * PlusMinusTest. + */ + @Test + public void plusMinusTest() { + assertThat(HighAndLow.highAndLowest("1 -1"), is("1 -1")); + } + + /** + * Plus plus test. + */ + @Test + public void plusPlusTest() { + assertThat(HighAndLow.highAndLowest("1 1"), is("1 1")); + } + + /** + * Minus minus test. + */ + @Test + public void minusMinusTest() { + assertThat(HighAndLow.highAndLowest("-1 -1"), is("-1 -1")); + } + + /** + * Plus minus zero test. + */ + @Test + public void plusMinusZeroTest() { + assertThat(HighAndLow.highAndLowest("1 -1 0"), is("1 -1")); + } + + /** + * Plus zero test. + */ + @Test + public void plusPlusZeroTest() { + assertThat(HighAndLow.highAndLowest("1 1 0"), is("1 0")); + } + + /** + * Minus zero test. + */ + @Test + public void minusMinusZeroTest() { + assertThat(HighAndLow.highAndLowest("-1 -1 0"), is("0 -1")); + } + + /** + * Single test. + */ + @Test + public void singleTest() { + assertThat(HighAndLow.highAndLowest("42"), is("42 42")); + } + +} diff --git a/src/test/java/org/fundacionjala/coding/Fernando/movies/ChildrenTest.java b/src/test/java/org/fundacionjala/coding/Fernando/movies/ChildrenTest.java new file mode 100644 index 0000000..cea2c6f --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/Fernando/movies/ChildrenTest.java @@ -0,0 +1,75 @@ +package org.fundacionjala.coding.Fernando.movies; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Created by PC on 24/06/2017. + */ +public class ChildrenTest { + + private Movie movie; + + /** + * Creating Children instance. + */ + @Before + public void createCustomer() { + movie = new Children("Toy Story"); + } + + /** + * Test to verify the amount rent less than three days. + */ + @Test + public void testCalculateAmountWhenTheRentedDaysIsLessThanThree() { + + // when: + final double actualResult = movie.calculateAmount(2); + + // then + final double expectedResult = 1.5; + assertEquals(expectedResult, actualResult, 0); + } + + /** + * Test to verify the amount rent more than three days. + */ + @Test + public void testToCalculateRentMovieMoreThanThreeDays() { + + // when: + final double actualResult = movie.calculateAmount(10); + + // then: + final double expectedResult = 12.0; + assertEquals(expectedResult, actualResult, 0); + } + + /** + * Test to verify the frequent renter for different days. + */ + @Test + public void testToCalculateTheFrequentRentDifferentDays() { + + // when: + final int actualResult = movie.calculateFrequentRenterPoints(1); + + // then: + final int expectedResult = 1; + assertEquals(expectedResult, actualResult); + + // given: + + // when: + final int actualResultTwo = movie.calculateFrequentRenterPoints(3); + + // then: + final int expectedResultTwo = 1; + assertEquals(expectedResultTwo, actualResultTwo); + + } + +} diff --git a/src/test/java/org/fundacionjala/coding/Fernando/movies/CustomerTest.java b/src/test/java/org/fundacionjala/coding/Fernando/movies/CustomerTest.java new file mode 100644 index 0000000..8ec3d98 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/Fernando/movies/CustomerTest.java @@ -0,0 +1,88 @@ +package org.fundacionjala.coding.Fernando.movies; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Created by PC on 25/06/2017. + */ +public class CustomerTest { + + private static final int RENT_DAY = 1; + private static final double PRICE_MINOR = 1.5; + + private Customer customer; + + /** + * Create customer. + */ + @Before + public void createCustomer() { + customer = new Customer("Fernando"); + } + + /** + * testSpinWordsWhenCustomeIsTest. + */ + @Test + public void testSpinWordsWhenCustomeIsTest() { + + // given: + customer.addRental(new Rental(new Children("The Revenant"), 2)); + + // when: + final String actualResult = customer.getName(); + + // then: + final String expectedResult = "Fernando"; + assertEquals(expectedResult, actualResult); + } + + /** + * test Movie When Day Rented Is less For Children. + */ + @Test + public void testMovieWhenDayRentedISLessForChildren() { + + // given: + customer.addRental(new Rental(new Children("The Revenant"), RENT_DAY)); + + // when: + final double actualResult = customer.calculateTotalAmount(); + + // then: + + assertEquals(PRICE_MINOR, actualResult, 0); + } + + /** + * Test customer class. + */ + @Test + public void testCustomer() { + final double rentalAmountONe = 6.0; + final double rentalAmountTwo = 2.0; + final double rentalTotalAmount = 8.0; + final int earnedFrequentRenter = 3; + + // given + customer.addRental(new Rental(new NewRelease("Moana"), 2)); + customer.addRental(new Rental(new Regular("Titanic"), 1)); + + // when + final String actualResult = customer.generateDetail(); + + // then + StringBuilder expectedResult = new StringBuilder(); + expectedResult.append(String.format("Rental Record for %s %n", "Fernando")); + expectedResult.append(String.format("\t %s \t%f %n", "Moana", rentalAmountONe)); + expectedResult.append(String.format("\t %s \t%f %n", "Titanic", rentalAmountTwo)); + + expectedResult.append(String.format("Amount owed is %f %n", rentalTotalAmount)); + expectedResult.append(String.format("You earned %d frequent renter points", earnedFrequentRenter)); + + assertEquals(expectedResult.toString(), actualResult); + } +} diff --git a/src/test/java/org/fundacionjala/coding/Fernando/movies/NewReleaseTest.java b/src/test/java/org/fundacionjala/coding/Fernando/movies/NewReleaseTest.java new file mode 100644 index 0000000..bcfd469 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/Fernando/movies/NewReleaseTest.java @@ -0,0 +1,75 @@ +package org.fundacionjala.coding.Fernando.movies; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Created by PC on 25/06/2017. + */ +public class NewReleaseTest { + + private Movie movie; + + /** + * Creating new release instance. + */ + @Before + public void createNewRelease() { + movie = new NewRelease("Toy Story"); + } + + /** + * Test to verify the amount rent less than three days. + */ + @Test + public void testCalculateAmountWhenTheRentedDaysIsLessThanThree() { + + // when: + final double actualResult = movie.calculateAmount(2); + + // then + final double expectedResult = 1.5; + assertEquals(0, expectedResult, actualResult); + } + + /** + * Test to verify the amount rent more than three days. + */ + @Test + public void testToCalculateRentMovieMoreThanThreeDays() { + + // when: + final double actualResult = movie.calculateAmount(10); + + // then: + final double expectedResult = 10.5; + assertEquals(0, expectedResult, actualResult); + } + + /** + * Test to verify the frequent renter for different days. + */ + @Test + public void testToCalculateTheFrequentRentDifferentDays() { + + // when: + final int actualResult = movie.calculateFrequentRenterPoints(1); + + // then: + final int expectedResult = 1; + assertEquals(expectedResult, actualResult); + + // given: + + // when: + final int actualResultTwo = movie.calculateFrequentRenterPoints(3); + + // then: + final int expectedResultTwo = 2; + assertEquals(expectedResultTwo, actualResultTwo); + + } + +} diff --git a/src/test/java/org/fundacionjala/coding/Fernando/movies/RegularTest.java b/src/test/java/org/fundacionjala/coding/Fernando/movies/RegularTest.java new file mode 100644 index 0000000..2243368 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/Fernando/movies/RegularTest.java @@ -0,0 +1,74 @@ +package org.fundacionjala.coding.Fernando.movies; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Created by PC on 25/06/2017. + */ +public class RegularTest { + + private Movie movie; + + /** + * Creating Regular instance. + */ + @Before + public void createRegular() { + movie = new Regular("Toy Story"); + } + + /** + * Test to verify the amount rent less than three days. + */ + @Test + public void testCalculateAmountWhenTheRentedDaysIsLessThanThree() { + + // when: + final double actualResult = movie.calculateAmount(2); + + // then + final double expectedResult = 1.5; + assertEquals(0, expectedResult, actualResult); + } + + /** + * Test to verify the amount rent more than three days. + */ + @Test + public void testToCalculateRentMovieMoreThanThreeDays() { + + // when: + final double actualResult = movie.calculateAmount(10); + + // then: + final double expectedResult = 10.5; + assertEquals(0, expectedResult, actualResult); + } + + /** + * Test to verify the frequent renter for different days. + */ + @Test + public void testToCalculateTheFrequentRentDifferentDays() { + + // when: + final int actualResult = movie.calculateFrequentRenterPoints(1); + + // then: + final int expectedResult = 1; + assertEquals(expectedResult, actualResult); + + // given: + + // when: + final int actualResultTwo = movie.calculateFrequentRenterPoints(3); + + // then: + final int expectedResultTwo = 1; + assertEquals(expectedResultTwo, actualResultTwo); + + } +} diff --git a/src/test/java/org/fundacionjala/coding/Fernando/movies/RentalTest.java b/src/test/java/org/fundacionjala/coding/Fernando/movies/RentalTest.java new file mode 100644 index 0000000..3727bd0 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/Fernando/movies/RentalTest.java @@ -0,0 +1,55 @@ +package org.fundacionjala.coding.Fernando.movies; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Created by PC on 03/07/2017. + */ +public class RentalTest { + + private static final int DAYS_RENTED = 2; + + private Movie movie; + private Rental rental; + + /** + * Creating Regular and Rental instance. + */ + @Before + public void createRegularAndRental() { + movie = new Regular("Star Wars"); + rental = new Rental(movie, DAYS_RENTED); + } + + /** + * Test get title. + */ + @Test + public void testGetTitle() { + + // when: + final String actualResult = rental.getMovie().getTitle(); + + // then: + final String expectedResult = "Star Wars"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test days rented. + */ + + @Test + public void testDaysRented() { + + // when: + final int actualResult = rental.getDaysRented(); + + // then: + final int expectedResult = DAYS_RENTED; + assertEquals(expectedResult, actualResult); + } +} diff --git a/src/test/java/org/fundacionjala/coding/Fernando/multiples/MultiplesTest.java b/src/test/java/org/fundacionjala/coding/Fernando/multiples/MultiplesTest.java new file mode 100644 index 0000000..4ec7a96 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/Fernando/multiples/MultiplesTest.java @@ -0,0 +1,81 @@ +package org.fundacionjala.coding.Fernando.multiples; + +import org.junit.Test; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Created by PC on 03/07/2017. + */ +public class MultiplesTest { + + /** + * Unit Test about multiples of 3 and 5. + * + * Test one. + */ + @Test + public void testOne() { + final int expectedResult = 23; + + final int expectedVariable = 10; + + assertEquals(expectedResult, Multiples.solution(expectedVariable)); + } + + /** + * Unit Test about multiples of 3 and 5. + * + * Test two. + */ + @Test + public void testTwo() { + final int expectedResult = 78; + + final int expectedVariable = 20; + + assertEquals(expectedResult, Multiples.solution(expectedVariable)); + } + + /** + * Unit Test about multiples of 3 and 5. + * + * Test three. + */ + @Test + public void testThree() { + final int expectedResult = 9168; + + final int expectedVariable = 200; + + assertEquals(expectedResult, Multiples.solution(expectedVariable)); + } + + /** + * Unit test if is zero. + */ + @Test + public void testFour() { + final int expectedResult = 0; + + final int expectedVariable = 0; + + assertEquals(expectedResult, Multiples.solution(expectedVariable)); + } + + /** + * Test constructor. + * @throws Exception exception. + */ + @Test + public void testConstructorIsPrivate() throws Exception { + Constructor constructor = Multiples.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +}