package ru.job4j;

import java.util.*;

import org.junit.Test;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

/**
 * Testing Task 3.4.1
 * Create Directory oragnization
 *
 * @author Anton Vasilyuk
 * @version 1.0
 * @since 0.1
 */

public class DirectoryOrganizationTest {

    /**.
     * Testing method check all organization to array
     */
    @Test
    public void whenArrayNameOrganizationThenCheckAllElement() {
        List<String> list = new ArrayList<>();
        List<String> checkList = new ArrayList<>();
        String one = "K1/SK1";
        String two = "K1/SK2";
        String three = "K1/SK1/SSK1";
        String four = "K1/SK1/SSK2";
        String five = "K2";
        String six = "K2/SK1/SSK1";
        String seven = "K2/SK1/SSK2";
        String eight = "K2/SK1";
        String nine = "K1";
        list.add(one);
        list.add(two);
        list.add(three);
        list.add(four);
        list.add(five);
        list.add(six);
        list.add(seven);
        checkList.addAll(list);
        checkList.add(eight);
        checkList.add(nine);
        DirectoryOrganization dir = new DirectoryOrganization();
        list = dir.checkOrganization(list);

        boolean expect = true;
        boolean fact = false;
        if (list.containsAll(checkList)) {fact = true;}
        assertThat(fact, is(expect));
    }

    /**.
     * Test method natural sorting array organization
     */
    @Test
    public void whenArrayNameOrganizationThenSortArray() {
        List<String> list = new ArrayList<>();
        String[] checkList = new String[9];
        int num = 0;
        int i = 0;
        String one = "K1/SK1";
        String two = "K1/SK2";
        String three = "K1/SK1/SSK1";
        String four = "K1/SK1/SSK2";
        String five = "K2";
        String six = "K2/SK1/SSK1";
        String seven = "K2/SK1/SSK2";
        String eight = "K2/SK1";
        String nine = "K1";

        list.add(one);
        list.add(two);
        list.add(three);
        list.add(four);
        list.add(five);
        list.add(six);
        list.add(seven);

        checkList[0] = nine;
        checkList[1] = one;
        checkList[2] = three;
        checkList[3] = four;
        checkList[4] = two;
        checkList[5] = five;
        checkList[6] = eight;
        checkList[7] = six;
        checkList[8] = seven;

        DirectoryOrganization dir = new DirectoryOrganization();
        list = dir.checkOrganization(list);
        list = dir.sortOrganization(list);
        System.out.println(list);
        for (String s : list) {
            if (s.equals(checkList[i++])) {
            } else {num++;}
        }
        boolean expect = true;
        boolean fact = false;
        if (num == 0) {fact = true;}
        assertThat(fact, is(expect));
    }

    /**.
     * Testing reverse sort array organization
     */
    @Test
    public void whenArrayNameOrganizationThenReverseSortArray() {
        List<String> list = new ArrayList<>();
        String[] checkList = new String[9];
        int num = 0;
        int i = 8;
        String one = "K1/SK1";
        String two = "K1/SK2";
        String three = "K1/SK1/SSK1";
        String four = "K1/SK1/SSK2";
        String five = "K2";
        String six = "K2/SK1/SSK1";
        String seven = "K2/SK1/SSK2";
        String eight = "K2/SK1";
        String nine = "K1";

        list.add(one);
        list.add(two);
        list.add(three);
        list.add(four);
        list.add(five);
        list.add(six);
        list.add(seven);

        checkList[0] = nine;
        checkList[1] = one;
        checkList[2] = three;
        checkList[3] = four;
        checkList[4] = two;
        checkList[5] = five;
        checkList[6] = eight;
        checkList[7] = six;
        checkList[8] = seven;

        DirectoryOrganization dir = new DirectoryOrganization();
        list = dir.checkOrganization(list);
        list = dir.reverseSortOrganization(list);
        System.out.println(list);
        for (String s : list) {
            if (s.equals(checkList[i--])) {
            } else {num++;}
        }
        boolean expect = true;
        boolean fact = false;
        if (num == 0) {fact = true;}
        assertThat(fact, is(expect));
    }
}


@@ -1524,99 +1524,8 @@
 ) %7B%0A
-        List%3CString%3E list = new ArrayList%3C%3E();%0A        String%5B%5D checkList = new String%5B9%5D;%0A
     
@@ -1556,24 +1556,25 @@
  int i = 0;%0A
+%0A
         Stri
@@ -1857,33 +1857,32 @@
 ine = %22K1%22;%0A
-%0A
         
 list.add(one
@@ -1873,68 +1873,84 @@
     
-list.add(one);%0A        list.add(two);%0A        list.add(three
+List%3CString%3E asLists = Arrays.asList(one, two, three, four, five, six, seven
 );%0A 
@@ -1960,45 +1960,45 @@
     
-list.add(four);%0A        list.add(five
+List%3CString%3E list = new LinkedList%3C%3E(
 );%0A 
@@ -2008,39 +2008,47 @@
     list.add
-(six
+All(asLists
 );%0A
+%0A
         
 list.add(sev
@@ -2035,33 +2035,51 @@
         
-list.add(seven);%0A
+String%5B%5D checkList = new String%5B9%5D;
 %0A       
@@ -2402,52 +2402,8 @@
 ();%0A
-        list = dir.checkOrganization(list);%0A
     
@@ -2445,42 +2445,8 @@
 t);%0A
-        System.out.println(list);%0A
     
@@ -2645,32 +2645,33 @@
  %7Bfact = true;%7D%0A
+%0A
         assertTh
@@ -2863,37 +2863,38 @@
 ing%3E list = new 
-Array
+Linked
 List%3C%3E();%0A      
@@ -2891,52 +2891,8 @@
 ();%0A
-        String%5B%5D checkList = new String%5B9%5D;%0A
     
@@ -3240,116 +3240,83 @@
     
-list.add(one);%0A        list.add(two);%0A        list.add(three);%0A        list.add(four);%0A        list.add(fi
+List%3CString%3E asLists= Arrays.asList(one, two, three, four, five, six, se
 ve
+n
 );%0A 
@@ -3334,40 +3334,65 @@
 .add
-(six);%0A        list.add(seven);%0A
+All(asLists);%0A        String%5B%5D checkList = new String%5B9%5D;
 %0A   
@@ -3738,108 +3738,30 @@
 dir.
-checkOrganization(list);%0A        list = dir.reverseSortOrganization(list);%0A        System.out.printl
+reverseSortOrganizatio
 n(li

add file for chapter_003_3.4.3