summaryrefslogtreecommitdiffstats
path: root/docs/teaching/exercises/tests
diff options
context:
space:
mode:
authorehilsdal <ehilsdal>2003-08-28 15:11:12 +0000
committerehilsdal <ehilsdal>2003-08-28 15:11:12 +0000
commitf3929cad6a0e6d6973483dd23c7aea68b6e7fed1 (patch)
tree7caf9b0ac3e5a52c0341dfc8b9061be49287b599 /docs/teaching/exercises/tests
parentf1a7345a62bd1f227dd64fcd7c2d519c8911ae5c (diff)
downloadaspectj-f3929cad6a0e6d6973483dd23c7aea68b6e7fed1.tar.gz
aspectj-f3929cad6a0e6d6973483dd23c7aea68b6e7fed1.zip
updated section 2
Diffstat (limited to 'docs/teaching/exercises/tests')
-rw-r--r--docs/teaching/exercises/tests/Test2a.java20
-rw-r--r--docs/teaching/exercises/tests/Test2b.java19
-rw-r--r--docs/teaching/exercises/tests/Test2c.java25
-rw-r--r--docs/teaching/exercises/tests/Test2d.java27
-rw-r--r--docs/teaching/exercises/tests/Test2e.java23
-rw-r--r--docs/teaching/exercises/tests/Test2f.java24
-rw-r--r--docs/teaching/exercises/tests/Test2g.java42
-rw-r--r--docs/teaching/exercises/tests/Test2h.java42
8 files changed, 74 insertions, 148 deletions
diff --git a/docs/teaching/exercises/tests/Test2a.java b/docs/teaching/exercises/tests/Test2a.java
index 0b737020b..4bc6dd28a 100644
--- a/docs/teaching/exercises/tests/Test2a.java
+++ b/docs/teaching/exercises/tests/Test2a.java
@@ -16,18 +16,16 @@ import figures.*;
import junit.framework.*;
-public class Test2a extends Test {
+public class Test2a extends TestCase {
public Test2a(String name) { super(name); }
public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test.class);
junit.textui.TestRunner.run(Test2a.class);
}
- public void setUp() {
- super.setUp();
- }
-
public void testTooSmall() {
+ Point p1 = new Point(10, 100);
try {
p1.setX(-10);
fail("should have thrown IllegalArgumentException");
@@ -35,17 +33,13 @@ public class Test2a extends Test {
}
}
-
- public void testTooBig() {
- try {
- p1.setY(1000);
- fail("should have thrown IllegalArgumentException");
- } catch (IllegalArgumentException ea) {
- }
+ public void testNotTooSmall() {
+ Point p1 = new Point(10, 100);
+ p1.setX(0);
}
-
public void testMove() {
+ Line l1 = new Line(new Point(10, 100), new Point(20, 200));
try {
l1.move(-500, -500);
fail("should have thrown IllegalArgumentException");
diff --git a/docs/teaching/exercises/tests/Test2b.java b/docs/teaching/exercises/tests/Test2b.java
index e127b5cc4..822c8de74 100644
--- a/docs/teaching/exercises/tests/Test2b.java
+++ b/docs/teaching/exercises/tests/Test2b.java
@@ -16,22 +16,31 @@ import figures.*;
import junit.framework.*;
-public class Test2b extends Test {
+public class Test2b extends TestCase {
public Test2b(String name) { super(name); }
public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test.class);
junit.textui.TestRunner.run(Test2b.class);
}
- public void setUp() {
- super.setUp();
- }
-
public void testNull() {
+ Point p1 = new Point(10, 100);
+ Group g = new Group(p1);
+
try {
g.add(null);
fail("should have thrown IllegalArgumentException");
} catch (IllegalArgumentException ea) {
}
}
+
+ public void testNonNull() {
+ Point p1 = new Point(10, 100);
+ Group g = new Group(p1);
+ Point p2 = new Point(20, 200);
+
+ g.add(p2);
+ }
+
}
diff --git a/docs/teaching/exercises/tests/Test2c.java b/docs/teaching/exercises/tests/Test2c.java
index 153739fc0..01c4978e4 100644
--- a/docs/teaching/exercises/tests/Test2c.java
+++ b/docs/teaching/exercises/tests/Test2c.java
@@ -16,30 +16,31 @@ import figures.*;
import junit.framework.*;
-public class Test2c extends Test {
+public class Test2c extends TestCase {
public Test2c(String name) { super(name); }
public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test.class);
+ junit.textui.TestRunner.run(Test2b.class);
junit.textui.TestRunner.run(Test2c.class);
}
- public void setUp() {
- super.setUp();
- }
+ public void testSelf() {
+ Point p1 = new Point(10, 100);
+ Group g = new Group(p1);
- public void testNull() {
try {
- g.add(null);
+ g.add(g);
fail("should have thrown IllegalArgumentException");
} catch (IllegalArgumentException ea) {
}
}
- public void testSelf() {
- try {
- g.add(g);
- fail("should have thrown IllegalArgumentException");
- } catch (IllegalArgumentException ea) {
- }
+ public void testNotSelf() {
+ Point p1 = new Point(10, 100);
+ Group g1 = new Group(p1);
+ Group g2 = new Group(p1);
+
+ g1.add(g2);
}
}
diff --git a/docs/teaching/exercises/tests/Test2d.java b/docs/teaching/exercises/tests/Test2d.java
index b8056fbf3..cc8d7f51c 100644
--- a/docs/teaching/exercises/tests/Test2d.java
+++ b/docs/teaching/exercises/tests/Test2d.java
@@ -16,22 +16,31 @@ import figures.*;
import junit.framework.*;
-public class Test2d extends Test {
+public class Test2d extends TestCase {
public Test2d(String name) { super(name); }
public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test.class);
junit.textui.TestRunner.run(Test2d.class);
}
- public void setUp() {
- super.setUp();
+ public void testOutOfBounds() {
+ Point p1 = new Point(10, 100);
+
+ p1.setX(-10);
+ p1.setY(-100);
+
+ assertEquals(0, p1.getX());
+ assertEquals(0, p1.getY());
}
- public void testSetting() {
- try {
- sloth1.setX(10);
- fail("should have thrown RuntimeException");
- } catch (RuntimeException ea) {
- }
+ public void testInBounds() {
+ Point p1 = new Point(10, 100);
+
+ p1.setX(30);
+ p1.setY(300);
+
+ assertEquals(30, p1.getX());
+ assertEquals(300, p1.getY());
}
}
diff --git a/docs/teaching/exercises/tests/Test2e.java b/docs/teaching/exercises/tests/Test2e.java
index dfa456138..09ab65790 100644
--- a/docs/teaching/exercises/tests/Test2e.java
+++ b/docs/teaching/exercises/tests/Test2e.java
@@ -16,27 +16,24 @@ import figures.*;
import junit.framework.*;
-public class Test2e extends Test {
+public class Test2e extends TestCase {
public Test2e(String name) { super(name); }
public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test.class);
junit.textui.TestRunner.run(Test2e.class);
}
- public void setUp() {
- super.setUp();
- }
-
- public void testEasy() {
- Box sq = new Box(0, 0, 10, 10);
- sq.move(5,5);
- assertEquals(sq.getP0().getX(), 5);
- assertEquals(sq.getP0().getY(), 5);
-
+ public void testSloth() {
+ Point sp = new SlothfulPoint(10, 10);
try {
- sq.getP0().setX(100);
- sq.move(37, 1);
+ sp.move(10, 10);
fail("should have thrown IllegalStateException");
} catch (IllegalStateException e) { }
}
+
+ public void testNonSloth() {
+ Point p1 = new Point(10, 100);
+ p1.move(3, 30);
+ }
}
diff --git a/docs/teaching/exercises/tests/Test2f.java b/docs/teaching/exercises/tests/Test2f.java
index a11e16781..1b90d268a 100644
--- a/docs/teaching/exercises/tests/Test2f.java
+++ b/docs/teaching/exercises/tests/Test2f.java
@@ -20,23 +20,23 @@ public class Test2f extends Test {
public Test2f(String name) { super(name); }
public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test.class);
junit.textui.TestRunner.run(Test2f.class);
}
- public void setUp() {
- super.setUp();
- }
-
- public void testEasy() {
- Box sq = new Box(0, 0, 10, 10);
- sq.move(5,5);
- assertEquals(sq.getP0().getX(), 5);
- assertEquals(sq.getP0().getY(), 5);
-
+ public void testSloth() {
+ FigureElement fe = new SlothfulPoint(10, 10);
try {
- sq.getP0().setX(100);
- sq.getP1();
+ fe.move(10, 10);
fail("should have thrown IllegalStateException");
} catch (IllegalStateException e) { }
}
+
+ public void testNonSloth() {
+ Point p1 = new Point(10, 100);
+ Point p2 = new Point(20, 200);
+ Line l1 = new Line(p1, p2);
+
+ l1.move(3, 30);
+ }
}
diff --git a/docs/teaching/exercises/tests/Test2g.java b/docs/teaching/exercises/tests/Test2g.java
deleted file mode 100644
index f4a7a1949..000000000
--- a/docs/teaching/exercises/tests/Test2g.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/* *******************************************************************
- * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Common Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * PARC initial implementation
- * ******************************************************************/
-
-package tests;
-
-import figures.*;
-
-import junit.framework.*;
-
-public class Test2g extends Test {
- public Test2g(String name) { super(name); }
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(Test2g.class);
- }
-
- public void setUp() {
- super.setUp();
- }
-
- public void testBounds() {
- p1.setX(FigureElement.MAX_VALUE + 1);
- assertEquals(FigureElement.MAX_VALUE, p1.getX());
- p1.setY(FigureElement.MIN_VALUE - 1);
- assertEquals(FigureElement.MIN_VALUE, p1.getY());
- }
-
- public void testBox() {
- Box s = new Box(50, 50, 20000, 20000);
- assertEquals(FigureElement.MAX_VALUE, s.getP2().getX());
- assertEquals(FigureElement.MAX_VALUE, s.getP2().getY());
- }
-}
diff --git a/docs/teaching/exercises/tests/Test2h.java b/docs/teaching/exercises/tests/Test2h.java
deleted file mode 100644
index 339322519..000000000
--- a/docs/teaching/exercises/tests/Test2h.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/* *******************************************************************
- * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Common Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * PARC initial implementation
- * ******************************************************************/
-
-package tests;
-
-import figures.*;
-
-import junit.framework.*;
-
-public class Test2h extends Test {
- public Test2h(String name) { super(name); }
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(Test2h.class);
- }
-
- public void setUp() {
- super.setUp();
- }
-
- public void testSloth() {
- FigureElement fe = new SlothfulPoint(10, 10);
- try {
- fe.move(10, 10);
- fail("should have thrown IllegalStateException");
- } catch (IllegalStateException e) { }
- }
-
- public void movePoints() {
- p1.move(30, 45);
- p2.move(10, 33);
- }
-}