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/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/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/movies/Rental.java b/src/main/java/org/fundacionjala/coding/norman/movies/Rental.java new file mode 100644 index 0000000..9271f79 --- /dev/null +++ b/src/main/java/org/fundacionjala/coding/norman/movies/Rental.java @@ -0,0 +1,55 @@ +package org.fundacionjala.coding.norman.movies; + +/** + * Created by NORMAN on 2/7/2017. + */ + +class Rental { + private Movie movie; + private int 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; + this.daysRented = daysRented; + } + + /** + * Getter method to obtain days a movies was rented. + * + * @return movies days rented. + */ + public int getDaysRented() { + return daysRented; + } + + /** + * Getter method to obtain the movie information. + * + * @return the movie object. + */ + Movie getMovie() { + return 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/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/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/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..0aa25f9 --- /dev/null +++ b/src/test/java/org/fundacionjala/coding/norman/movies/NewReleaseTest.java @@ -0,0 +1,90 @@ +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 + * for a NewRelease movie is less than 3 e.g. 1 + */ + @Test + public void testCalculateAmountWhenTheRentedDaysIsLessThanThree() { + // given: + + // when: + final double actualResult = newReleaseInstance.calculateAmount(1); + + // then + final double expectedResult = 3; + assertTrue(expectedResult - actualResult == 0); + + } + + /** + * 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: + + // when: + final double actualResult = newReleaseInstance.calculateAmount(10); + + // then: + final double expectedResult = 30; + assertTrue(expectedResult - actualResult == 0); + } + + /** + * Test to verify the frequent renter points for a NewRelease movie + * is 1 for different rented days. + */ + @Test + public void testCalculateFrequentRenterPointsVerifyTheResultIsOne() { + // given: + + // 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); + } + + +}