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<String> asLists = Arrays.asList(one, two, three, four, five, six, seven);
        list = new LinkedList<>();
        list.addAll(asLists);
        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() {
        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<String> asLists = Arrays.asList(one, two, three, four, five, six, seven);
        List<String> list = new LinkedList<>();
        list.addAll(asLists);

        String[] checkList = {"K1", "K1/SK1", "K1/SK1/SSK1", "K1/SK1/SSK2", "K1/SK2", "K2", "K2/SK1", "K2/SK1/SSK1","K2/SK1/SSK2"};
        DirectoryOrganization dir = new DirectoryOrganization();
        list = dir.sortOrganization(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 LinkedList<>();
        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<String> asLists= Arrays.asList(one, two, three, four, five, six, seven);
        list.addAll(asLists);
        String[] checkList = {"K1", "K1/SK1", "K1/SK1/SSK1", "K1/SK1/SSK2", "K1/SK2", "K2", "K2/SK1", "K2/SK1/SSK1","K2/SK1/SSK2"};

        DirectoryOrganization dir = new DirectoryOrganization();
        list = dir.reverseSortOrganization(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));
    }
}


@@ -1529,27 +1529,8 @@
 = 0;
-%0A        int i = 0;
 %0A%0A  
@@ -1770,69 +1770,9 @@
 2%22;%0A
-        String eight = %22K2/SK1%22;%0A        String nine = %22K1%22;
 %0A
+
     
@@ -1937,32 +1937,36 @@
 );%0A%0A        
+List%3C
 String
-%5B%5D
+%3E
  checkList =
@@ -1955,36 +1955,52 @@
 tring%3E checkList
- = %7B
+One = Arrays.asList(
 %22K1%22, %22K1/SK1%22, 
@@ -2082,17 +2082,17 @@
 K1/SSK2%22
-%7D
+)
 ;%0A      
@@ -2142,32 +2142,92 @@
 Organization();%0A
+        Iterator%3CString%3E checkIt = checkListOne.iterator();%0A
         list = d
@@ -2319,17 +2319,17 @@
 heck
-List%5Bi++%5D
+It.next()
 )) %7B
@@ -2724,27 +2724,9 @@
  0;%0A
-        int i = 8;
 %0A
+
     
@@ -2963,69 +2963,8 @@
 K2%22;
-%0A        String eight = %22K2/SK1%22;%0A        String nine = %22K1%22;
 %0A%0A  
@@ -3089,16 +3089,20 @@
     
+List%3C
 String
-%5B%5D
+%3E
  che
@@ -3111,31 +3111,46 @@
 List
- = %7B%22K1%22, %22
+One = Arrays.asList(%22K2/S
 K1/S
-K1
+SK2
 %22, %22K
-1
+2
 /SK1
@@ -3163,50 +3163,50 @@
 , %22K
-1
+2
 /SK1
-/SSK2
 %22, %22
-K1/S
 K2%22, %22
+K1/S
 K2%22, %22K
-2
+1
 /SK1
+/SSK2
 %22, %22K
-2
+1
 /SK1
@@ -3216,24 +3216,84 @@
 K1%22,
+ 
 %22K
-2
+1
 /SK1
-/SSK2%22%7D;%0A
+%22,%22K1%22);%0A        Iterator%3CString%3E checkIt = checkListOne.iterator();
 %0A   
@@ -3470,17 +3470,17 @@
 heck
-List%5Bi--%5D
+It.next()
 )) %7B

add file for chapter_003_3.4.3