diff --git "a/src/main/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/CharMethods.java" "b/src/main/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/CharMethods.java" new file mode 100644 index 0000000..61e7c80 --- /dev/null +++ "b/src/main/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/CharMethods.java" @@ -0,0 +1,7 @@ +package Step1_학습테스트; + +public class CharMethods { + public char charAt(String string, int index) { + return string.charAt(index); + } +} diff --git "a/src/main/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/SetMethods.java" "b/src/main/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/SetMethods.java" new file mode 100644 index 0000000..3449768 --- /dev/null +++ "b/src/main/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/SetMethods.java" @@ -0,0 +1,10 @@ +package Step1_학습테스트; + +import java.util.Set; + +public class SetMethods { + public int getSize(Set set) { + return set.size(); + } + +} diff --git "a/src/main/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/StringMethods.java" "b/src/main/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/StringMethods.java" new file mode 100644 index 0000000..5f6335e --- /dev/null +++ "b/src/main/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/StringMethods.java" @@ -0,0 +1,11 @@ +package Step1_학습테스트; + +public class StringMethods { + public String[] splitStrings(String string) { + return string.split(""); + } + + public static String subString(String string, int a, int b) { + return string.substring(a,b); + } +} diff --git a/src/main/java/Step2_Calculator/ArithmeticOperation.java b/src/main/java/Step2_Calculator/ArithmeticOperation.java new file mode 100644 index 0000000..f0a53a9 --- /dev/null +++ b/src/main/java/Step2_Calculator/ArithmeticOperation.java @@ -0,0 +1,41 @@ +package Step2_Calculator; + +public class ArithmeticOperation { + + public static int arithmeticOperation(int acc, int curr, String arithmeticOperator) { + + if(arithmeticOperator.equals("+")){ + return sum(acc, curr); + } + + if(arithmeticOperator.equals("-")){ + return subtract(acc, curr); + } + + if(arithmeticOperator.equals("/")){ + return divide(acc, curr); + } + + if(arithmeticOperator.equals("*")){ + return multiply(acc, curr); + } + + return acc; + } + + private static int sum(int acc, int curr) { + return acc + curr; + } + + private static int divide(int acc, int curr) { + return acc / curr; + } + + private static int multiply(int acc, int curr) { + return acc * curr; + } + + private static int subtract(int acc, int curr) { + return acc - curr; + } +} diff --git a/src/main/java/Step2_Calculator/Calculator.java b/src/main/java/Step2_Calculator/Calculator.java new file mode 100644 index 0000000..7d3ed78 --- /dev/null +++ b/src/main/java/Step2_Calculator/Calculator.java @@ -0,0 +1,17 @@ +package Step2_Calculator; + +public class Calculator { + private int accumulator; + + public int calculate(String s) { + InputErrorHandler.checkCalculatorIllegalArgument(s); + String[] arithmetics = InputExtactor.extractCalculatorInputs(s); + + accumulator = Integer.parseInt(arithmetics[0]); + + for(int i = 1; i< arithmetics.length; i += 2) { + accumulator = ArithmeticOperation.arithmeticOperation(accumulator, Integer.parseInt(arithmetics[i+1]), arithmetics[i]); + } + return accumulator; + } +} diff --git a/src/main/java/Step2_Calculator/CalculatorApp.java b/src/main/java/Step2_Calculator/CalculatorApp.java new file mode 100644 index 0000000..3875721 --- /dev/null +++ b/src/main/java/Step2_Calculator/CalculatorApp.java @@ -0,0 +1,11 @@ +package Step2_Calculator; + +public class CalculatorApp { + public static void main(String[] args) { + InputView.startCalculator(); + String input = InputView.inputArithmeticOperations(); + Calculator calculator = new Calculator(); + int result = calculator.calculate(input); + OutputView.showOutput(result); + } +} diff --git a/src/main/java/Step2_Calculator/InputErrorHandler.java b/src/main/java/Step2_Calculator/InputErrorHandler.java new file mode 100644 index 0000000..bed5bb2 --- /dev/null +++ b/src/main/java/Step2_Calculator/InputErrorHandler.java @@ -0,0 +1,17 @@ +package Step2_Calculator; + +public class InputErrorHandler { + public static void checkCalculatorIllegalArgument(String s){ + String numbersToSingleLength = s.replaceAll("-?\\d+", "1"); + String noSpace = numbersToSingleLength.replaceAll(" ", ""); + if(numbersToSingleLength.length() != noSpace.length()*2-1) { + throw new IllegalArgumentException("Wrong input Format! Must be (number) (arithmetic Operator) (number) ... so on with no null inputs"); + } + + if(!s.matches("[\\d+*/\\-]+")){ + System.out.println("asdasdasd"); + throw new IllegalArgumentException("Wrong inputs!!!"); + } + + } +} diff --git a/src/main/java/Step2_Calculator/InputExtactor.java b/src/main/java/Step2_Calculator/InputExtactor.java new file mode 100644 index 0000000..6e137a1 --- /dev/null +++ b/src/main/java/Step2_Calculator/InputExtactor.java @@ -0,0 +1,7 @@ +package Step2_Calculator; + +public class InputExtactor { + public static String[] extractCalculatorInputs(String s) { + return s.split(" "); + } +} diff --git a/src/main/java/Step2_Calculator/InputView.java b/src/main/java/Step2_Calculator/InputView.java new file mode 100644 index 0000000..e81272d --- /dev/null +++ b/src/main/java/Step2_Calculator/InputView.java @@ -0,0 +1,16 @@ +package Step2_Calculator; + +import java.util.Scanner; + +public class InputView { + private static Scanner scanner; + + public static void startCalculator(){ + System.out.print("Input Arithmetic Operations : "); + } + public static String inputArithmeticOperations() { + scanner = new Scanner(System.in); + return scanner.nextLine(); + } + +} diff --git a/src/main/java/Step2_Calculator/OutputView.java b/src/main/java/Step2_Calculator/OutputView.java new file mode 100644 index 0000000..747a357 --- /dev/null +++ b/src/main/java/Step2_Calculator/OutputView.java @@ -0,0 +1,9 @@ +package Step2_Calculator; + +public class OutputView { + + public static void showOutput(int result) { + System.out.println("Result :" + result); + } + +} diff --git a/src/main/java/empty.txt b/src/main/java/empty.txt index e69de29..24c6c86 100644 --- a/src/main/java/empty.txt +++ b/src/main/java/empty.txt @@ -0,0 +1 @@ +ㄷㄱㅀㄴㄷㄹ \ No newline at end of file diff --git a/src/main/java/step3_racing_car/Car.java b/src/main/java/step3_racing_car/Car.java new file mode 100644 index 0000000..25661d5 --- /dev/null +++ b/src/main/java/step3_racing_car/Car.java @@ -0,0 +1,16 @@ +package step3_racing_car; + +import java.util.Random; + +public class Car { + + public static int move() { + return movable() ? 1 : 0; + } + + public static boolean movable() { + int randomNumber = RandomGenerator.generateNumber(10); + return randomNumber < 5 ? false : true; + } + +} diff --git a/src/main/java/step3_racing_car/CarList.java b/src/main/java/step3_racing_car/CarList.java new file mode 100644 index 0000000..5a69303 --- /dev/null +++ b/src/main/java/step3_racing_car/CarList.java @@ -0,0 +1,19 @@ +package step3_racing_car; + +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +public class CarList { + + public static String[] getNames(String carNames) { + return carNames.split(","); + } + + public static String[] getIndexNames(String[] carListNames, int[] winnersIndex) { + return IntStream.range(0, carListNames.length) + .filter(i -> IntStream.of(winnersIndex).anyMatch(x-> x== i)) + .mapToObj(i -> carListNames[i]) + .toArray(String[]::new); + } +} \ No newline at end of file diff --git a/src/main/java/step3_racing_car/InputView.java b/src/main/java/step3_racing_car/InputView.java new file mode 100644 index 0000000..8304b86 --- /dev/null +++ b/src/main/java/step3_racing_car/InputView.java @@ -0,0 +1,24 @@ +package step3_racing_car; + +import java.util.Scanner; + +public class InputView { + private static Scanner scanner; + public static int carAmount() { + System.out.println("자동차 대수는 몇 대 인가요?"); + scanner = new Scanner(System.in); + return scanner.nextInt(); + } + + public static String carNames() { + System.out.println("경주할 자동차 이름을 입력하세요(이름은 쉼표(,)를 기준으로 구분)."); + scanner = new Scanner(System.in); + return scanner.nextLine(); + } + + public static int loopCount() { + System.out.println("시도할 회수는 몇 회 인가요?"); + scanner = new Scanner(System.in); + return scanner.nextInt(); + } +} diff --git a/src/main/java/step3_racing_car/README.md b/src/main/java/step3_racing_car/README.md new file mode 100644 index 0000000..ac9c6cb --- /dev/null +++ b/src/main/java/step3_racing_car/README.md @@ -0,0 +1,26 @@ +기능을 구현하기 전에 README.md 파일에 구현할 기능 목록을 정리해 추가한다 + + +App +- RacingGame -> app controller + 1. inputView 자동차 대수는 몇 대 인가요? + a + 시도할 회수는 몇 회 인가요? + b + 출력(실행) + 2. input값 car 도메인에 전달. + +Domain +- car + 1. move(a,b) + 2. randomMove() +- carList + 1. getNames() + 2. getIndexNames() +- RaceCalculator + 1. calculateWinner + 2. calculateFurthestPosition + +UI +- InputView -> input 넣는 scanner +- ResultView -> 출력할 System.out의 문구들 \ No newline at end of file diff --git a/src/main/java/step3_racing_car/RaceCalculator.java b/src/main/java/step3_racing_car/RaceCalculator.java new file mode 100644 index 0000000..a87153a --- /dev/null +++ b/src/main/java/step3_racing_car/RaceCalculator.java @@ -0,0 +1,20 @@ +package step3_racing_car; + +import java.util.Arrays; +import java.util.stream.IntStream; + +public class RaceCalculator { + + public static int[] calculateWinner(int[] carPositions){ + int furthestPosition = calculateFurthestPosition(carPositions); + return IntStream.range(0, carPositions.length) + .filter(i -> furthestPosition == carPositions[i]) + .mapToObj(i->i) + .mapToInt(x -> x) + .toArray(); + } + + public static int calculateFurthestPosition(int[] carPositions) { + return Arrays.stream(carPositions).max().getAsInt(); + } +} diff --git a/src/main/java/step3_racing_car/RacingGame.java b/src/main/java/step3_racing_car/RacingGame.java new file mode 100644 index 0000000..e68616b --- /dev/null +++ b/src/main/java/step3_racing_car/RacingGame.java @@ -0,0 +1,38 @@ +package step3_racing_car; + +public class RacingGame { + private static int[] carPositions; + private static int time; + + public RacingGame(int[] carPositions, int time) { + this.carPositions = carPositions; + this.time = time; + } + + public static void main(String[] args) { + String carNames = InputView.carNames(); + String[] carListNames = CarList.getNames(carNames); + carPositions = new int[carListNames.length]; + time = InputView.loopCount(); + move(carListNames); + int[] winnersIndex = RaceCalculator.calculateWinner(carPositions); + String[] winnerList = CarList.getIndexNames(carListNames, winnersIndex); + ResultView.showWinner(winnerList); + } + + public static int[] move(String[] carListNames) { + ResultView.startMove(); + for(int j =0; j < time; j ++ ) { + changePosition(); + ResultView.carPositions(carPositions,carListNames); + } + return carPositions; + } + + public static void changePosition() { + for (int i = 0; i < carPositions.length; i++) { + carPositions[i] += Car.move(); + } + } + +} \ No newline at end of file diff --git a/src/main/java/step3_racing_car/RandomGenerator.java b/src/main/java/step3_racing_car/RandomGenerator.java new file mode 100644 index 0000000..d8e97e1 --- /dev/null +++ b/src/main/java/step3_racing_car/RandomGenerator.java @@ -0,0 +1,12 @@ +package step3_racing_car; + +import java.util.Random; + +public class RandomGenerator { + private static Random generator; + + public static int generateNumber(int max) { + generator = new Random(); + return generator.nextInt(max); + } +} diff --git a/src/main/java/step3_racing_car/ResultView.java b/src/main/java/step3_racing_car/ResultView.java new file mode 100644 index 0000000..9e8f0f4 --- /dev/null +++ b/src/main/java/step3_racing_car/ResultView.java @@ -0,0 +1,31 @@ +package step3_racing_car; + +public class ResultView { + public static void carPositions(int[] carPositions, String[] carListNames) { + System.out.println(); + for(int i = 0; i< carListNames.length; i ++) { + System.out.print(carListNames[i] + " : "); + printPosition(carPositions[i]); + System.out.println(); + } + } + + public static void printPosition(int position) { + for(int i = 0; i <= position; i ++) { + System.out.print("-"); + } + } + + public static void startMove() { + System.out.println("실행 결과"); + } + + public static void showWinner(String[] winnerList) { + for(String winner : winnerList) { + System.out.print(winner + " "); + } + System.out.println("(이)가 최종 우승했습니다."); + } + + +} diff --git "a/src/test/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/CharMethodsTest.java" "b/src/test/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/CharMethodsTest.java" new file mode 100644 index 0000000..34b5431 --- /dev/null +++ "b/src/test/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/CharMethodsTest.java" @@ -0,0 +1,51 @@ +package Step1_학습테스트; + +import Step1_학습테스트.CharMethods; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +@DisplayName("Char Methods 테스트") +public class CharMethodsTest { + private CharMethods charMethods; + @BeforeEach + void setUp() { + charMethods = new CharMethods(); + } + + @DisplayName("charAt 테스트") + @ParameterizedTest + @CsvSource(value = {"abc:0:a", "abc:1:b", "abc:2:c"}, delimiter = ':') + public void charIOTest(String string,int index, char expected) { + assertThat(charMethods.charAt(string, index)).isEqualTo(expected); + } + + @DisplayName("charAt Error Index out of bound 테스트") + @Test + public void charErrorTest() { + + assertThatThrownBy(() -> { + charMethods.charAt("abc", 3); + }).isInstanceOf(IndexOutOfBoundsException.class) + .hasMessageContaining("String index out of range: 3"); + +// Throwable thrown = catchThrowable(() -> { throw new Exception("String index out of range: 3"); }); +// assertThat(thrown).isInstanceOf(Exception.class) .hasMessageContaining("String index out of range: 3"); + + assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> charMethods.charAt("abc", 3)) + .withMessage("String index out of range: 3") + .withMessageContaining("String") + .withNoCause(); + +// assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> { throw new IndexOutOfBoundsException("NO!"); }) +// .withMessage("NO!") +// .withMessageContaining("NO") +// .withNoCause(); + + } +} diff --git "a/src/test/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/SetMethodsTest.java" "b/src/test/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/SetMethodsTest.java" new file mode 100644 index 0000000..30deb2b --- /dev/null +++ "b/src/test/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/SetMethodsTest.java" @@ -0,0 +1,61 @@ +package Step1_학습테스트; + +import Step1_학습테스트.SetMethods; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; +import static org.junit.jupiter.api.Assertions.assertTrue; + + +import java.util.HashSet; +import java.util.Set; + +import static org.assertj.core.api.Assertions.*; + +@DisplayName("set Method Test") +public class SetMethodsTest { + private Set numbers; + private SetMethods setMethods; + @BeforeEach + void setUp() { + setMethods = new SetMethods(); + numbers = new HashSet<>(); + numbers.add(1); + numbers.add(1); + numbers.add(2); + numbers.add(3); + } + + @DisplayName("set 사이즈 테스트") + @Test + public void setSizeTest() { + int setSize = setMethods.getSize(numbers); + assertThat(setSize).isEqualTo(3); + } + + @DisplayName("set 내용물 확인 테스트") + @ParameterizedTest + @ValueSource(ints = {1,1,2,3}) + public void setContainsTest(int number) { + assertThat(numbers.contains(number)).isTrue(); + } + +// @Test +// public void setThrowErrorTest() { +// assertThat(numbers.contains(true)).isEqualTo(false); +// assertThat(numbers.contains(4)).isEqualTo(false); +// assertThat(numbers.contains(5)).isEqualTo(false); +// } + + @DisplayName("set 입력 출력 테스트") + @ParameterizedTest + @CsvSource(value = {"1:true", "2:true", "3:true", "4:false", "5:false" }, delimiter = ':') + public void setIOTest(int input, boolean expected) { + assertThat(numbers.contains(input)).isEqualTo(expected); + + } + +} diff --git "a/src/test/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/StringMethodsTest.java" "b/src/test/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/StringMethodsTest.java" new file mode 100644 index 0000000..724a4d8 --- /dev/null +++ "b/src/test/java/Step1_\355\225\231\354\212\265\355\205\214\354\212\244\355\212\270/StringMethodsTest.java" @@ -0,0 +1,44 @@ +package Step1_학습테스트; + +import Step1_학습테스트.StringMethods; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; + +@DisplayName("String Method 테스트") +public class StringMethodsTest { + private StringMethods stringMethods; + + @BeforeEach + void setUp() { + stringMethods = new StringMethods(); + } + + @DisplayName("String split 테스트") + @Test + public void splitStringTest() { + String[] splittedString = stringMethods.splitStrings("12"); + assertThat(splittedString).contains("1","2"); + assertThat(splittedString).containsExactly("1","2"); + assertThat(splittedString).isEqualTo(new String[]{"1","2"}); + + String[] splittedString1 = stringMethods.splitStrings("1"); + assertThat(splittedString1).isEqualTo(new String[]{"1"}); + assertThat(splittedString1).contains("1"); + assertThat(splittedString1).containsExactly("1"); + + } + + @DisplayName("String subString 테스트") + @Test + public void subStringTest() { + String modifiedString = stringMethods.subString("(1,2)", 1,4); + assertThat(modifiedString).isEqualTo("1,2"); + assertThat(modifiedString).doesNotContain("("); + assertThat(modifiedString).doesNotContain(")"); + } +} + + diff --git a/src/test/java/Step2_Calculator/CalculatorTest.java b/src/test/java/Step2_Calculator/CalculatorTest.java new file mode 100644 index 0000000..cf02e0a --- /dev/null +++ b/src/test/java/Step2_Calculator/CalculatorTest.java @@ -0,0 +1,67 @@ +package Step2_Calculator; + +import Step2_Calculator.Calculator; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; + +import static org.assertj.core.api.Assertions.*; + +public class CalculatorTest { + private Calculator calculator; + + @BeforeEach + void setUp() { + calculator = new Calculator(); + } + + @DisplayName("test calculator") + @ParameterizedTest + @CsvSource(value = {"2 + 3 * 4 / 2:10", "1:1", "0 * 10 * 11 + 3: 3"}, delimiter = ':') + public void calculatorTestArithmeticOperations(String arithmetic, int result) { + assertThat(calculator.calculate(arithmetic)).isEqualTo(result); + } + + @DisplayName("null input") + @Test + public void calculatorTestWithNull() { + assertThatIllegalArgumentException().isThrownBy(() -> { + calculator.calculate("null"); + }); + } + + @DisplayName("wrong input") + @Test + public void calculatorTestWithWrongInput() { + assertThatIllegalArgumentException().isThrownBy(() -> { + calculator.calculate("!"); + }); + } + + @DisplayName("wrong format") + @Test + public void calculatorTestWithWrongFormat() { + assertThatIllegalArgumentException().isThrownBy(() -> { + calculator.calculate("4 + a"); + }); + } + + @DisplayName("space inputs") + @Test + public void calculatorTestWithSpaceInputs() { + assertThatIllegalArgumentException().isThrownBy(() -> { + calculator.calculate("4 + 1 * 2"); + }); + } + + @DisplayName("negative inputs") + @Test + public void calculatorTestWithNegativeInputs() { + assertThat(calculator.calculate("-4 - 1 * 2")).isEqualTo(-10); + } + + +} diff --git a/src/test/java/step3_racing_car/CarListTest.java b/src/test/java/step3_racing_car/CarListTest.java new file mode 100644 index 0000000..77b63cc --- /dev/null +++ b/src/test/java/step3_racing_car/CarListTest.java @@ -0,0 +1,24 @@ +package step3_racing_car; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CarListTest { + @Test + public void getNamesTest(){ + CarList carList = new CarList(); + assertThat( carList.getNames("a,b,c")).isEqualTo(new String[] {"a","b","c"}); + } + @Test + public void getIndexNamesTest(){ + CarList carList = new CarList(); + carList.getIndexNames(new String[] {"a","b"}, new int[] {1}); + assertThat(carList.getIndexNames(new String[] {"a","b", "c"}, new int[] {1})).isEqualTo(new String[] {"b"}); + } + + +} diff --git a/src/test/java/step3_racing_car/CarTest.java b/src/test/java/step3_racing_car/CarTest.java new file mode 100644 index 0000000..9bdaa2d --- /dev/null +++ b/src/test/java/step3_racing_car/CarTest.java @@ -0,0 +1,31 @@ +package step3_racing_car; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CarTest { + private Car car; + + @BeforeEach + void setUp() { + car = new Car(); + } + + @DisplayName("randomMoveable tests if movable returns true or false") + @Test + public void randomMovableTest() { + assertThat(car.movable()).isEqualTo(true||false); + } + + @DisplayName("randomMove returns 0 or 1") + @Test + public void randomMoveTest() { + assertTrue(car.move() == 1 || car.move() == 0); + } + + +} diff --git a/src/test/java/step3_racing_car/RaceCalculatorTest.java b/src/test/java/step3_racing_car/RaceCalculatorTest.java new file mode 100644 index 0000000..a5a4e0c --- /dev/null +++ b/src/test/java/step3_racing_car/RaceCalculatorTest.java @@ -0,0 +1,23 @@ +package step3_racing_car; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; + + +public class RaceCalculatorTest { + + @Test + public void calculateWinnerTest(){ + RaceCalculator raceCalculator = new RaceCalculator(); + assertThat(raceCalculator.calculateWinner(new int[] {4,5,6,6})).isEqualTo(new int[] {2,3}); + } + + @Test + public void calculateFurthestPosition() { + RaceCalculator raceCalculator = new RaceCalculator(); + assertThat(raceCalculator.calculateFurthestPosition(new int[] {4,5,6,6})).isEqualTo(6); + } + +} diff --git a/src/test/java/step3_racing_car/RacingGameTest.java b/src/test/java/step3_racing_car/RacingGameTest.java new file mode 100644 index 0000000..fff429e --- /dev/null +++ b/src/test/java/step3_racing_car/RacingGameTest.java @@ -0,0 +1,25 @@ +package step3_racing_car; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; + + +public class RacingGameTest { + private RacingGame racingGame; + + @BeforeEach + void setUp() { + racingGame = new RacingGame(new int[] {0,0,0,0,0}, 5); + } + + @DisplayName("if moved") + @Test + public void moveTest() { + assertTrue(racingGame.move(new String[] {}).length == 5); + } + +} diff --git a/src/test/java/step3_racing_car/RandomGeneratorTest.java b/src/test/java/step3_racing_car/RandomGeneratorTest.java new file mode 100644 index 0000000..9d9a463 --- /dev/null +++ b/src/test/java/step3_racing_car/RandomGeneratorTest.java @@ -0,0 +1,22 @@ +package step3_racing_car; + + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class RandomGeneratorTest { + private RandomGenerator randomGenerator; + + @BeforeEach + void setUp() { + randomGenerator = new RandomGenerator(); + } + + @Test + public void randomMoveTest() { + int generatedRandomIntNumber = randomGenerator.generateNumber(10); + assertTrue(generatedRandomIntNumber <= 10); + } + +} diff --git a/test b/test new file mode 100644 index 0000000..028e2d8 --- /dev/null +++ b/test @@ -0,0 +1 @@ +test pull request \ No newline at end of file