001 package test;
002
003 import physics3d.Angle;
004 import physics3d.Shape;
005 import physics3d.Vect3;
006
007 import components.GameSettings;
008 import components.GameSpace;
009 import components.CircleBumper;
010
011 import junit.framework.TestCase;
012
013 public class TestCircleBumper extends TestCase {
014 GameSpace g1;
015 GameSpace g2;
016
017 Vect3 p1;
018 Vect3 p2;
019
020 Vect3 o1;
021 Vect3 o2;
022
023 Angle a1;
024 Angle a2;
025
026 CircleBumper b1;
027 CircleBumper b2;
028 CircleBumper b3;
029 CircleBumper b4;
030
031 public TestCircleBumper(String name) {
032 super(name);
033
034 g1 = new GameSpace(new GameSettings());
035 g2 = new GameSpace(new GameSettings());
036
037 p1 = new Vect3(1, 2, 3);
038 p2 = new Vect3(-5, 10, -12);
039
040 o1 = Vect3.X_HAT;
041 o2 = Vect3.Z_HAT;
042
043 a1 = Angle.DEG_270;
044 a2 = Angle.DEG_90;
045
046 b1 = new CircleBumper(p1, o1, a1, "b1", g1);
047 b2 = new CircleBumper(p2, o2, a2, "b2", g2);
048 b3 = new CircleBumper(p1, o1, a1, "b1", g1);
049 b4 = new CircleBumper(p1, o1, a1, "b1", g2);
050 }
051
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 CircleBumper b = null;
064 try {
065 b = new CircleBumper(position, orientVect, a, name, g);
066 } catch (Exception e) {
067 fail("could not create CircleBumper 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(CircleBumper b, Vect3 p) {
081 assertEquals("position of CircleBumper 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(CircleBumper b) {
096 assertEquals("velocity of CircleBumper 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(CircleBumper b, Vect3 ov) {
110 assertEquals("Orientation vector of CircleBumper 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(CircleBumper b, Angle a) {
124 assertEquals("Orientation angle of CircleBumper 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(CircleBumper 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(CircleBumper b) {
147 assertEquals(b.getShape(), Shape.getCirBumperShape());
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(CircleBumper b1, CircleBumper b2) {
168 assertEquals(b1, b2);
169 }
170
171 protected void checkNotEquals(CircleBumper b1, CircleBumper b2) {
172 assertFalse(b1.equals(b2));
173 }
174 }