/*-
 *  Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
 * 
 *  This file is part of CityDoctor2.
 *
 *  CityDoctor2 is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  CityDoctor2 is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with CityDoctor2.  If not, see <https://www.gnu.org/licenses/>.
 */
package de.hft.stuttgart.citydoctor2.math.graph;

import java.util.List;

import org.junit.Assert;
import org.junit.Test;

import de.hft.stuttgart.citydoctor2.datastructure.GmlId;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;

/**
 * 
 * @author Matthias Betz
 *
 */
public class TarjanGraphTest {

	@Test
	public void testConnectedComponents() {
		LinearRing lr = new LinearRing(LinearRingType.EXTERIOR);
		lr.setGmlId(new GmlId("R1"));
		CycleNode root = new CycleNode(lr);
		
		lr = new LinearRing(LinearRingType.EXTERIOR);
		lr.setGmlId(new GmlId("R2"));
		CycleNode c0 = new CycleNode(lr);
		root.addChild(c0);
		c0.addChild(root);
		
		lr = new LinearRing(LinearRingType.EXTERIOR);
		lr.setGmlId(new GmlId("R3"));
		CycleNode c00 = new CycleNode(lr);
		c0.addChild(c00);
		c00.addChild(root);
		c00.addChild(c0);
		
		lr = new LinearRing(LinearRingType.EXTERIOR);
		lr.setGmlId(new GmlId("R4"));
		CycleNode c000 = new CycleNode(lr);
		c00.addChild(c000);
		c000.addChild(root);
		
		
		lr = new LinearRing(LinearRingType.EXTERIOR);
		lr.setGmlId(new GmlId("R5"));
		CycleNode c1 = new CycleNode(lr);
		root.addChild(c1);
		
		lr = new LinearRing(LinearRingType.EXTERIOR);
		lr.setGmlId(new GmlId("R6"));
		CycleNode c2 = new CycleNode(lr);
		root.addChild(c2);
		
		lr = new LinearRing(LinearRingType.EXTERIOR);
		lr.setGmlId(new GmlId("R7"));
		CycleNode c20 = new CycleNode(lr);
		c2.addChild(c20);
		root.addChild(c20);
		
		CycleGraph tg = new CycleGraph(root);
		
		List<List<LinearRing>> connectedComponents = tg.getConnectedComponents();
		
		Assert.assertEquals(4, connectedComponents.size());
	}

}
