diff --git a/src/main/java/org/fundacionjala/coding/reinaldo/average/Average.java b/src/main/java/org/fundacionjala/coding/reinaldo/average/Average.java new file mode 100644 index 0000000..71f128d --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/reinaldo/average/Average.java @@ -0,0 +1,32 @@ +package org.fundacionjala.coding.reinaldo.average; + +import java.util.stream.IntStream; + +/** + * Created by Administrator on 6/30/2017. + * + */ +public final class Average { + /** + * Constructor private. + */ + private Average() { + + } + + /** + * This method averagesCalculate verify is empty, null or only has + * one element or averges. + * + * @param sentence array. + * @return true if the array is not empty, null or has only one element. + */ + public static double[] averagesCalculate(final int[] sentence) { + + return sentence == null || sentence.length < 2 + ? new double[0] + : IntStream.range(0, sentence.length - 1) + .mapToDouble(i -> (sentence[i] + sentence[i + 1]) / 2d).toArray(); + } +} + diff --git a/src/main/java/org/fundacionjala/coding/reinaldo/ean/Ean.java b/src/main/java/org/fundacionjala/coding/reinaldo/ean/Ean.java new file mode 100644 index 0000000..7a1f7c5 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/reinaldo/ean/Ean.java @@ -0,0 +1,43 @@ +package org.fundacionjala.coding.reinaldo.ean; + +import java.util.stream.IntStream; + + +/** + * Created by Administrator on 6/30/2017. + */ +public final class Ean { + + private static final int DIVISOR = 10; + + /** + * This is the constructor of Ean. + */ + private Ean() { + + } + + /** + * @param eanCode validate checksum. + * @return boolean is checksum. + */ + static boolean validate(final String eanCode) { + final int sumToCheck = IntStream + .range(0, eanCode.length() - 1) + .reduce(0, (acc, index) + -> acc + Character.getNumericValue(eanCode.charAt(index)) * (1 + 2 * (index % 2))); + + return Character.getNumericValue(eanCode.charAt(eanCode.length() - 1)) == getAnInt(sumToCheck); + + } + + /** + * This method return getAnInt. + * + * @param sumToCheck sumtocheck. + * @return int getSum + */ + private static int getAnInt(final int sumToCheck) { + return sumToCheck % DIVISOR == 0 ? 0 : DIVISOR - (sumToCheck % DIVISOR); + } +} diff --git a/src/main/java/org/fundacionjala/coding/reinaldo/evaporator/Evaporator.java b/src/main/java/org/fundacionjala/coding/reinaldo/evaporator/Evaporator.java new file mode 100644 index 0000000..f72ceba --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/reinaldo/evaporator/Evaporator.java @@ -0,0 +1,32 @@ +package org.fundacionjala.coding.reinaldo.evaporator; + +/** + * Created by Administrator on 6/30/2017. + * + */ +final class Evaporator { + + /** + * This is the constructor of Evaporator. + */ + private Evaporator() { + + } + + /** + * this method calc the Evaporator at day. + * + * @param cant is the cant + * @param lost is the lost + * @param limit is the limit + * @return int at day + */ + static int evaporator(final double cant, final double lost, final double limit) { + int result = 0; + do { + ++result; + } while (Math.pow(1 - (lost / 100), result) > limit / 100); + + return result; + } +} diff --git a/src/main/java/org/fundacionjala/coding/reinaldo/highestAndLowestTest/HighestAndLowest.java b/src/main/java/org/fundacionjala/coding/reinaldo/highestAndLowestTest/HighestAndLowest.java new file mode 100644 index 0000000..de39089 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/reinaldo/highestAndLowestTest/HighestAndLowest.java @@ -0,0 +1,35 @@ +package org.fundacionjala.coding.reinaldo.highestAndLowestTest; + +import java.util.stream.Stream; + +/** + * Created by Administrator on 6/30/2017. + */ +final class HighestAndLowest { + /** + * Private constructor. + */ + private HighestAndLowest() { + } + + /** + * the method return the highAndLowest. + * + * @param numbers highAndLowest test + * @return String highAndLowest string + */ + static String highAndLowest(final String numbers) { + + + int high = Stream.of(numbers.split(" ")) + .mapToInt(Integer::parseInt) + .max().getAsInt(); + + int low = Stream.of(numbers.split(" ")) + .mapToInt(Integer::parseInt) + .min().getAsInt(); + + return String.format("%d %d", high, low); + } + +} diff --git a/src/main/java/org/fundacionjala/coding/reinaldo/kataBankOcr/BankOcrKata.java b/src/main/java/org/fundacionjala/coding/reinaldo/kataBankOcr/BankOcrKata.java new file mode 100644 index 0000000..62fe826 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/reinaldo/kataBankOcr/BankOcrKata.java @@ -0,0 +1,85 @@ +package org.fundacionjala.coding.reinaldo.kataBankOcr; + +import java.util.Arrays; +import java.util.List; + +/** + * Created by reinaldo on 08/07/2017. + */ +final class BankOcrKata { + private static final int MODULUS_FACTOR = 11; + private static final int INCREMENT_BY_THREE = 3; + private static final int TAM_CHARACTERS = 26; + + /** + * This is the constructor bankOcrKata. + */ + private BankOcrKata() { + } + + /** + * This method decode a List. + * + * @param listAccountNumber listAccount + * @return String list + */ + static String decode(final List listAccountNumber) { + int charsPerCharacter = INCREMENT_BY_THREE; + int index = 0; + StringBuilder accountNumber = new StringBuilder(); + + while (index <= TAM_CHARACTERS) { + + accountNumber.append(EncodedDigit.comparation(getDigitString(listAccountNumber, charsPerCharacter, index))); + charsPerCharacter += INCREMENT_BY_THREE; + index += INCREMENT_BY_THREE; + + } + + return accountNumber.toString(); + } + + /** + * This method return the a digite in strings for found on map. + * + * @param listAccountNumber listAccount + * @param charsPerCharacter charsper + * @param index index + * @return String string + */ + private static String getDigitString(final List listAccountNumber, + final int charsPerCharacter, final int index) { + return String.format("%s%s%s", + listAccountNumber.get(0).substring(index, charsPerCharacter), + listAccountNumber.get(1).substring(index, charsPerCharacter), + listAccountNumber.get(2).substring(index, charsPerCharacter)); + } + + + /** + * @param dateNamber parameter. + * @return ResultErrIll. + * this is my constructor 12/03/2017. + */ + static String codeCheck(final String dateNamber) { + return (dateNamber.matches("(.*)[?](.*)") ? "ILL" : (checkSumAcount(dateNamber) != 0) ? "ERR" : "OK"); + } + + /** + * @param accountNumber parameter. + * @return int. + */ + static int checkSumAcount(final String accountNumber) { + + int multiplyByNine = 9; + List listAcountNumber = Arrays.asList(accountNumber.split("")); + int suma = 0; + + for (String wordItem : listAcountNumber) { + suma += Integer.parseInt(wordItem) * multiplyByNine--; + } + + return suma % MODULUS_FACTOR; + } + +} diff --git a/src/main/java/org/fundacionjala/coding/reinaldo/kataBankOcr/Digit.java b/src/main/java/org/fundacionjala/coding/reinaldo/kataBankOcr/Digit.java new file mode 100644 index 0000000..79935e4 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/reinaldo/kataBankOcr/Digit.java @@ -0,0 +1,8 @@ +package org.fundacionjala.coding.reinaldo.kataBankOcr; + +/** + * Created by reinaldo on 12/03/2017. + */ +public enum Digit { + CERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE +} diff --git a/src/main/java/org/fundacionjala/coding/reinaldo/kataBankOcr/EncodedDigit.java b/src/main/java/org/fundacionjala/coding/reinaldo/kataBankOcr/EncodedDigit.java new file mode 100644 index 0000000..d3460c4 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/reinaldo/kataBankOcr/EncodedDigit.java @@ -0,0 +1,86 @@ +package org.fundacionjala.coding.reinaldo.kataBankOcr; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * Created by reinaldo on 08/07/2017. + */ +final class EncodedDigit { + private static final Map MUMBER_MAP; + + /** + * constructor. + */ + private EncodedDigit() { + } + + /** + * method fill number digite. + */ + static { + + MUMBER_MAP = new HashMap(); + MUMBER_MAP.put(Digit.CERO.ordinal(), + " _ " + + "| |" + + "|_|"); + MUMBER_MAP.put(Digit.ONE.ordinal(), + " " + + " |" + + " |"); + MUMBER_MAP.put(Digit.TWO.ordinal(), + " _ " + + " _|" + + "|_ "); + MUMBER_MAP.put(Digit.THREE.ordinal(), + " _ " + + " _|" + + " _|"); + MUMBER_MAP.put(Digit.FOUR.ordinal(), + " " + + "|_|" + + " |"); + MUMBER_MAP.put(Digit.FIVE.ordinal(), + " _ " + + "|_ " + + " _|"); + MUMBER_MAP.put(Digit.SIX.ordinal(), + " _ " + + "|_ " + + "|_|"); + MUMBER_MAP.put(Digit.SEVEN.ordinal(), + " _ " + + " |" + + " |"); + MUMBER_MAP.put(Digit.EIGHT.ordinal(), + " _ " + + "|_|" + + "|_|"); + MUMBER_MAP.put(Digit.NINE.ordinal(), + " _ " + + "|_|" + + " _|"); + } + + /** + * @param lineNumber this is string parameter. + * @return String. + */ + static String comparation(final String lineNumber) { + Iterator> it = MUMBER_MAP.entrySet().iterator(); + String resulValue = "?"; + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().equalsIgnoreCase(lineNumber)) { + return entry.getKey().toString(); + + } + } + + return resulValue; + } +} + + diff --git a/src/main/java/org/fundacionjala/coding/reinaldo/movies/Children.java b/src/main/java/org/fundacionjala/coding/reinaldo/movies/Children.java new file mode 100644 index 0000000..adf94b6 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/reinaldo/movies/Children.java @@ -0,0 +1,42 @@ +package org.fundacionjala.coding.reinaldo.movies; + +/** + * Created by Administrator on 3/21/2017. + */ +public class Children extends Movie { + private static final int LIMIT_NEW_CHILD = 3; + private static final double PRICE = 1.5; + private static final int NUMBER_RENTAL_DAYS = 1; + + /** + * * This is the constructor of Children class. + * + * @param title title + */ + Children(final String title) { + + super(title); + } + + /** + * This is the calculateAmount of Children movie. + * {@inherentDoc} + */ + @Override + public double calculateAmount(final int daysRented) { + double amount = PRICE; + if (daysRented > LIMIT_NEW_CHILD) { + amount += (daysRented - LIMIT_NEW_CHILD) * PRICE; + } + return amount; + } + + /** + * This is the calculateFrequentRenterPoints of Children movie. + * {@inherentDoc} + */ + @Override + public int calculateFrequentRenterPoints(final int daysRented) { + return NUMBER_RENTAL_DAYS; + } +} diff --git a/src/main/java/org/fundacionjala/coding/reinaldo/movies/Customer.java b/src/main/java/org/fundacionjala/coding/reinaldo/movies/Customer.java new file mode 100644 index 0000000..a4ebd44 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/reinaldo/movies/Customer.java @@ -0,0 +1,76 @@ +package org.fundacionjala.coding.reinaldo.movies; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Administrator on 3/21/2017. + */ +public class Customer { + + private String nameCustomer; + private List rentalsCustomer; + + /** + * @param nameCustomer String with name of Customer. + * Constructor of the Customer Class. + */ + Customer(final String nameCustomer) { + this.nameCustomer = nameCustomer; + rentalsCustomer = new ArrayList<>(); + } + /** + * Takes a rental, and add to list rental same rental object passed as parameter. + * @param rental String with rental of movie. + */ + void addRental(final Rental rental) { + rentalsCustomer.add(rental); + } + + /** + * @return the nameCustomer string. + */ + String getName() { + return this.nameCustomer; + } + + /** + * returns a string generate Detail about retail a movie with respective customer. + * + * @return the generateDetail string, but with Rental Record for,Amount owed is,You earned. + */ + 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() + "\n"); + } + result.append("Amount owed is ").append(calculateTotalAmount()).append("\n"); + result.append("You earned ").append(calculateTotalFrequentRenterPoints()).append(" frequent renter points"); + return result.toString(); + } + + /** + * returns a double Amount owed of retail movie. + * + * @return the calculateTotalAmount double. + */ + double calculateTotalAmount() { + + return rentalsCustomer.stream() + .mapToDouble(Rental::calculateAmount) + .sum(); + } + + /** + * returns a int Total Frequent Retail Points owed of retail movie. + * + * @return the calculateTotalFrequentRenterPoints int. + */ + private int calculateTotalFrequentRenterPoints() { + return rentalsCustomer.stream() + .mapToInt(Rental::calculateFrequentRenterPoint) + .sum(); + } +} diff --git a/src/main/java/org/fundacionjala/coding/reinaldo/movies/Movie.java b/src/main/java/org/fundacionjala/coding/reinaldo/movies/Movie.java new file mode 100644 index 0000000..fa36df7 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/reinaldo/movies/Movie.java @@ -0,0 +1,42 @@ +package org.fundacionjala.coding.reinaldo.movies; + +/** + * Created by Administrator on 3/21/2017. + */ +public abstract class Movie { + private String title; + + /** + * This is the constructor of Movie class. + * + * @param title String with title for Movie movie. + */ + Movie(final String title) { + this.title = title; + } + + /** + * This is an abstract method. + * + * @param daysRented int with daysRented. + * @return calculateAmount movie + */ + public abstract double calculateAmount(int daysRented); + + /** + * This is an abstract method. + * + * @param daysRented int with daysRented. + * @return calculateFrequentRenterPoints movie + */ + public abstract int calculateFrequentRenterPoints(int daysRented); + + /** + * This is an abstract method. + * + * @return getTitle movie. + */ + String getTitle() { + return title; + } +} diff --git a/src/main/java/org/fundacionjala/coding/reinaldo/movies/NewRelease.java b/src/main/java/org/fundacionjala/coding/reinaldo/movies/NewRelease.java new file mode 100644 index 0000000..59b8d73 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/reinaldo/movies/NewRelease.java @@ -0,0 +1,44 @@ +package org.fundacionjala.coding.reinaldo.movies; + +/** + * Created by Administrator on 3/21/2017. + */ +public class NewRelease extends Movie { + + private static final int LIMIT_NEW_CHILD = 3; + + private static final int NUMBER_ONE = 1; + + private static final int NUMBER_TWO = 2; + + /** + * This is the constructor of NewRelease class. + * + *{@inherentDoc} + * @param title String with title for NewRelease. + */ + NewRelease(final String title) { + + super(title); + } + + /** + * This is the calculateFrequentRenterPoints of NewRelease movie. + *{@inherentDoc} + * @param daysRented String with daysRented for NewRelease movie. + */ + @Override + public double calculateAmount(final int daysRented) { + return daysRented * LIMIT_NEW_CHILD; + } + + /** + * This is the calculateFrequentRenterPoints of NewRelease movie. + *{@inherentDoc} + * @param daysRented String with daysRented for NewRelease movie. + */ + @Override + public int calculateFrequentRenterPoints(final int daysRented) { + return daysRented > NUMBER_ONE ? NUMBER_TWO : NUMBER_ONE; + } +} diff --git a/src/main/java/org/fundacionjala/coding/reinaldo/movies/Regular.java b/src/main/java/org/fundacionjala/coding/reinaldo/movies/Regular.java new file mode 100644 index 0000000..8784ae7 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/reinaldo/movies/Regular.java @@ -0,0 +1,47 @@ +package org.fundacionjala.coding.reinaldo.movies; + +/** + * Created by Administrator on 3/21/2017. + */ +public class Regular extends Movie { + + private static final double PRICE = 1.5; + + private static final int LIMIT_REGULAR = 2; + private static final int RESUL_FREQUENT_NUMBER = 1; + + /** + * This is the constructor of Regular class. + *{@inherentDoc} + * @param title String with title for Regular. + */ + Regular(final String title) { + + super(title); + } + + /** + * This is the calculateAmount of Regular movie. + *{@inherentDoc} + * @param daysRented String with daysRented for Regular movie. + */ + @Override + public double calculateAmount(final int daysRented) { + double amount = LIMIT_REGULAR; + if (daysRented > LIMIT_REGULAR) { + amount += (daysRented - LIMIT_REGULAR) * PRICE; + } + return amount; + } + + /** + * This is the calculateFrequentRenterPoints of Regular movie. + *{@inherentDoc} + * @param daysRented String with daysRented for Regular movie. + */ + @Override + public int calculateFrequentRenterPoints(final int daysRented) { + + return RESUL_FREQUENT_NUMBER; + } +} diff --git a/src/main/java/org/fundacionjala/coding/reinaldo/movies/Rental.java b/src/main/java/org/fundacionjala/coding/reinaldo/movies/Rental.java new file mode 100644 index 0000000..7c17f77 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/reinaldo/movies/Rental.java @@ -0,0 +1,40 @@ +package org.fundacionjala.coding.reinaldo.movies; + +/** + * 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 movie object. + */ + Movie getMovie() { + return this.movie; + } + + /** + * @return price object. + */ + double calculateAmount() { + return movie.calculateAmount(daysRented); + } + + /** + * @return calculateFrequentRenterPoint int. + */ + int calculateFrequentRenterPoint() { + return movie.calculateFrequentRenterPoints(daysRented); + } +} + diff --git a/src/main/java/org/fundacionjala/coding/reinaldo/multiplesOf3And5/MultiplesOf3And5.java b/src/main/java/org/fundacionjala/coding/reinaldo/multiplesOf3And5/MultiplesOf3And5.java new file mode 100644 index 0000000..6478f59 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/reinaldo/multiplesOf3And5/MultiplesOf3And5.java @@ -0,0 +1,31 @@ +package org.fundacionjala.coding.reinaldo.multiplesOf3And5; + +import java.util.stream.IntStream; + +/** + * Created by Administrator on 6/30/2017. + */ +final class MultiplesOf3And5 { + private static final int NUMBERTHREE = 3; + private static final int NUMBERFIVE = 5; + + /** + * This is the constructor MultiplesOf3And5 class. + */ + private MultiplesOf3And5() { + + } + + /** + * This is the method return a int number. + * + * @param number getSolution + * @return int getSolution + */ + static int getSolution(final int number) { + + return IntStream.range(NUMBERTHREE, number) + .filter(num -> num % NUMBERTHREE == 0 || num % NUMBERFIVE == 0) + .sum(); + } +} diff --git a/src/main/java/org/fundacionjala/coding/reinaldo/wordDescent/WordDescent.java b/src/main/java/org/fundacionjala/coding/reinaldo/wordDescent/WordDescent.java new file mode 100644 index 0000000..1260695 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/reinaldo/wordDescent/WordDescent.java @@ -0,0 +1,49 @@ +package org.fundacionjala.coding.reinaldo.wordDescent; + +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * Created by Administrator on 6/30/2017. + */ +public final class WordDescent { + + private static final int WORD_LIMIT = 3; + + /** + * This a constructor of wordDescent. + */ + private WordDescent() { + + } + + /** + * This Method retorn the word invert. + * + * @param sentence all the Word + * @return String word invert + */ + public static String getWordDescent(final String sentence) { + return Stream.of(sentence.split(" ")) + .map(word -> word.length() < WORD_LIMIT ? word : invertString(word)) + .collect(Collectors.joining(" ")); + + } + + /** + * This is a method for to invert each word of the list. + * + * @param words only the Word + * @return String word invert + */ + private static String invertString(final String words) { + + String wordInvert = new StringBuilder( + words.substring(1, words.length() - 1)).reverse().toString(); + + + return String.format("%s%s%s", Character.toString( + words.charAt(0)), wordInvert, Character.toString(words.charAt(words.length() - 1))); + } + +} diff --git a/src/test/java/org/fundacionjala/coding/reinaldo/average/AverageTest.java b/src/test/java/org/fundacionjala/coding/reinaldo/average/AverageTest.java new file mode 100644 index 0000000..690220d --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/reinaldo/average/AverageTest.java @@ -0,0 +1,115 @@ +package org.fundacionjala.coding.reinaldo.average; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.Arrays; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Created by Administrator on 6/30/2017. + */ +public class AverageTest { + + /** + * This verify test Calculate Average When The Array Have FiveElements. + */ + @Test + public void testCalculateAverageWhenTheArrayHaveFiveElements() { + // given: + final int[] sentece = {2, 2, 2, 2, 2}; + + // when: + final double[] actualResultOne = Average.averagesCalculate(sentece); + + // then: + final double[] expectedResultOne = {2.0, 2.0, 2.0, 2.0}; + assertEquals(Arrays.toString(expectedResultOne), Arrays.toString(actualResultOne)); + + // given: + final int[] sentence = {1, 3, 5, 1, -10}; + + // when: + final double[] actualResultTwo = Average.averagesCalculate(sentence); + + // then: + final double[] expectedResultTwo = {2.0, 4.0, 3.0, -4.5}; + assertEquals(Arrays.toString(expectedResultTwo), Arrays.toString(actualResultTwo)); + + // given: + final int[] setence = {2, -2, 2, -2, 2}; + + // when: + final double[] actualResultThree = Average.averagesCalculate(setence); + + // then: + final double[] expectedResultThree = {0.0, 0.0, 0.0, 0.0}; + assertEquals(Arrays.toString(expectedResultThree), Arrays.toString(actualResultThree)); + + } + + /** + * This verify test Calculate Average When The Array Is Null. + */ + @Test + public void testCalculateAverageWhenTheArrayIsNull() { + // given: + final int[] sentence = null; + + // when: + final double[] actualResult = Average.averagesCalculate(sentence); + + // then: + final double[] expectedResult = {}; + assertEquals(Arrays.toString(expectedResult), Arrays.toString(actualResult)); + } + + /** + * This test verify Calculate Average When The Array Is Empty. + */ + @Test + public void testCalculateAverageWhenTheArrayIsEmpty() { + // give: + final int[] setence = {}; + + // when: + final double[] actualResult = Average.averagesCalculate(setence); + + // then: + final double[] expectedResult = {}; + + assertEquals(Arrays.toString(expectedResult), Arrays.toString(actualResult)); + } + + /** + * This test verify Calculate Average When The Array Has Only One Element. + */ + @Test + public void testCalculateAverageWhenTheArrayHasOnlyOneElement() { + // given: + final int[] setence = {2}; + + // when: + final double[] actualResult = Average.averagesCalculate(setence); + + // then: + final double[] expectedResult = {}; + assertEquals(Arrays.toString(expectedResult), Arrays.toString(actualResult)); + } + + /** + * Test constructor. + * + * @throws Exception construct + */ + @Test + public void testConstructorIsPrivate() throws Exception { + Constructor constructor = Average.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/src/test/java/org/fundacionjala/coding/reinaldo/ean/EanTest.java b/src/test/java/org/fundacionjala/coding/reinaldo/ean/EanTest.java new file mode 100644 index 0000000..9d64560 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/reinaldo/ean/EanTest.java @@ -0,0 +1,56 @@ +package org.fundacionjala.coding.reinaldo.ean; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Created by Administrator on 6/30/2017. + */ +public class EanTest { + + /** + * Test when checksum isn't 0. + */ + @Test + public void testEanWenTheChecksumIsNotZero() { + // given: + final String sentence = "4003301018398"; + + // when: + final boolean actualResult = Ean.validate(sentence); + + assertTrue(actualResult); + } + + /** + * Test when checksum is equal to 0. + */ + @Test + public void testEanWhenTheCheckSumIsEqualToZero() { + // given: + final String eanStringNumber = "4003301018392"; + + // when: + final boolean actualResult = Ean.validate(eanStringNumber); + + assertFalse(actualResult); + } + + /** + * Test constructor. + * + * @throws Exception construct + */ + @Test + public void testConstructorIsPrivate() throws Exception { + Constructor constructor = Ean.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/src/test/java/org/fundacionjala/coding/reinaldo/evaporator/EvaporatorTest.java b/src/test/java/org/fundacionjala/coding/reinaldo/evaporator/EvaporatorTest.java new file mode 100644 index 0000000..7ddacbe --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/reinaldo/evaporator/EvaporatorTest.java @@ -0,0 +1,93 @@ +package org.fundacionjala.coding.reinaldo.evaporator; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Created by Administrator on 6/30/2017. + */ +public class EvaporatorTest { + /** + * The testEvaporatorOne test. + */ + @Test + public void testEvaporatorOne() { + assertEquals(22, Evaporator.evaporator(10, 10, 10)); + } + + /** + * the testEvaporatorTwo test. + */ + @Test + public void testEvaporatorTwo() { + assertEquals(29, Evaporator.evaporator(10, 10, 5)); + } + + /** + * The testEvaporatorthree test. + */ + @Test + public void testEvaporatorThree() { + assertEquals(59, Evaporator.evaporator(100, 5, 5)); + } + + /** + * The testEvaporatorFour test. + */ + @Test + public void testEvaporatorFour() { + assertEquals(37, Evaporator.evaporator(50, 12, 1)); + } + + /** + * The estEvaporatorFive test. + */ + @Test + public void testEvaporatorFive() { + assertEquals(31, Evaporator.evaporator(47.5, 8, 8)); + } + + /** + * The testEvaporatorSix test. + */ + @Test + public void testEvaporatorSix() { + assertEquals(459, Evaporator.evaporator(100, 1, 1)); + } + + /** + * The testEvaporatorSeven test. + */ + @Test + public void testEvaporatorSeven() { + assertEquals(459, Evaporator.evaporator(10, 1, 1)); + } + + /** + * The testEvaporatorEight test. + */ + @Test + public void testEvaporatorEight() { + assertEquals(299, Evaporator.evaporator(100, 1, 5)); + } + + /** + * Test constructor. + * + * @throws Exception construct + */ + @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/reinaldo/highestAndLowestTest/HighestAndLowestTest.java b/src/test/java/org/fundacionjala/coding/reinaldo/highestAndLowestTest/HighestAndLowestTest.java new file mode 100644 index 0000000..e0ee144 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/reinaldo/highestAndLowestTest/HighestAndLowestTest.java @@ -0,0 +1,184 @@ +package org.fundacionjala.coding.reinaldo.highestAndLowestTest; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Created by Administrator on 6/30/2017. + */ +public class HighestAndLowestTest { + + /** + * 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); + } + + /** + * Test constructor. + * + * @throws Exception construct + */ + @Test + public void testConstructorIsPrivate() throws Exception { + Constructor constructor = HighestAndLowest.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + +} diff --git a/src/test/java/org/fundacionjala/coding/reinaldo/kataBankOcr/BankOcrKataTest.java b/src/test/java/org/fundacionjala/coding/reinaldo/kataBankOcr/BankOcrKataTest.java new file mode 100644 index 0000000..3d057db --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/reinaldo/kataBankOcr/BankOcrKataTest.java @@ -0,0 +1,149 @@ +package org.fundacionjala.coding.reinaldo.kataBankOcr; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Created by reinaldo on 08/07/2017. + */ +public class BankOcrKataTest { + + /** + * Test if testBankOcrWhenScannedNumbersOneToNine. + */ + @Test + public void testBankOcrWhenScannedNumbersOneToNine() { + // given: + List insertLineFour = new ArrayList(); + insertLineFour.add(" _ _ _ _ _ _ _ "); + insertLineFour.add(" | _| _||_||_ |_ ||_||_|"); + insertLineFour.add(" ||_ _| | _||_| ||_| _|"); + insertLineFour.add(""); + + + // when: + final String actualResult = BankOcrKata.decode(insertLineFour); + + // then: + final String expectedResult = "123456789"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test if testBankOcrWhenScannedNumbersFiveIsErrorandEight. + */ + @Test + public void testBankOcrWhenScannedNumbersFiveIsErrorandEight() { + + // given: + List insertLineFour = new ArrayList(); + insertLineFour.add(" _ _ _ _ _ _ _ "); + insertLineFour.add(" | _| _||_| r |_ ||_7|_|"); + insertLineFour.add(" ||_ _| | _||_| ||_| _|"); + insertLineFour.add(""); + + // when: + final String actualResult = BankOcrKata.decode(insertLineFour); + + // then: + final String expectedResult = "1234?67?9"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test if testBankOcrWhenScannedNumbersFiveIsOk. + */ + @Test + public void testHistoryThreTwoChecksumWentTheOK() { + // given: + final String sentence = "457508000"; + + // when: + final String expectedResult = "OK"; + final String actualResult = BankOcrKata.codeCheck(sentence); + + assertEquals(expectedResult, actualResult); + } + + /** + * Test if testHistoryThreeWhenIsErr. + */ + @Test + public void testHistoryThreeWhenIsErr() { + // given: + final String sentence = "664371495"; + + // when: + final String expectedResult = "ERR"; + final String actualResult = BankOcrKata.codeCheck(sentence); + + assertEquals(expectedResult, actualResult); + } + + /** + * Test if testHistoryThreeWhenIsIll. + */ + @Test + public void testHistoryThreeWhenIsILL() { + // given: + final String sentence = "664371?95"; + + // when: + final String expectedResult = "ILL"; + final String actualResult = BankOcrKata.codeCheck(sentence); + + assertEquals(expectedResult, actualResult); + } + + /** + * Test if testBankOcrWhenScannedNumbersFiveIsErrorandEight. + */ + @Test + public void testHistoryTwoChecksumWentTheChecksumIsCero() { + // given: + final String sentence = "457508000"; + + // when: + final int expectedResult = 0; + final int actualResult = BankOcrKata.checkSumAcount(sentence); + + assertEquals(expectedResult, actualResult); + } + + /** + * Test if testBankOcrWhenScannedNumbersFiveIsErrorandEight. + */ + @Test + public void testHistoryTwoChecksumWentTheChecksumIsnotCero() { + // given: + final String sentence = "664371495"; + + // when: + final int expectedResult = 0; + final int actualResult = BankOcrKata.checkSumAcount(sentence); + + assertTrue(expectedResult != actualResult); + } + + /** + * Constructor test. + * + * @throws Exception Exception + */ + @Test + public void testConstructor() throws Exception { + Constructor kataConstructor = BankOcrKata.class.getDeclaredConstructor(); + Assert.assertTrue(Modifier.isPrivate(kataConstructor.getModifiers())); + kataConstructor.setAccessible(true); + kataConstructor.newInstance(); + } + +} diff --git a/src/test/java/org/fundacionjala/coding/reinaldo/movies/CustomerTest.java b/src/test/java/org/fundacionjala/coding/reinaldo/movies/CustomerTest.java new file mode 100644 index 0000000..ccb44f0 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/reinaldo/movies/CustomerTest.java @@ -0,0 +1,188 @@ +package org.fundacionjala.coding.reinaldo.movies; + +import org.junit.Before; +import org.junit.Test; + + +import static org.junit.Assert.assertEquals; + +/** + * Created by reinaldo on 11/03/2017. + */ +public class CustomerTest { + private Customer customer; + + /** + * This this inicialice. + */ + @Before + public void setup() { + customer = new Customer("Test"); + } + + /** + * Test Movie When NameCustomer Is Word. + */ + @Test + public void testMovieWhenNameCustomerIsWord() { + + // when: + final String actualResult = customer.getName(); + + // then: + final String expectedResult = "Test"; + + 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"), 1)); + + // when: + final double actualResult = customer.calculateTotalAmount(); + + // then: + final double expectedResult = 1.5; + + assertEquals(expectedResult, actualResult, 0); + } + + /** + * test Movie When Day Rented Is greater For Children. + */ + @Test + public void testMovieWhenDayRentedISGreaterForChildren() { + + customer.addRental(new Rental(new Children("The Revenant"), 4)); + + // when: + final double actualResult = customer.calculateTotalAmount(); + + // then: + final double expectedResult = 3.0; + + assertEquals(expectedResult, actualResult, 0); + } + + /** + * test Movie When Day Rented IS one Day Rented For NewRelease. + */ + @Test + public void testMovieWhenDayRentedIsOneDayRentedForNewRelease() { + + customer.addRental(new Rental(new NewRelease("The Revenant"), 1)); + + // when: + final double actualResult = customer.calculateTotalAmount(); + + // then: + final double expectedResult = 3.0; + + assertEquals(expectedResult, actualResult, 0); + } + + /** + * test Movie When Day Rented Is Less For Regular. + */ + + @Test + public void testMovieWhenDayRentedIsLessForRegular() { + + // given: + customer.addRental(new Rental(new Regular("The Revenant"), 1)); + + // when: + final double actualResult = customer.calculateTotalAmount(); + + // then: + final double expectedResult = 2; + + assertEquals(expectedResult, actualResult, 0); + } + + /** + * test Movie When Day Rented Is Greater For Regular. + */ + + @Test + public void testMovieWhenDayRentedIsGreaterForRegular() { + + // given: + customer.addRental(new Rental(new Regular("The Revenant"), 3)); + + // when: + final double actualResult = customer.calculateTotalAmount(); + + // then: + final double expectedResult = 3.5; + + assertEquals(expectedResult, actualResult, 0); + } + + /** + * test Movie When Result Report Detail. + */ + + @Test + public void testMovieWhenResultReportDetail() { + + // given: + customer.addRental(new Rental(new Regular("The Revenant"), 3)); + + // when: + final String actualResult = customer.generateDetail(); + + // then: + final String expectedResult = "Rental Record for Test\n" + + "\tThe Revenant\t3.5\n" + + "Amount owed is 3.5\n" + + "You earned 1 frequent renter points"; + + assertEquals(expectedResult, actualResult); + } + + /** + * test Movie When Result Report children. + */ + @Test + public void testMovieWhenCalculateFrequentRenterPoints() { + //given + Movie movie = new Children("fantacy"); + int resul = movie.calculateFrequentRenterPoints(1); + assertEquals(1, resul); + + } + + /** + * this method CalculatecFrequentRenterPoints. + */ + @Test + public void testMovieWhenIsMajorCalculatecFrequentRenterPoints() { + //given + Movie movie = new NewRelease("fantacy"); + int resul = movie.calculateFrequentRenterPoints(5); + assertEquals(2, resul); + + } + + /** + * this method CalculatecFrequentRenterPoints. + */ + @Test + public void testMovieWhenIsOneCalculatecFrequentRenterPoints() { + //given + Movie movie = new NewRelease("fantacy"); + final int resul = movie.calculateFrequentRenterPoints(1); + assertEquals(1, resul); + + } + +} + diff --git a/src/test/java/org/fundacionjala/coding/reinaldo/multiplesOf3And5/MultiplesOf3And5Test.java b/src/test/java/org/fundacionjala/coding/reinaldo/multiplesOf3And5/MultiplesOf3And5Test.java new file mode 100644 index 0000000..d8c9a68 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/reinaldo/multiplesOf3And5/MultiplesOf3And5Test.java @@ -0,0 +1,71 @@ +package org.fundacionjala.coding.reinaldo.multiplesOf3And5; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Created by Administrator on 6/30/2017. + */ +public class MultiplesOf3And5Test { + + /** + * The method verifies expectedResult = 23. + */ + @Test + public void testGetSolutionWhenNumberPassedIs10() { + final int numberLimit = 10; + + final int actualResult = MultiplesOf3And5.getSolution(numberLimit); + + final int expectedResult = 23; + + assertEquals(expectedResult, actualResult); + } + + /** + * The method verifies expectedResult = 78. + */ + @Test + public void testGetSolutionWhenNumberPassedIs20() { + final int numberLimit = 20; + + final int actualResult = MultiplesOf3And5.getSolution(numberLimit); + + final int expectedResult = 78; + + assertEquals(expectedResult, actualResult); + } + + /** + * The method verifies expectedResult = 9168. + */ + @Test + public void testGetSolutionWhenNumberPassedIs200() { + + final int numberLimit = 200; + + final int actualResult = MultiplesOf3And5.getSolution(numberLimit); + + final int expectedResult = 9168; + + assertEquals(expectedResult, actualResult); + } + + /** + * Test constructor. + * + * @throws Exception construct + */ + @Test + public void testConstructorIsPrivate() throws Exception { + Constructor constructor = MultiplesOf3And5.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/src/test/java/org/fundacionjala/coding/reinaldo/wordDescent/WordDescentTest.java b/src/test/java/org/fundacionjala/coding/reinaldo/wordDescent/WordDescentTest.java new file mode 100644 index 0000000..b138e72 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/reinaldo/wordDescent/WordDescentTest.java @@ -0,0 +1,78 @@ +package org.fundacionjala.coding.reinaldo.wordDescent; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Created by Administrator on 6/30/2017. + */ +public class WordDescentTest { + + /** + * Test when WordDescentTest change Word. + */ + @Test + public void testchangeWord() { + + // given: + final String sentence = "wait for me"; + + // when: + final String actualResult = WordDescent.getWordDescent(sentence); + + // then: + final String expectedResult = "wiat for me"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test when WordDescentTest testchange Word Two. + */ + @Test + public void testchangeWordTwo() { + + // given: + final String sentence = "sort the iennr cennott in dcdeeinnsg order"; + + // when: + final String actualResult = WordDescent.getWordDescent(sentence); + + // then: + final String expectedResult = "srot the inner ctonnet in dsnnieedcg oedrr"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test when WordDescentTest testchange Word Three. + */ + @Test + public void testchangeWordThree() { + // given: + final String sentence = "this kata is easy"; + + // when: + final String actualResult = WordDescent.getWordDescent(sentence); + + // then: + final String expectedResult = "tihs ktaa is esay"; + assertEquals(expectedResult, actualResult); + } + + /** + * Test constructor. + * + * @throws Exception construct + */ + @Test + public void testConstructorIsPrivate() throws Exception { + Constructor constructor = WordDescent.class.getDeclaredConstructor(); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +}