KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > thewayout > two > SpaceShipTest


1 package de.thewayout.two;
2
3 import junit.framework.TestCase;
4 // JUnitDoclet begin import
5
// JUnitDoclet end import
6

7 /**
8 * Generated by JUnitDoclet, a tool provided by
9 * ObjectFab GmbH under LGPL.
10 * Please see www.junitdoclet.org, www.gnu.org
11 * and www.objectfab.de for informations about
12 * the tool, the license and the the authors.
13 */

14
15
16 public class SpaceShipTest
17 // JUnitDoclet begin extends_implements
18
extends TestCase implements SteeringConstants
19 // JUnitDoclet end extends_implements
20
{
21   // JUnitDoclet begin class
22
SpaceShip spaceship = null;
23
24   public void assertEquals(long[] expected, long[] actual) {
25     if ((expected == null) && (actual == null)) {
26       return;
27     }
28
29     if ((expected != null) && (actual != null)) {
30       if (expected.length == actual.length) {
31         for(int i=0; i<expected.length; i++) {
32           assertEquals("arrays differ at index"+i, expected[i], actual[i]);
33         }
34       } else {
35         fail("Two arrays don't have the same length.");
36       }
37       return;
38     }
39     fail("Two arrays are not equal.");
40   }
41
42   // JUnitDoclet end class
43

44   public SpaceShipTest(String JavaDoc name) {
45     // JUnitDoclet begin method SpaceShipTest
46
super(name);
47     // JUnitDoclet end method SpaceShipTest
48
}
49
50   public void setUp() throws Exception JavaDoc {
51     // JUnitDoclet begin method testcase.setUp
52
super.setUp();
53     spaceship = new de.thewayout.two.SpaceShip();
54     // JUnitDoclet end method testcase.setUp
55
}
56
57   public void tearDown() throws Exception JavaDoc {
58     // JUnitDoclet begin method testcase.tearDown
59
spaceship = null;
60     super.tearDown();
61     // JUnitDoclet end method testcase.tearDown
62
}
63
64   public void testSetGetDirection() throws Exception JavaDoc {
65     // JUnitDoclet begin method setDirection getDirection
66
int[] tests = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
67
68     for (int i=0; i<tests.length; i++) {
69       spaceship.setDirection(tests[i]);
70       assertEquals(tests[i], spaceship.getDirection());
71     }
72     // JUnitDoclet end method setDirection getDirection
73
}
74
75   public void testSetGetSpeed() throws Exception JavaDoc {
76     // JUnitDoclet begin method setSpeed getSpeed
77
long[] tests = {Long.MIN_VALUE, -1, 0, 1, Long.MAX_VALUE};
78
79     for (int i = 0; i < tests.length; i++) {
80       spaceship.setSpeed(tests[i]);
81       assertEquals(tests[i], spaceship.getSpeed());
82     }
83     // JUnitDoclet end method setSpeed getSpeed
84
}
85
86   public void testSetGetPosition() throws Exception JavaDoc {
87     // JUnitDoclet begin method setPosition getPosition
88
long[][] tests = {new long[]{1, 2, 3}, new long[]{4, 5, 6}};
89
90     for (int i = 0; i < tests.length; i++) {
91       spaceship.setPosition(tests[i]);
92       assertEquals(tests[i], spaceship.getPosition());
93     }
94     // JUnitDoclet end method setPosition getPosition
95
}
96
97   public void testGetPowerConsumed() throws Exception JavaDoc {
98     // JUnitDoclet begin method getPowerConsumed
99
// JUnitDoclet end method getPowerConsumed
100
}
101
102   public void testConsumePower() throws Exception JavaDoc {
103     // JUnitDoclet begin method consumePower
104
long powerBefore = spaceship.getPowerConsumed();
105     spaceship.consumePower(100);
106     assertEquals("Unexpected power consumption",
107                  powerBefore + 100, spaceship.getPowerConsumed());
108     // JUnitDoclet end method consumePower
109
}
110
111   public void testCalculateStep() throws Exception JavaDoc {
112     // JUnitDoclet begin method calculateStep
113
// JUnitDoclet end method calculateStep
114
}
115
116   public void testMakeStep() throws Exception JavaDoc {
117     // JUnitDoclet begin method makeStep
118
long[] p1, p2;
119     p1 = new long[] { 100, 100, 100 };
120     spaceship.setPosition(p1);
121     spaceship.setSpeed(1);
122     spaceship.goAhead();
123     p2 = spaceship.getPosition();
124     assertEquals("Moved unexpected distance.",
125                  1, Math.abs(p2[0] - p1[0] + p2[1] - p1[1] + p2[2] - p1[2]));
126     // JUnitDoclet end method makeStep
127
}
128
129
130
131   /**
132   * JUnitDoclet moves markers to this method, if there is no match
133   * for them in the regenerated code and if the marker is not empty.
134   * This way, no test gets lost when regenerating after renaming.
135   * Method testVault is supposed to be empty.
136   */

137   public void testVault() throws Exception JavaDoc {
138     // JUnitDoclet begin method testcase.testVault()
139
// JUnitDoclet end method testcase.testVault()
140
}
141
142   public static void main(String JavaDoc[] args) {
143     // JUnitDoclet begin method testcase.main
144
junit.textui.TestRunner.run(SpaceShipTest.class);
145     // JUnitDoclet end method testcase.main
146
}
147 }
148
Popular Tags