summaryrefslogtreecommitdiffstats
path: root/docs/teaching/exercises/tests
diff options
context:
space:
mode:
Diffstat (limited to 'docs/teaching/exercises/tests')
-rw-r--r--docs/teaching/exercises/tests/Test.java80
-rw-r--r--docs/teaching/exercises/tests/Test1a.java55
-rw-r--r--docs/teaching/exercises/tests/Test2a.java55
-rw-r--r--docs/teaching/exercises/tests/Test2b.java37
-rw-r--r--docs/teaching/exercises/tests/Test2c.java45
-rw-r--r--docs/teaching/exercises/tests/Test2d.java37
-rw-r--r--docs/teaching/exercises/tests/Test2e.java42
-rw-r--r--docs/teaching/exercises/tests/Test2f.java42
-rw-r--r--docs/teaching/exercises/tests/Test2g.java42
-rw-r--r--docs/teaching/exercises/tests/Test2h.java42
-rw-r--r--docs/teaching/exercises/tests/Test3a.java49
-rw-r--r--docs/teaching/exercises/tests/Test3b.java54
-rw-r--r--docs/teaching/exercises/tests/Test3c.java47
-rw-r--r--docs/teaching/exercises/tests/Test4a.java38
-rw-r--r--docs/teaching/exercises/tests/Test4b.java70
-rw-r--r--docs/teaching/exercises/tests/Test4c.java84
-rw-r--r--docs/teaching/exercises/tests/Test4d.java81
-rw-r--r--docs/teaching/exercises/tests/Test4e.java68
18 files changed, 968 insertions, 0 deletions
diff --git a/docs/teaching/exercises/tests/Test.java b/docs/teaching/exercises/tests/Test.java
new file mode 100644
index 000000000..e4f5b60f9
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test.java
@@ -0,0 +1,80 @@
+/* *******************************************************************
+ * 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 Test extends TestCase {
+ public Test(String name) { super(name); }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test.class);
+ }
+
+ Box bb;
+ Point p1;
+ Point p2;
+ Line l1;
+ SlothfulPoint sloth1;
+ Group g;
+
+ public void setUp() {
+ p1 = new Point(10, 100);
+ p2 = new Point(20, 200);
+ l1 = new Line(p1, p2);
+ bb = new Box(5, 5, 10, 10);
+ sloth1 = new SlothfulPoint(0, 0);
+ g = new Group(p1);
+ }
+
+ public final void testCreate() {
+ assertEquals(p1.getX(), 10);
+ assertEquals(p1.getY(), 100);
+
+ assertEquals(l1.getP1(), p1);
+ assertEquals(l1.getP2(), p2);
+ }
+
+ public final void testSetPoint() {
+ p1.setX(20);
+ assertEquals(p1.getX(), 20);
+ assertEquals(p1.getY(), 100);
+
+ p1.setY(10);
+ assertEquals(p1.getX(), 20);
+ assertEquals(p1.getY(), 10);
+ }
+
+ public final void testMoveLine1() {
+ l1.move(40, 40);
+ assertEquals(l1.getP1(), p1);
+ assertEquals(l1.getP2(), p2);
+
+ assertEquals(p1.getX(), 50);
+ assertEquals(p1.getY(), 140);
+
+ assertEquals(p2.getX(), 60);
+ assertEquals(p2.getY(), 240);
+ }
+
+ public final void testMoveLine2() {
+ l1.move(-10, -10);
+ assertEquals(p1.getX(), 0);
+ assertEquals(p1.getY(), 90);
+
+ assertEquals(p2.getX(), 10);
+ assertEquals(p2.getY(), 190);
+ }
+}
diff --git a/docs/teaching/exercises/tests/Test1a.java b/docs/teaching/exercises/tests/Test1a.java
new file mode 100644
index 000000000..b8bb2e120
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test1a.java
@@ -0,0 +1,55 @@
+/* *******************************************************************
+ * 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 support.Log;
+
+import junit.framework.*;
+
+public class Test1a extends Test {
+ public Test1a(String name) { super(name); }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test1a.class);
+ }
+
+ public void setUp() {
+ Log.clear();
+ super.setUp();
+ }
+
+ public void testCreateLog() {
+ assertEquals("", Log.getString());
+ }
+
+ public void testSetXPointLog() {
+ p1.setX(20);
+ assertEquals("set;", Log.getString());
+ }
+
+ public void testSetYPointLog() {
+ p1.setY(10);
+ assertEquals("", Log.getString());
+ }
+
+ public void testGetYPointLog() {
+ p1.getY();
+ assertEquals("", Log.getString());
+ }
+
+ public void testMoveLineLog() {
+ l1.move(40, 40);
+ assertEquals("", Log.getString());
+ }
+}
diff --git a/docs/teaching/exercises/tests/Test2a.java b/docs/teaching/exercises/tests/Test2a.java
new file mode 100644
index 000000000..21ce08a9f
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test2a.java
@@ -0,0 +1,55 @@
+/* *******************************************************************
+ * 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 Test2a extends Test {
+ public Test2a(String name) { super(name); }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test2a.class);
+ }
+
+ public void setUp() {
+ super.setUp();
+ }
+
+ public void testTooSmall() {
+ try {
+ p1.setX(-10);
+ fail("should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ea) {
+ }
+ }
+
+
+ public void testTooBig() {
+ try {
+ p1.setY(1000);
+ fail("should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ea) {
+ }
+ }
+
+
+ public void testMove() {
+ try {
+ l1.move(-500, -500);
+ fail("should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ea) {
+ }
+ }
+}
diff --git a/docs/teaching/exercises/tests/Test2b.java b/docs/teaching/exercises/tests/Test2b.java
new file mode 100644
index 000000000..63a10b7b0
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test2b.java
@@ -0,0 +1,37 @@
+/* *******************************************************************
+ * 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 Test2b extends Test {
+ public Test2b(String name) { super(name); }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test2b.class);
+ }
+
+ public void setUp() {
+ super.setUp();
+ }
+
+ public void testNull() {
+ try {
+ g.add(null);
+ fail("should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ea) {
+ }
+ }
+}
diff --git a/docs/teaching/exercises/tests/Test2c.java b/docs/teaching/exercises/tests/Test2c.java
new file mode 100644
index 000000000..cfcb0d1d8
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test2c.java
@@ -0,0 +1,45 @@
+/* *******************************************************************
+ * 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 Test2c extends Test {
+ public Test2c(String name) { super(name); }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test2c.class);
+ }
+
+ public void setUp() {
+ super.setUp();
+ }
+
+ public void testNull() {
+ try {
+ g.add(null);
+ fail("should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ea) {
+ }
+ }
+
+ public void testSelf() {
+ try {
+ g.add(g);
+ fail("should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ea) {
+ }
+ }
+}
diff --git a/docs/teaching/exercises/tests/Test2d.java b/docs/teaching/exercises/tests/Test2d.java
new file mode 100644
index 000000000..89e47c088
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test2d.java
@@ -0,0 +1,37 @@
+/* *******************************************************************
+ * 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 Test2d extends Test {
+ public Test2d(String name) { super(name); }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test2d.class);
+ }
+
+ public void setUp() {
+ super.setUp();
+ }
+
+ public void testSetting() {
+ try {
+ sloth1.setX(10);
+ fail("should have thrown RuntimeException");
+ } catch (RuntimeException ea) {
+ }
+ }
+}
diff --git a/docs/teaching/exercises/tests/Test2e.java b/docs/teaching/exercises/tests/Test2e.java
new file mode 100644
index 000000000..57af08501
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test2e.java
@@ -0,0 +1,42 @@
+/* *******************************************************************
+ * 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 Test2e extends Test {
+ public Test2e(String name) { super(name); }
+
+ public static void main(String[] args) {
+ 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);
+
+ try {
+ sq.getP0().setX(100);
+ sq.move(37, 1);
+ fail("should have thrown IllegalStateException");
+ } catch (IllegalStateException e) { }
+ }
+}
diff --git a/docs/teaching/exercises/tests/Test2f.java b/docs/teaching/exercises/tests/Test2f.java
new file mode 100644
index 000000000..da63b12e1
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test2f.java
@@ -0,0 +1,42 @@
+/* *******************************************************************
+ * 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 Test2f extends Test {
+ public Test2f(String name) { super(name); }
+
+ public static void main(String[] args) {
+ 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);
+
+ try {
+ sq.getP0().setX(100);
+ sq.getP1();
+ fail("should have thrown IllegalStateException");
+ } catch (IllegalStateException e) { }
+ }
+}
diff --git a/docs/teaching/exercises/tests/Test2g.java b/docs/teaching/exercises/tests/Test2g.java
new file mode 100644
index 000000000..7ed9ba341
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test2g.java
@@ -0,0 +1,42 @@
+/* *******************************************************************
+ * 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
new file mode 100644
index 000000000..9ed695d9b
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test2h.java
@@ -0,0 +1,42 @@
+/* *******************************************************************
+ * 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);
+ }
+}
diff --git a/docs/teaching/exercises/tests/Test3a.java b/docs/teaching/exercises/tests/Test3a.java
new file mode 100644
index 000000000..3cb063251
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test3a.java
@@ -0,0 +1,49 @@
+/* *******************************************************************
+ * 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 support.Log;
+
+import junit.framework.*;
+
+public class Test3a extends Test {
+ public Test3a(String name) { super(name); }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test3a.class);
+ }
+
+ public void setUp() {
+ Log.clear();
+ super.setUp();
+ }
+
+ public void testCreateLog() {
+ assertEquals("", Log.getString());
+ }
+
+ public void testMovePointLog() {
+ p1.move(20, 30);
+ assertEquals("moving;", Log.getString());
+ }
+
+ public void testSetYPointLog() {
+ assertEquals("", Log.getString());
+ }
+
+ public void testGetYPointLog() {
+ p1.getY();
+ assertEquals("", Log.getString());
+ }
+}
diff --git a/docs/teaching/exercises/tests/Test3b.java b/docs/teaching/exercises/tests/Test3b.java
new file mode 100644
index 000000000..6ec933cee
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test3b.java
@@ -0,0 +1,54 @@
+/* *******************************************************************
+ * 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 support.Log;
+
+import junit.framework.*;
+
+public class Test3b extends Test {
+ public Test3b(String name) { super(name); }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test3b.class);
+ }
+
+ public void setUp() {
+ super.setUp();
+ Log.clear();
+ }
+
+ public void testCreateLog() {
+ assertEquals("", Log.getString());
+ }
+
+ public void testCreateWithPointLog() {
+ g = new Group(p1);
+ assertEquals("adding Point;", Log.getString());
+ }
+
+ public void testCreateWithoutPointLog() {
+ g = new Group(l1);
+ assertEquals("", Log.getString());
+ }
+
+ public void testAddPointLog() {
+ g.add(p1);
+ assertEquals("adding Point;", Log.getString());
+ }
+ public void testAddNonPointLog() {
+ g.add(l1);
+ assertEquals("", Log.getString());
+ }
+}
diff --git a/docs/teaching/exercises/tests/Test3c.java b/docs/teaching/exercises/tests/Test3c.java
new file mode 100644
index 000000000..6c135e91c
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test3c.java
@@ -0,0 +1,47 @@
+/* *******************************************************************
+ * 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 support.Log;
+
+import junit.framework.*;
+
+public class Test3c extends Test {
+ public Test3c(String name) { super(name); }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test3c.class);
+ }
+
+ public void setUp() {
+ Log.clear();
+ super.setUp();
+ }
+
+ public void testCreateLog() {
+ assertEquals("", Log.getString());
+ }
+
+ public void testMoveLonePoint() {
+ p1 = new Point(0, 0);
+ p1.move(37, 88);
+ assertEquals("moving as a part of null;", Log.getString());
+ }
+
+ public void testMoveGroupedPoint() {
+ g = new Group(p1);
+ p1.move(0, 0);
+ assertEquals("moving as a part of " + g + ";", Log.getString());
+ }
+}
diff --git a/docs/teaching/exercises/tests/Test4a.java b/docs/teaching/exercises/tests/Test4a.java
new file mode 100644
index 000000000..ddb18415a
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test4a.java
@@ -0,0 +1,38 @@
+/* *******************************************************************
+ * 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 java.awt.Rectangle;
+
+import junit.framework.*;
+
+public class Test4a extends Test {
+ Rectangle wholeCanvas =
+ new Rectangle(FigureElement.MIN_VALUE, FigureElement.MIN_VALUE,
+ FigureElement.MAX_VALUE, FigureElement.MAX_VALUE);
+
+ public Test4a(String name) { super(name); }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test4a.class);
+ }
+
+ public void setUp() {
+ super.setUp();
+ }
+
+ public void testGroupBounds() {
+ assertEquals(g.getBounds(), wholeCanvas);
+ }
+}
diff --git a/docs/teaching/exercises/tests/Test4b.java b/docs/teaching/exercises/tests/Test4b.java
new file mode 100644
index 000000000..609289508
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test4b.java
@@ -0,0 +1,70 @@
+/* *******************************************************************
+ * 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 java.awt.Rectangle;
+
+import junit.framework.*;
+
+public class Test4b extends Test {
+
+ public Test4b(String name) { super(name); }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test4b.class);
+ }
+
+ public void setUp() {
+ super.setUp();
+ }
+
+ public void testBasicEquality() {
+ assertTrue(g.getBounds() == g.getBounds());
+ }
+
+ public void testEqualityAfterAddition() {
+ Point p0 = new Point(1, 2);
+ Point p1 = new Point(2, 3);
+
+ Group g0 = new Group(p0);
+ Group g1 = new Group(p1);
+
+ Rectangle r0 = g0.getBounds();
+ Rectangle r1 = g1.getBounds();
+ assertTrue(r0 != r1);
+ g0.add(new Point(37, 90));
+ assertTrue(g0.getBounds() == r0);
+ assertTrue(g1.getBounds() != r0);
+ assertTrue(g0.getBounds() != r1);
+ assertTrue(g1.getBounds() == r1);
+
+ g1.add(new Point(4, 8));
+ assertTrue(g0.getBounds() == r0);
+ assertTrue(g1.getBounds() != r0);
+ assertTrue(g0.getBounds() != r1);
+ assertTrue(g1.getBounds() == r1);
+ }
+
+ public void testNotWholeCanvas() {
+ assertTrue("bounds for this group should not be the whole canvas",
+ g.getBounds().getWidth() <
+ (FigureElement.MAX_VALUE - FigureElement.MIN_VALUE));
+ assertTrue("bounds for this group should not be the whole canvas",
+ g.getBounds().getHeight() <
+ (FigureElement.MAX_VALUE - FigureElement.MIN_VALUE));
+
+ }
+}
+
+
diff --git a/docs/teaching/exercises/tests/Test4c.java b/docs/teaching/exercises/tests/Test4c.java
new file mode 100644
index 000000000..b5bf8f708
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test4c.java
@@ -0,0 +1,84 @@
+/* *******************************************************************
+ * 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 java.awt.Rectangle;
+
+import junit.framework.*;
+
+public class Test4c extends Test {
+
+ public Test4c(String name) { super(name); }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test4c.class);
+ }
+
+ public void setUp() {
+ super.setUp();
+ }
+
+ public void testBasicEquality() {
+ assertTrue(g.getBounds() == g.getBounds());
+ }
+
+ public void testEqualityAfterAddition() {
+ Point p0 = new Point(1, 2);
+ Point p1 = new Point(2, 3);
+
+ Group g0 = new Group(p0);
+ Group g1 = new Group(p1);
+
+ Rectangle r0 = g0.getBounds();
+ Rectangle r1 = g1.getBounds();
+ assertTrue(r0 != r1);
+ g0.add(new Point(37, 90));
+ assertTrue(g0.getBounds() == r0);
+ assertTrue(g1.getBounds() != r0);
+ assertTrue(g0.getBounds() != r1);
+ assertTrue(g1.getBounds() == r1);
+
+ g1.add(new Point(4, 8));
+ assertTrue(g0.getBounds() == r0);
+ assertTrue(g1.getBounds() != r0);
+ assertTrue(g0.getBounds() != r1);
+ assertTrue(g1.getBounds() == r1);
+ }
+
+ public void testEqualityAfterMove() {
+ Point p0 = new Point(1, 2);
+ Point p1 = new Point(2, 3);
+
+ Group g0 = new Group(p0);
+ Group g1 = new Group(p1);
+
+ Rectangle r0 = g0.getBounds();
+ Rectangle r1 = g1.getBounds();
+ assertTrue(r0 != r1);
+ assertTrue(g0.getBounds() == r0);
+ assertTrue(g1.getBounds() != r0);
+ assertTrue(g0.getBounds() != r1);
+ assertTrue(g1.getBounds() == r1);
+
+ g0.move(3, 1);
+ Rectangle r00 = g0.getBounds();
+ Rectangle r10 = g1.getBounds();
+
+ assertTrue(r10 != r00);
+ assertTrue(r0 != r00);
+ assertTrue(g0.getBounds() == r00);
+ }
+}
+
+
diff --git a/docs/teaching/exercises/tests/Test4d.java b/docs/teaching/exercises/tests/Test4d.java
new file mode 100644
index 000000000..e4458c6a4
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test4d.java
@@ -0,0 +1,81 @@
+/* *******************************************************************
+ * 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 java.awt.Rectangle;
+
+import junit.framework.*;
+
+public class Test4d extends Test {
+
+ public Test4d(String name) { super(name); }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test4d.class);
+ }
+
+ public void setUp() {
+ super.setUp();
+ }
+
+ public void testBasicEquality() {
+ assertTrue(g.getBounds() == g.getBounds());
+ }
+
+ public void testNonGroupMove() {
+ p1.move(3, 27);
+ }
+
+ public void testEqualityAfterAddition() {
+ Rectangle r = g.getBounds();
+ g.add(new Point(37, 90));
+ assertTrue(g.getBounds() == r);
+ }
+
+ public void testEqualityAfterMove() {
+ Point p0 = new Point(1, 2);
+ Point p1 = new Point(2, 3);
+
+ Group g0 = new Group(p0);
+ Group g1 = new Group(p1);
+
+ Rectangle r0 = g0.getBounds();
+ Rectangle r1 = g1.getBounds();
+ assertTrue(r0 != r1);
+ assertTrue(g0.getBounds() == r0);
+ assertTrue(g1.getBounds() != r0);
+ assertTrue(g0.getBounds() != r1);
+ assertTrue(g1.getBounds() == r1);
+
+ p0.move(3, 1);
+ Rectangle r00 = g0.getBounds();
+ Rectangle r10 = g1.getBounds();
+
+ assertTrue(r10 != r00);
+ assertTrue(r0 != r00);
+ assertTrue(g0.getBounds() == r00);
+ }
+
+ public void testEqualityAfterMove0() {
+ g = new Group(p1);
+ Rectangle r0 = g.getBounds();
+ assertTrue(g.getBounds() == r0);
+ p1.move(3, 1);
+ Rectangle r1 = g.getBounds();
+ assertTrue(r0 != r1);
+ assertTrue(r1 == g.getBounds());
+ }
+}
+
+
diff --git a/docs/teaching/exercises/tests/Test4e.java b/docs/teaching/exercises/tests/Test4e.java
new file mode 100644
index 000000000..f6a3635d2
--- /dev/null
+++ b/docs/teaching/exercises/tests/Test4e.java
@@ -0,0 +1,68 @@
+/* *******************************************************************
+ * 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 java.awt.Rectangle;
+
+import junit.framework.*;
+
+public class Test4e extends Test {
+
+ public Test4e(String name) { super(name); }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(Test4e.class);
+ }
+
+ public void setUp() {
+ super.setUp();
+ }
+
+ public void testBasicEquality() {
+ assertTrue(g.getBounds() == g.getBounds());
+ }
+
+ public void testNonGroupMove() {
+ p1.move(3, 27);
+ }
+
+ public void testEqualityAfterAddition() {
+ Rectangle r = g.getBounds();
+ g.add(new Point(37, 90));
+ assertTrue(g.getBounds() == r);
+ }
+
+ public void testEqualityAfterMove() {
+ g = new Group(p1);
+ Rectangle r0 = g.getBounds();
+ assertTrue(g.getBounds() == r0);
+ p1.move(3, 1);
+ Rectangle r1 = g.getBounds();
+ assertTrue(r0 != r1);
+ assertTrue(r1 == g.getBounds());
+ }
+
+ public void testSecondEnclosingGroup() {
+ g = new Group(p1);
+ Group h = new Group(g);
+ Rectangle r0 = h.getBounds();
+ assertTrue(h.getBounds() == r0);
+ p1.move(3, 1);
+ Rectangle r1 = h.getBounds();
+ assertTrue(r0 != r1);
+ assertTrue(r1 == h.getBounds());
+ }
+}
+
+