1 package de.thewayout.two; 2 3 import junit.framework.TestCase; 4 7 14 15 16 public class SpaceShipTest 17 extends TestCase implements SteeringConstants 19 { 21 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 44 public SpaceShipTest(String name) { 45 super(name); 47 } 49 50 public void setUp() throws Exception { 51 super.setUp(); 53 spaceship = new de.thewayout.two.SpaceShip(); 54 } 56 57 public void tearDown() throws Exception { 58 spaceship = null; 60 super.tearDown(); 61 } 63 64 public void testSetGetDirection() throws Exception { 65 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 } 74 75 public void testSetGetSpeed() throws Exception { 76 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 } 85 86 public void testSetGetPosition() throws Exception { 87 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 } 96 97 public void testGetPowerConsumed() throws Exception { 98 } 101 102 public void testConsumePower() throws Exception { 103 long powerBefore = spaceship.getPowerConsumed(); 105 spaceship.consumePower(100); 106 assertEquals("Unexpected power consumption", 107 powerBefore + 100, spaceship.getPowerConsumed()); 108 } 110 111 public void testCalculateStep() throws Exception { 112 } 115 116 public void testMakeStep() throws Exception { 117 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 } 128 129 130 131 137 public void testVault() throws Exception { 138 } 141 142 public static void main(String [] args) { 143 junit.textui.TestRunner.run(SpaceShipTest.class); 145 } 147 } 148 | Popular Tags |