package me.teaisaweso.client;

import java.util.Collection;

import junit.framework.Assert;
import junit.framework.TestCase;
import me.teaisaweso.client.graphmanagers.GraphManager2d;
import me.teaisaweso.client.graphmanagers.GraphManager2dFactory;
import me.teaisaweso.shared.Graph;
import me.teaisaweso.shared.Vertex;

/**
 * NOTE: this class relies on the GraphManager2d factory working, if it isn't
 * you should probably assume that this test is totally broken
 */
public class GraphManager2dTest extends TestCase {
	private GraphManager2d mManager;

	/**
	 * runs test setup, creates a graphmanager instance
	 */
	public void setUp() {
		mManager = GraphManager2dFactory.getInstance().makeDefaultGraphManager();
	}

	public void tearDown() {
		mManager = null;
	}

	/**
	 * tests that adding vertices works
	 */
	public void testAddVertex_single() {
		mManager.addVertex(new Vertex("hi"), 0, -3, 10);
		Graph underlying = mManager.getUnderlyingGraph();
		Assert.assertEquals(true, underlying.getVertices().contains(new Vertex("hi")));
		Collection<VertexDrawable> drawables = mManager.getVertexDrawables();
		Assert.assertEquals(1, drawables.size());
		VertexDrawable[] vds = drawables.toArray(new VertexDrawable[] { new VertexDrawable(0, 0, 0,
				0, "") });
		Assert.assertEquals(0, vds[0].getCenterX());
		Assert.assertEquals(-5, vds[0].getLeft());
		Assert.assertEquals(-3, vds[0].getCenterY());
		Assert.assertEquals(-8, vds[0].getTop());
		Assert.assertEquals(10, vds[0].getWidth());
		Assert.assertEquals(10, vds[0].getHeight());
		Assert.assertEquals("hi", vds[0].getLabel());
	}
}

@@ -1586,10 +1586,572 @@
 ());%0A%09%7D%0A
+%0A%09public void testAddVertex_multiple() %7B%0A%09%09mManager.addVertex(new Vertex(%22bees%22), 100, 17, 2);%0A%09%09mManager.addVertex(new Vertex(%22cheese%22), 0, 0, 2);%0A%0A%09%09Graph underlying = mManager.getUnderlyingGraph();%0A%09%09Assert.assertEquals(2, underlying.getVertices().size());%0A%09%09Assert.assertEquals(true, underlying.getVertices().contains(new Vertex(%22bees%22)));%0A%09%09Assert.assertEquals(true, underlying.getVertices().contains(new Vertex(%22cheese%22)));%0A%0A%09%09VertexDrawable%5B%5D vds = mManager.getVertexDrawables().toArray(new VertexDrawable%5B%5D %7B%7D);%0A%09%09Assert.assertEquals(2, vds.length);%0A%09%7D%0A%0A
 %7D%0A

add a multiple vertex add test