001 package test; 002 003 import components.Ball; 004 import components.GameSettings; 005 import components.GameSpace; 006 007 import physics3d.Shape; 008 import physics3d.Vect3; 009 import junit.framework.TestCase; 010 011 public class TestBall extends TestCase { 012 GameSpace gs; 013 GameSpace gs2; 014 015 Vect3 p1; 016 Vect3 p2; 017 018 Ball b1; 019 Ball b2; 020 Ball b3; 021 Ball b4; 022 023 public TestBall(String name) { 024 super(name); 025 026 gs = new GameSpace(new GameSettings()); 027 gs2 = new GameSpace(new GameSettings()); 028 029 p1 = new Vect3(1, 2, 3); 030 p2 = new Vect3(-1, -100, 2); 031 032 b1 = new Ball(p1, p1, "myBall", gs); 033 b2 = new Ball(p2, p2, "", gs); 034 b3 = new Ball(p1, p1, "myBall", gs); 035 b4 = new Ball(p1, p1, "myBall", gs2); 036 } 037 038 protected void setUp() {} 039 040 //test ball creation 041 public void testCreation() { 042 checkCreation(p1, p1, "myBall", gs); 043 } 044 045 public void testCreation2() { 046 checkCreation(p2, p2, "", gs); 047 } 048 049 protected void checkCreation(Vect3 position, Vect3 velocity, String name, GameSpace g) { 050 Ball ball = null; 051 try { 052 ball = new Ball(position, velocity, name, g); 053 } catch (Exception e) { 054 fail("could not create ball with legal values"); 055 } 056 } 057 058 059 //test getPosition 060 public void testPosition() { 061 checkGetPosition(b1, p1); 062 } 063 064 public void testPosition2() { 065 checkGetPosition(b2, p2); 066 } 067 068 protected void checkGetPosition(Ball ball, Vect3 p) { 069 assertEquals("position should have been " + p.toString() + " but was " + 070 ball.getTLF().toString(), ball.getTLF(), p); 071 } 072 073 public void testVelocity() { 074 checkGetVelocity(b1, p1); 075 } 076 077 public void testVelocity2() { 078 checkGetVelocity(b2, p2); 079 } 080 081 //test getVelocity 082 protected void checkGetVelocity(Ball ball, Vect3 v) { 083 assertEquals("velocity should hve been " + v.toString() + " but was " + 084 ball.getVelocity().toString(), ball.getVelocity(), v); 085 } 086 087 //test getOrientAngle 088 //test getOrientVector 089 090 //test getName 091 public void testName() { 092 checkName(b1, "myBall"); 093 } 094 095 public void testName2() { 096 checkName(b2, ""); 097 } 098 099 protected void checkName(Ball ball, String name) { 100 assertEquals("name should have been " + name + " but was " + ball.getName(), 101 ball.getName(), name); 102 } 103 104 //test getGameSpace 105 protected void checkGameSpace(Ball ball, GameSpace g) { 106 assertEquals("GameSpace not right", ball.getGameSpace(), g); 107 } 108 109 //test getTargets 110 111 //test shape 112 public void testShape() { 113 checkShape(b1); 114 } 115 116 public void testShape2() { 117 checkShape(b2); 118 } 119 120 protected void checkShape(Ball ball) { 121 assertEquals(ball.getShape(), Shape.getBallShape()); 122 } 123 124 //test equals 125 //checking something is equal to itself 126 public void testEquals() { 127 checkEquals(b1, b1); 128 } 129 130 public void testEquals2() { 131 checkEquals(b1, b3); 132 } 133 134 public void testNotEquals() { 135 checkNotEquals(b1, b2); 136 } 137 138 public void testNotEquals2() { 139 checkNotEquals(b1, b4); 140 } 141 142 protected void checkEquals(Ball b1, Ball b2) { 143 assertEquals(b1, b2); 144 } 145 146 protected void checkNotEquals(Ball b1, Ball b2) { 147 assertFalse(b1.equals(b2)); 148 } 149 150 }