1 | public class YIntervalTests extends TestCase {↵ | | 1 | public class YWithXIntervalTests extends TestCase {↵
|
|
2 | /**↵ | | 2 | /**↵
|
3 | * Returns the tests as a test suite.↵ | | 3 | * Returns the tests as a test suite.↵
|
4 | *↵ | | 4 | *↵
|
5 | * @return The test suite.↵ | | 5 | * @return The test suite.↵
|
6 | */↵ | | 6 | */↵
|
7 | public static Test suite() {↵ | | 7 | public static Test suite() {↵
|
8 | return new TestSuite(YIntervalTests.class);↵ | | 8 | return new TestSuite(YWithXIntervalTests.class);↵
|
9 | }↵ | | 9 | }↵
|
|
10 | /**↵ | | 10 | /**↵
|
11 | * Constructs a new set of tests.↵ | | 11 | * Constructs a new set of tests.↵
|
12 | *↵ | | 12 | *↵
|
13 | * @param name the name of the tests.↵ | | 13 | * @param name the name of the tests.↵
|
14 | */↵ | | 14 | */↵
|
15 | public YIntervalTests(String name) {↵ | | 15 | public YWithXIntervalTests(String name) {↵
|
16 | super(name);↵ | | 16 | super(name);↵
|
17 | }↵ | | 17 | }↵
|
|
18 | /**↵ | | 18 | /**↵
|
19 | * Confirm that the equals method can distinguish all the required fields.↵ | | 19 | * Confirm that the equals method can distinguish all the required fields.↵
|
20 | */↵ | | 20 | */↵
|
21 | public void testEquals() {↵ | | 21 | public void testEquals() {↵
|
22 | YInterval i1 = new YInterval(1.0, 0.5, 1.5);↵ | | 22 | YWithXInterval i1 = new YWithXInterval(1.0, 0.5, 1.5);↵
|
23 | YInterval i2 = new YInterval(1.0, 0.5, 1.5);↵ | | 23 | YWithXInterval i2 = new YWithXInterval(1.0, 0.5, 1.5);↵
|
24 | assertEquals(i1, i2);↵ | | 24 | assertEquals(i1, i2);↵
|
25 | ↵ | | 25 | ↵
|
26 | i1 = new YInterval(1.1, 0.5, 1.5);↵ | | 26 | i1 = new YWithXInterval(1.1, 0.5, 1.5);↵
|
27 | assertFalse(i1.equals(i2));↵ | | 27 | assertFalse(i1.equals(i2));↵
|
28 | i2 = new YInterval(1.1, 0.5, 1.5);↵ | | 28 | i2 = new YWithXInterval(1.1, 0.5, 1.5);↵
|
29 | assertTrue(i1.equals(i2));↵ | | 29 | assertTrue(i1.equals(i2));↵
|
|
30 | i1 = new YInterval(1.1, 0.55, 1.5);↵ | | 30 | i1 = new YWithXInterval(1.1, 0.55, 1.5);↵
|
31 | assertFalse(i1.equals(i2));↵ | | 31 | assertFalse(i1.equals(i2));↵
|
32 | i2 = new YInterval(1.1, 0.55, 1.5);↵ | | 32 | i2 = new YWithXInterval(1.1, 0.55, 1.5);↵
|
33 | assertTrue(i1.equals(i2));↵ | | 33 | assertTrue(i1.equals(i2));↵
|
34 | ↵ | | 34 | ↵
|
35 | i1 = new YInterval(1.1, 0.55, 1.55);↵ | | 35 | i1 = new YWithXInterval(1.1, 0.55, 1.55);↵
|
36 | assertFalse(i1.equals(i2));↵ | | 36 | assertFalse(i1.equals(i2));↵
|
37 | i2 = new YInterval(1.1, 0.55, 1.55);↵ | | 37 | i2 = new YWithXInterval(1.1, 0.55, 1.55);↵
|
38 | assertTrue(i1.equals(i2));↵ | | 38 | assertTrue(i1.equals(i2));↵
|
39 | }↵ | | 39 | }↵
|
|
40 | /**↵ | | 40 | /**↵
|
41 | * This class is immutable.↵ | | 41 | * This class is immutable.↵
|
42 | */↵ | | 42 | */↵
|
43 | public void testCloning() {↵ | | 43 | public void testCloning() {↵
|
44 | YInterval i1 = new YInterval(1.0, 0.5, 1.5);↵ | | 44 | YWithXInterval i1 = new YWithXInterval(1.0, 0.5, 1.5);↵
|
45 | assertFalse(i1 instanceof Cloneable);↵ | | 45 | assertFalse(i1 instanceof Cloneable);↵
|
46 | }↵ | | 46 | }↵
|
|
47 | /**↵ | | 47 | /**↵
|
48 | * Serialize an instance, restore it, and check for equality.↵ | | 48 | * Serialize an instance, restore it, and check for equality.↵
|
49 | */↵ | | 49 | */↵
|
50 | public void testSerialization() {↵ | | 50 | public void testSerialization() {↵
|
51 | YInterval i1 = new YInterval(1.0, 0.5, 1.5);↵ | | 51 | YWithXInterval i1 = new YWithXInterval(1.0, 0.5, 1.5);↵
|
52 | YInterval i2 = null;↵ | | 52 | YWithXInterval i2 = null;↵
|
53 | ↵ | | 53 | ↵
|
54 | try {↵ | | 54 | try {↵
|
55 | ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵ | | 55 | ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵
|
56 | ObjectOutput out = new ObjectOutputStream(buffer);↵ | | 56 | ObjectOutput out = new ObjectOutputStream(buffer);↵
|
57 | out.writeObject(i1);↵ | | 57 | out.writeObject(i1);↵
|
58 | out.close();↵ | | 58 | out.close();↵
|
|
59 | ObjectInput in = new ObjectInputStream(↵ | | 59 | ObjectInput in = new ObjectInputStream(↵
|
60 | new ByteArrayInputStream(buffer.toByteArray()));↵ | | 60 | new ByteArrayInputStream(buffer.toByteArray()));↵
|
61 | i2 = (YInterval) in.readObject();↵ | | 61 | i2 = (YWithXInterval) in.readObject();↵
|
62 | in.close();↵ | | 62 | in.close();↵
|
63 | }↵ | | 63 | }↵
|
64 | catch (Exception e) {↵ | | 64 | catch (Exception e) {↵
|
65 | e.printStackTrace();↵ | | 65 | e.printStackTrace();↵
|
66 | }↵ | | 66 | }↵
|
67 | assertEquals(i1, i2) | | 67 | assertEquals(i1, i2)
|