/
javapractice
/
JavaPractice
Обзор
Документация
Войти
/
javapractice
/
JavaPractice
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
2
CI/CD
Аналитика
develop
CodeRun/src/test/java/quickStart/QuickStartExercise08Test.java
139 строк
3 KB
Кузьма Даждъбогин
TSKJVPRCTC5-14
15 янв 2026, 15:13
15 янв 2026, 15:13
18b5c27
Код
Авторство
О чём код?
package quickStart; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.PrintStream; import java.nio.charset.StandardCharsets; import static org.junit.jupiter.api.Assertions.assertEquals; class QuickStartExercise08Test { private final InputStream systemIn = System.in; private final PrintStream systemOut = System.out; private ByteArrayInputStream testIn; private ByteArrayOutputStream testOut; @BeforeEach void setUp() { testOut = new ByteArrayOutputStream(); System.setOut(new PrintStream(testOut, true, StandardCharsets.UTF_8)); } @AfterEach void tearDown() { System.setIn(systemIn); System.setOut(systemOut); } void provideInput(String data) { testIn = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); System.setIn(testIn); } String getOutput() { return testOut.toString(StandardCharsets.UTF_8).trim(); } @Test void firstChance_shouldReturnYesForStrictlyIncreasingSequence() throws Exception { // Given provideInput("1 3 5 7"); // When QuickStartExercise08.firstChance(); // Then assertEquals("YES", getOutput()); } @Test void firstChance_shouldReturnNoForEqualElements() throws Exception { // Given provideInput("1 2 2 4"); // When QuickStartExercise08.firstChance(); // Then assertEquals("NO", getOutput()); } @Test void firstChance_shouldReturnNoForDecreasingSequence() throws Exception { // Given provideInput("5 4 3 2 1"); // When QuickStartExercise08.firstChance(); // Then assertEquals("NO", getOutput()); } @Test void firstChance_shouldHandleSingleElement() throws Exception { // Given provideInput("42"); // When QuickStartExercise08.firstChance(); // Then assertEquals("YES", getOutput()); } @Test void secondChance_shouldReturnYesForStrictlyIncreasingSequence() throws Exception { // Given provideInput("1 3 5 7"); // When QuickStartExercise08.secondChance(); // Then assertEquals("YES", getOutput()); } @Test void secondChance_shouldReturnNoForEqualElements() throws Exception { // Given provideInput("1 2 2 4"); // When QuickStartExercise08.secondChance(); // Then assertEquals("NO", getOutput()); } @Test void secondChance_shouldReturnNoForDecreasingSequence() throws Exception { // Given provideInput("5 4 3 2 1"); // When QuickStartExercise08.secondChance(); // Then assertEquals("NO", getOutput()); } @Test void secondChance_shouldHandleSingleElement() throws Exception { // Given provideInput("42"); // When QuickStartExercise08.secondChance(); // Then assertEquals("YES", getOutput()); } }