package graph.test;


import graph.Graph;
import graph.GraphFactory;
import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;
import java.util.LinkedList;

import static org.junit.Assert.*;

/**
 * Created by Paweł Kopeć on 25.12.16.
 *
 * Tests for graph class.
 */
abstract public class GraphTest {

    protected GraphFactory.GRAPH_TYPES graphType;

    @Before
    abstract public void initGraphSubclass();

    @Test
    public void addRemoveEdge() {
        Graph graph = GraphFactory.getInstance(graphType, 5);
        graph.addEdge(4, 0);
        graph.addEdge(2, 3);
        graph.addEdge(1, 3);
        graph.addEdge(0, 3);

        assertTrue(graph.hasEdge(4, 0));
        assertTrue(graph.hasEdge(2, 3));
        assertTrue(graph.hasEdge(1, 3));
        assertTrue(graph.hasEdge(0, 3));

        assertFalse(graph.hasEdge(0, 1));
        assertFalse(graph.hasEdge(0, 2));
        assertFalse(graph.hasEdge(1, 2));
        assertFalse(graph.hasEdge(1, 4));
        assertFalse(graph.hasEdge(2, 4));
        assertFalse(graph.hasEdge(3, 4));

        assertEquals(graph.getVertices(), 5);
        assertEquals(graph.getEdges(), 4);

        graph.removeEdge(2, 3);
        graph.removeEdge(1, 3);
        graph.removeEdge(0, 3);

        assertTrue(graph.hasEdge(0, 4));

        assertFalse(graph.hasEdge(2, 3));
        assertFalse(graph.hasEdge(1, 3));
        assertFalse(graph.hasEdge(0, 3));
        assertFalse(graph.hasEdge(0, 1));
        assertFalse(graph.hasEdge(0, 2));
        assertFalse(graph.hasEdge(1, 2));
        assertFalse(graph.hasEdge(1, 4));
        assertFalse(graph.hasEdge(2, 4));
        assertFalse(graph.hasEdge(3, 4));

        assertEquals(graph.getVertices(), 5);
        assertEquals(graph.getEdges(), 1);
    }

    @Test
    public void getNeighbours() {
        Graph graph = GraphFactory.getInstance(graphType, 7);
        graph.addEdge(1, 2);
        graph.addEdge(4, 1);
        graph.addEdge(1, 6);
        graph.addEdge(1, 3);

        LinkedList<Integer> neighbours = graph.getNeighbours(1);
        neighbours.sort(Integer::compareTo);
        assertEquals(neighbours, new LinkedList<>(Arrays.asList(2, 3, 4, 6)));
    }

    @Test
    public void read() {
        String s = "5 4 0 3 2 3 1 3 4 3";
        Graph graph = GraphFactory.getInstanceFromString(graphType, s);

        assertTrue(graph.hasEdge(0, 3));
        assertTrue(graph.hasEdge(2, 3));
        assertTrue(graph.hasEdge(1, 3));
        assertTrue(graph.hasEdge(4, 3));

        assertFalse(graph.hasEdge(0, 1));
        assertFalse(graph.hasEdge(0, 2));
        assertFalse(graph.hasEdge(0, 4));
        assertFalse(graph.hasEdge(1, 2));
        assertFalse(graph.hasEdge(1, 4));
        assertFalse(graph.hasEdge(2, 4));


        assertEquals(graph.getVertices(), 5);
        assertEquals(graph.getEdges(), 4);
    }

}
@@ -164,16 +164,41 @@
 kedList;
+%0Aimport java.util.Random;
 %0A%0Aimport
@@ -480,14 +480,8 @@
  add
-Remove
 Edge
@@ -1170,16 +1170,242 @@
 s(), 4);
+%0A    %7D%0A%0A    @Test%0A    public void removeEdge() %7B%0A        Graph graph = GraphFactory.getInstance(graphType, 5);%0A        graph.addEdge(4, 0);%0A        graph.addEdge(2, 3);%0A        graph.addEdge(1, 3);%0A        graph.addEdge(0, 3);
 %0A%0A      
@@ -1499,50 +1499,8 @@
 );%0A%0A
-        assertTrue(graph.hasEdge(0, 4));%0A%0A
     
@@ -1629,85 +1629,233 @@
     
+%7D%0A%0A
     
-assertFalse(graph.hasEdge(0, 1));%0A        assertFalse(graph.hasEdge(0, 2)
+@Test%0A    public void getVertices() %7B%0A        Graph graph;%0A%0A        graph = GraphFactory.getInstance(graphType, 5);%0A        assertEquals(graph.getVertices(), 5);%0A%0A        graph = GraphFactory.getInstance(graphType, 432
 );%0A 
@@ -1871,33 +1871,97 @@
 sert
-F
+Equ
 als
-e
 (graph.
-hasEdge(1, 2)
+getVertices(), 432);%0A%0A        graph = GraphFactory.getInstance(graphType, 32
 );%0A 
@@ -1977,33 +1977,96 @@
 sert
-F
+Equ
 als
-e
 (graph.
-hasEdge(1, 4)
+getVertices(), 32);%0A%0A        graph = GraphFactory.getInstance(graphType, 15
 );%0A 
@@ -2082,125 +2082,481 @@
 sert
-F
+Equ
 als
-e
 (graph.
-hasEdge(2, 4)
+getVertices(), 15
 );%0A    
+%7D%0A%0A
     
-assertFalse(graph.has
+@Test%0A    public void getEdges() %7B%0A        Graph graph = GraphFactory.getInstance(graphType, 20);%0A%0A        graph.addEdge(3, 4);%0A        graph.add
 Edge(
-3
+12
 , 
+1
 4)
-);%0A%0A        assertEquals(graph.getVertices(), 5
+;%0A        graph.addEdge(0, 2);%0A        graph.addEdge(11, 7);%0A        graph.addEdge(5, 9);%0A        graph.addEdge(17, 12);%0A        graph.addEdge(14, 10);%0A        graph.addEdge(3, 9);%0A        graph.addEdge(2, 8);%0A        graph.addEdge(10, 19);%0A        graph.addEdge(19, 3
 );%0A
+%0A
     
@@ -2590,16 +2590,17 @@
 dges(), 
+1
 1);%0A    

Add unit tests to GraphTest.