diff --git a/lesson06/.idea/.gitignore b/lesson06/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/lesson06/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/lesson06/.idea/compiler.xml b/lesson06/.idea/compiler.xml new file mode 100644 index 0000000..6ee2e66 --- /dev/null +++ b/lesson06/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/lesson06/.idea/misc.xml b/lesson06/.idea/misc.xml new file mode 100644 index 0000000..66fa915 --- /dev/null +++ b/lesson06/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/lesson06/.idea/vcs.xml b/lesson06/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/lesson06/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lesson06/lesson06.iml b/lesson06/lesson06.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/lesson06/lesson06.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/lesson06/pom.xml b/lesson06/pom.xml new file mode 100644 index 0000000..043c159 --- /dev/null +++ b/lesson06/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + + 1.8 + 1.8 + + + + org.example + lesson06 + 1.0-SNAPSHOT + + + + org.junit.jupiter + junit-jupiter + 5.6.2 + test + + + + + \ No newline at end of file diff --git a/lesson06/src/Geekbrains/Main.java b/lesson06/src/Geekbrains/Main.java new file mode 100644 index 0000000..95b9fb8 --- /dev/null +++ b/lesson06/src/Geekbrains/Main.java @@ -0,0 +1,13 @@ +package Geekbrains; + +import java.util.logging.LogManager; +import java.util.logging.Logger; + +public class Main { + + private static final Logger LOGGER = LogManager.getLogManager(MainApp.); + + public static void main(String[] args) { + + } +} diff --git a/lesson06/src/main/java/ArrayTestClass.java b/lesson06/src/main/java/ArrayTestClass.java new file mode 100644 index 0000000..f5437fc --- /dev/null +++ b/lesson06/src/main/java/ArrayTestClass.java @@ -0,0 +1,55 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class ArrayTestClass { + public String arrayAfterFour(int[] array) { + List listOfInt = new ArrayList(); + int[] newArrayAfterFour = new int[0]; + boolean checkFour = false; + // проходим по всем элементам массива + for (int i = 0; i < array.length; i++) { + // если есть четверки + if (array[i] == 4) { + // то создаем новый array + newArrayAfterFour = new int[array.length - (i + 1)]; + for (int j = 0, a = i; j < newArrayAfterFour.length; a++, j++) { + // и заполняем его тем что справа от четверки + newArrayAfterFour[j] = array[a + 1]; + } + // если хоть раз зашли в условие, то флажок true + checkFour = true; + } + // и так проходим по всему массиву, создавая заново, newArrayAfterFour, хотя это наверное затратно + } + if (!checkFour) { + //если в массиве нет 4, то флажок false и сюда не заходим + throw new RuntimeException("нет 4"); + } + // для тестов удобнее чтобы метод возвратил строку +// System.out.println(Arrays.equals(arrayTestClass.arrayAfterFour(arrayOne),expectedArrayOne)); + String joinedString = Arrays.toString(newArrayAfterFour); + return joinedString; + } + + // Написать метод, который проверяет состав массива из чисел 1 и 4. Если в нем нет хоть одной четверки или единицы, то +// метод вернет false; Написать набор тестов для этого метода (по 3-4 варианта входных данных). + // корректно ли делать статик переменные в даном случае? + static boolean checkOne = false; + static boolean checkTwo = false; + public static boolean arrayOneFour(int[] array) { + + boolean checkFinal = (checkOne && checkTwo); + for (int i = 0; i + + + + logs + + + + + + + + + + + + + + + + + + + diff --git a/lesson06/src/test/java/Test.java b/lesson06/src/test/java/Test.java new file mode 100644 index 0000000..63718a3 --- /dev/null +++ b/lesson06/src/test/java/Test.java @@ -0,0 +1,74 @@ + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; + +import java.lang.reflect.Array; + + +class TestClass { + // Проверка: Тестовый массив + int[] arrayOne={3,5,4,5,4,4,5,67,8,6,5,4,3,56,67}; + + int[] arrayTwo={5,5,4,7,5,67,8,6,56,4,3,46,67}; + + int[] arrayThree={4,67}; + + + //2 задание + + int[] array1={7,4,67}; //- + int[] array2={1,67,8,};//- + int[] array3={1,4};//+ + + + // int[] checkedArrayToo={3,5,5,5,67,8,6,5,3,56,67}; + + + private ArrayTestClass arrayTestClass; + + @BeforeEach + public void init() { + arrayTestClass = new ArrayTestClass(); + } + + @Test + @Timeout(value = 100) + public void test1() { + Assertions.assertEquals("[3, 56, 67]", arrayTestClass.arrayAfterFour(arrayOne)); + } + @Test + @Timeout(value = 100) + public void test2() { + + Assertions.assertEquals("[3, 46, 67]", arrayTestClass.arrayAfterFour(arrayTwo)); + } + @Test + @Timeout(value = 100) + public void test3() { + Assertions.assertEquals("[67]", arrayTestClass.arrayAfterFour(arrayThree)); + } + + + @Test + public void test4(){ + Assertions.assertTrue(arrayTestClass.arrayOneFour(array1)); + // Assertions.assertArrayEquals(); + } + @Test + public void test5(){ + Assertions.assertTrue(arrayTestClass.arrayOneFour(array2)); + // Assertions.assertArrayEquals(); + } + @Test + public void test6(){ + Assertions.assertTrue(arrayTestClass.arrayOneFour(array3)); + // Assertions.assertArrayEquals(); + } + + + + + } + diff --git a/lesson06/target/classes/ArrayTestClass.class b/lesson06/target/classes/ArrayTestClass.class new file mode 100644 index 0000000..7a4d6f7 Binary files /dev/null and b/lesson06/target/classes/ArrayTestClass.class differ diff --git a/lesson06/target/classes/log4j2 b/lesson06/target/classes/log4j2 new file mode 100644 index 0000000..3547898 --- /dev/null +++ b/lesson06/target/classes/log4j2 @@ -0,0 +1,24 @@ + + + + + logs + + + + + + + + + + + + + + + + + + + diff --git a/lesson06/target/test-classes/TestClass.class b/lesson06/target/test-classes/TestClass.class new file mode 100644 index 0000000..83dfa93 Binary files /dev/null and b/lesson06/target/test-classes/TestClass.class differ