001 package test; 002 003 import physics3d.Angle; 004 import physics3d.Shape; 005 import physics3d.Vect3; 006 import components.GameSettings; 007 import components.GameSpace; 008 import components.SquareBumper; 009 010 import junit.framework.TestCase; 011 012 public class TestSquareBumper extends TestCase { 013 GameSpace g1; 014 GameSpace g2; 015 016 Vect3 p1; 017 Vect3 p2; 018 019 Vect3 o1; 020 Vect3 o2; 021 022 Angle a1; 023 Angle a2; 024 025 SquareBumper b1; 026 SquareBumper b2; 027 SquareBumper b3; 028 SquareBumper b4; 029 030 public TestSquareBumper(String name) { 031 super(name); 032 033 g1 = new GameSpace(new GameSettings()); 034 g2 = new GameSpace(new GameSettings()); 035 036 p1 = new Vect3(1, 2, 3); 037 p2 = new Vect3(-5, 10, -12); 038 039 o1 = Vect3.X_HAT; 040 o2 = Vect3.Z_HAT; 041 042 a1 = Angle.DEG_270; 043 a2 = Angle.DEG_90; 044 045 b1 = new SquareBumper(p1, o1, a1, "b1", g1); 046 b2 = new SquareBumper(p2, o2, a2, "b2", g2); 047 b3 = new SquareBumper(p1, o1, a1, "b1", g1); 048 b4 = new SquareBumper(p1, o1, a1, "b1", g2); 049 } 050 051 protected void setUp() {} 052 053 //test creation 054 public void testCreation() { 055 checkCreation(p1, o1, a1, "bumper", g1); 056 } 057 058 public void testCreation2() { 059 checkCreation(p2, o2, a2, "", g2); 060 } 061 062 protected void checkCreation(Vect3 position, Vect3 orientVect, Angle a, String name, GameSpace g) { 063 SquareBumper b = null; 064 try { 065 b = new SquareBumper(position, orientVect, a, name, g); 066 } catch (Exception e) { 067 fail("could not create SquareBumper with legal values"); 068 } 069 } 070 071 //test getPosition 072 public void testPosition() { 073 checkGetPosition(b1, p1); 074 } 075 076 public void testPosition2() { 077 checkGetPosition(b2, p2); 078 } 079 080 protected void checkGetPosition(SquareBumper b, Vect3 p) { 081 assertEquals("position of SquareBumper should have been " + p.toString() + 082 ", not " + b.getTLF().toString(), b.getTLF(), p); 083 } 084 085 //test getVelocity (make sure it's zero!) 086 public void testVelocity() { 087 checkGetVelocity(b1); 088 } 089 090 public void testVelocity2() { 091 checkGetVelocity(b2); 092 } 093 094 095 protected void checkGetVelocity(SquareBumper b) { 096 assertEquals("velocity of SquareBumper should have been 0", b.getVelocity(), Vect3.ZERO); 097 } 098 099 100 //test getOrientVector 101 public void testOrientVect() { 102 checkOrientVector(b1, o1); 103 } 104 105 public void testOrientVect2() { 106 checkOrientVector(b2, o2); 107 } 108 109 protected void checkOrientVector(SquareBumper b, Vect3 ov) { 110 assertEquals("Orientation vector of SquareBumper should have been " + ov.toString() + 111 ", not " + b.getOrientVector().toString(), b.getOrientVector(), ov); 112 } 113 114 //test getOrientAngle 115 public void testOrientAngle() { 116 checkOrientAngle(b1, a1); 117 } 118 119 public void testOrientAngle2() { 120 checkOrientAngle(b2, a2); 121 } 122 123 protected void checkOrientAngle(SquareBumper b, Angle a) { 124 assertEquals("Orientation angle of SquareBumper should have been " + a.toString() + 125 ", not " + b.getOrientAngle().toString(), b.getOrientAngle(), a); 126 } 127 128 //test getName 129 public void testName() { 130 checkName(b1, "b1"); 131 } 132 133 protected void checkName(SquareBumper b, String name) { 134 assertEquals("name should have been " + name + ", not " + b.getName(), b.getName(), name); 135 } 136 137 //test getShape 138 public void testShape() { 139 checkShape(b1); 140 } 141 142 public void testShape2() { 143 checkShape(b2); 144 } 145 146 protected void checkShape(SquareBumper b) { 147 assertEquals(b.getShape(), Shape.getSqBumperShape()); 148 } 149 150 //test equals 151 public void testEquals() { 152 checkEquals(b1, b1); 153 } 154 155 public void testEquals2() { 156 checkEquals(b1, b3); 157 } 158 159 public void testNotEquals() { 160 checkNotEquals(b1, b2); 161 } 162 163 public void testNotEquals2() { 164 checkNotEquals(b1, b4); 165 } 166 167 protected void checkEquals(SquareBumper b1, SquareBumper b2) { 168 assertEquals(b1, b2); 169 } 170 171 protected void checkNotEquals(SquareBumper b1, SquareBumper b2) { 172 assertFalse(b1.equals(b2)); 173 } 174 }