package uk.ac.aber.cs31920.assignment.tests.factories;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import uk.ac.aber.cs31920.assignment.implementation.datastructures.GraphNode;
import uk.ac.aber.cs31920.assignment.implementation.factories.GraphFactory;
import uk.ac.aber.cs31920.assignment.implementation.factories.GridFactory;
import uk.ac.aber.cs31920.assignment.implementation.datastructures.ProblemGrid;

public class GraphFactoryTests {
    @Test
    public void testGridProducesProblemGraph(){
        // arrange
        String input = "2\n00\n00\n";
        ProblemGrid grid = GridFactory.createGridFromString(input);

        // act
        GraphNode result = GraphFactory.createGraphFromProblemGrid(grid).source;

        // assert
        Assertions.assertEquals(2, result.getNetworkChildren().size());
        GraphNode node1 = result.getNetworkChildren().get(0);
        GraphNode node2 = result.getNetworkChildren().get(1);

        Assertions.assertEquals(2, node1.getNetworkChildren().size());
        GraphNode node3 = node1.getNetworkChildren().get(0);
        GraphNode node4 = node1.getNetworkChildren().get(1);

        Assertions.assertEquals(2, node2.getNetworkChildren().size());
        Assertions.assertTrue(node2.getNetworkChildren().contains(node3));
        Assertions.assertTrue(node2.getNetworkChildren().contains(node4));

        Assertions.assertEquals(1, node3.getNetworkChildren().size());
        Assertions.assertTrue(node3.getNetworkChildren().get(0).isSink());

        Assertions.assertEquals(1, node4.getNetworkChildren().size());
        Assertions.assertTrue(node4.getNetworkChildren().get(0).isSink());


    }

    @Test
    public void testGridWithBlockersProducesProblemGraph(){
        // arrange
        String input = "2\n10\n00\n";
        ProblemGrid grid = GridFactory.createGridFromString(input);

        // act
        GraphNode result = GraphFactory.createGraphFromProblemGrid(grid).source;

        // assert
        Assertions.assertEquals(1, result.getNetworkChildren().size());
        GraphNode node1 = result.getNetworkChildren().get(0);

        Assertions.assertEquals(2, node1.getNetworkChildren().size());
        GraphNode node2 = node1.getNetworkChildren().get(0);
        GraphNode node3 = node1.getNetworkChildren().get(1);

        Assertions.assertEquals(1, node2.getNetworkChildren().size());
        Assertions.assertTrue(node2.getNetworkChildren().get(0).isSink());

        Assertions.assertEquals(1, node3.getNetworkChildren().size());
        Assertions.assertTrue(node3.getNetworkChildren().get(0).isSink());




    }

}
