package uk.me.graphe.client;

import java.util.Random;

import uk.me.graphe.shared.VertexDirection;

import junit.framework.Assert;
import junit.framework.TestCase;

public class EdgeDrawableTest extends TestCase {
    static int[] sTestValues = new int[] { 0, -10, 7, Integer.MAX_VALUE,
            Integer.MIN_VALUE };
    static Random sRand = new Random();

    /**
     * tests that start x works as expected
     */
    public void testStartX() {
        for (int i : sTestValues) {
            EdgeDrawable ed = new EdgeDrawable(i, sRand.nextInt(), sRand
                    .nextInt(), sRand.nextInt(), 0);
            Assert.assertEquals(i, ed.getStartX());
        }
    }

    /**
     * tests that start y works as expected
     */
    public void testStartY() {
        for (int i : sTestValues) {
            EdgeDrawable ed = new EdgeDrawable(sRand.nextInt(), i, sRand
                    .nextInt(), sRand.nextInt(), 0);
            Assert.assertEquals(i, ed.getStartY());
        }
    }

    /**
     * tests that end x works as expected
     */
    public void testEndX() {
        for (int i : sTestValues) {
            EdgeDrawable ed = new EdgeDrawable(sRand.nextInt(),
                    sRand.nextInt(), i, sRand.nextInt(), 0);
            Assert.assertEquals(i, ed.getEndX());
        }
    }

    /**
     * tests that end y works as expected
     */
    public void testEndY() {
        for (int i : sTestValues) {
            EdgeDrawable ed = new EdgeDrawable(sRand.nextInt(),
                    sRand.nextInt(), sRand.nextInt(), i, 0);
            Assert.assertEquals(i, ed.getEndY());
        }
    }

    /**
     * tests the use of needsarrow in an edge drawable
     */
    public void testArrow() {
        EdgeDrawable e = new EdgeDrawable(sRand.nextInt(), sRand.nextInt(),
                sRand.nextInt(), sRand.nextInt(), 0);
        Assert.assertEquals(false, e.needsFromToArrow());
        Assert.assertEquals(false, e.needsToFromArrow());
        e = new EdgeDrawable(sRand.nextInt(), sRand.nextInt(), sRand.nextInt(),
                sRand.nextInt(), 0, VertexDirection.both);
        Assert.assertEquals(false, e.needsFromToArrow());
        Assert.assertEquals(false, e.needsToFromArrow());
        e = new EdgeDrawable(sRand.nextInt(), sRand.nextInt(), sRand.nextInt(),
                sRand.nextInt(), 0, VertexDirection.fromTo);
        Assert.assertEquals(true, e.needsFromToArrow());
        Assert.assertEquals(false, e.needsToFromArrow());
        e = new EdgeDrawable(sRand.nextInt(), sRand.nextInt(), sRand.nextInt(),
                sRand.nextInt(), 0, VertexDirection.toFrom);
        Assert.assertEquals(false, e.needsFromToArrow());
        Assert.assertEquals(true, e.needsToFromArrow());
    }
}

@@ -53,53 +53,8 @@
 m;%0A%0A
-import uk.me.graphe.shared.VertexDirection;%0A%0A
 impo
@@ -112,16 +112,60 @@
 estCase;
+%0Aimport uk.me.graphe.shared.VertexDirection;
 %0A%0Apublic
@@ -2748,10 +2748,159 @@
 ;%0A    %7D%0A
+    %0A    public void testWeight() %7B%0A        EdgeDrawable ed = new EdgeDrawable(1, 2, 3, 4, 7);%0A        Assert.assertEquals(7, ed.getWeight());%0A    %7D%0A
 %7D%0A

add a test for edge weight