From fde16eb66e5b1e2c78dcb92d34ba2223f08f131d Mon Sep 17 00:00:00 2001 From: Vyaceslav Sv Date: Sun, 5 Jul 2020 15:59:25 +0300 Subject: [PATCH] first commit --- lesson06/.idea/.gitignore | 2 + lesson06/.idea/compiler.xml | 13 ++++ lesson06/.idea/misc.xml | 14 ++++ lesson06/.idea/vcs.xml | 6 ++ lesson06/lesson06.iml | 2 + lesson06/pom.xml | 27 +++++++ lesson06/src/Geekbrains/Main.java | 13 ++++ lesson06/src/main/java/ArrayTestClass.java | 55 ++++++++++++++ lesson06/src/main/resources/log4j2 | 24 ++++++ lesson06/src/test/java/Test.java | 74 +++++++++++++++++++ lesson06/target/classes/ArrayTestClass.class | Bin 0 -> 1396 bytes lesson06/target/classes/log4j2 | 24 ++++++ lesson06/target/test-classes/TestClass.class | Bin 0 -> 1862 bytes 13 files changed, 254 insertions(+) create mode 100644 lesson06/.idea/.gitignore create mode 100644 lesson06/.idea/compiler.xml create mode 100644 lesson06/.idea/misc.xml create mode 100644 lesson06/.idea/vcs.xml create mode 100644 lesson06/lesson06.iml create mode 100644 lesson06/pom.xml create mode 100644 lesson06/src/Geekbrains/Main.java create mode 100644 lesson06/src/main/java/ArrayTestClass.java create mode 100644 lesson06/src/main/resources/log4j2 create mode 100644 lesson06/src/test/java/Test.java create mode 100644 lesson06/target/classes/ArrayTestClass.class create mode 100644 lesson06/target/classes/log4j2 create mode 100644 lesson06/target/test-classes/TestClass.class 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 0000000000000000000000000000000000000000..7a4d6f794f2383d4a482d13d53ca7349f5a303d6 GIT binary patch literal 1396 zcmZuxU2hXd6g{(__GX=!z=r0l2{Zx6j%~i`LSoXQs7R3vmYRSBK@}Tk32U5nWN(1H zR{0b33GtE_9@%K%#cvt39X&o`AT$zg>9L6fnwu;D<8; zYG&f5fHvD)W>8PX54`K^t4m&M!Ch+5(_3lQ+{R6}<;(q^Qw#6=ZGm*|)EiL%#2zfr8v&DT*h%5Hc~dak>X>0ibttC_f?nbUX2jl9pD(#$sE#S?=@uy#ktWd zMc1-F5@9nAzzH^G7du!%LgLd($P&0}VAmnd`3QGKu7azc-GTU-hJs$sM(o5<+V-A( z3=Vf}FdXO1WU&aH*8;0ApxoMldQJVqx~`TqwWK?GZuc3!&N+I)e2TNVT}RjME=R|P zqnAv_$n(4}?-)79)b19lo2J+_#MZ}mT1nf~X}of@ACYH<(j;zy1>e zwW!D$@&HVhAUP(v>q0*{o}iT@!%K{s1_;R86&7;G$MD0c?Eoq&v<6w z90vIB=bbWhkd`j#A*L>^AqZlD3%SEHw{B2=J!NSv9>yQC-DVy$CxeUi{r-` ze~O+l7#|5>n6ONoHj&{h_y`{`BE)<2D}O`pW?d7=#zJF@nJP0cZX@voscj^mz|^*& zsb%%@P?k!LWQPjcQ#yY^f+jVWW^z-Zl5Yo}Ggpl?JIPwWdwZ$S047;+9^>qSNu1$7 zhZ4?5x{NaZ7+FXS6p0)$2lGxbD#f}alO7o9Z^Q>ELZmHL&C4ebT5Fs^@|RRu6Gu|E V7rzah<;N7fLBnZ!^0XBc{spdP4ch + + + + logs + + + + + + + + + + + + + + + + + + + diff --git a/lesson06/target/test-classes/TestClass.class b/lesson06/target/test-classes/TestClass.class new file mode 100644 index 0000000000000000000000000000000000000000..83dfa93dc65a223d971e6aaacc7e44065818ea37 GIT binary patch literal 1862 zcma)*?Q+{h6oy~fk|oPZtfaJ1D8-bII3|s0z8ab~sgovb}j4Kye zF2mh$2{1!x1{nVFhfClRxCo~2S;>hh&a|G{bN1|>ea`AV>%ac}^$!3G_}a!9EaWkX zMKMcau8LU}^O=}yCRS`%N!E1>HzZiKv4)!#Y8KWd-jMi~iA@t*8Z0l0yzd*KuOYLu zJ&2p%bv4*(t9cOl+{~%q%3v}#n9OS!PxAa;ywUM`Jq>QXCeY?!WrfMtgD{9!HDt@v zEe-lc_aULhdJy_|`j2=0sOjx?xH4Jq?s=V-7X=chi+X$z5L>7Z6LkSOBdn>;9u|xP_`<}tgWLEr z-C9Vt*oPgJQO8#f?x2yDAGA?!QSEr)ezmcC=kOW7pOh9Q+KWm>8#)}cFpeMK;zw%rCl&phkMn)zIEgyAgbx^L_>iYEq8zRv ztM;7AZ?M|Wk$(pJgl#hmBouh^gyW=~kGPlP>5mn2>X^BfGAAYrm7igAWPX8jgt3>w zQ@m<<2s|+aF0yo);As}9+{Pz#mq%0>Pb*|cSGddyv#(!ac0`3@T0tLOVU88%U%x{2 zxWX#GNZza~{QES<5!@q8ye!f(itN&f`tFcOqP~cv;nUN(xzXGk