1 | public class DefaultKeyedValues2DDatasetTests extends TestCase {↵ | | 1 | public class DefaultKeyedValuesDatasetTests 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(DefaultKeyedValues2DDatasetTests.class);↵ | | 8 | return new TestSuite(DefaultKeyedValuesDatasetTests.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 DefaultKeyedValues2DDatasetTests(String name) {↵ | | 15 | public DefaultKeyedValuesDatasetTests(String name) {↵
|
16 | super(name);↵ | | 16 | super(name);↵
|
17 | }↵ | | 17 | }↵
|
|
18 | /**↵ | | 18 | /**↵
|
19 | * Confirm that cloning works.↵ | | 19 | * Confirm that cloning works.↵
|
20 | */↵ | | 20 | */↵
|
21 | public void testCloning() {↵ | | 21 | public void testCloning() {↵
|
22 | DefaultKeyedValues2DDataset d1 = new DefaultKeyedValues2DDataset();↵ | | 22 | DefaultKeyedValuesDataset d1 = new DefaultKeyedValuesDataset();↵
|
23 | d1.setValue(new Integer(1), "V1", "C1");↵ | | 23 | d1.setValue("V1", new Integer(1));↵
|
24 | d1.setValue(null, "V2", "C1");↵ | | 24 | d1.setValue("V2", null);↵
|
25 | d1.setValue(new Integer(3), "V3", "C2");↵ | | 25 | d1.setValue("V3", new Integer(3));↵
|
26 | DefaultKeyedValues2DDataset d2 = null;↵ | | 26 | DefaultKeyedValuesDataset d2 = null;↵
|
27 | try {↵ | | 27 | try {↵
|
28 | d2 = (DefaultKeyedValues2DDataset) d1.clone();↵ | | 28 | d2 = (DefaultKeyedValuesDataset) d1.clone();↵
|
29 | }↵ | | 29 | }↵
|
30 | catch (CloneNotSupportedException e) {↵ | | 30 | catch (CloneNotSupportedException e) {↵
|
31 | System.err.println("Failed to clone.");↵ | | 31 | System.err.println("Failed to clone.");↵
|
32 | }↵ | | 32 | }↵
|
33 | assertTrue(d1 != d2);↵ | | 33 | assertTrue(d1 != d2);↵
|
34 | assertTrue(d1.getClass() == d2.getClass());↵ | | 34 | assertTrue(d1.getClass() == d2.getClass());↵
|
35 | assertTrue(d1.equals(d2));↵ | | 35 | assertTrue(d1.equals(d2));↵
|
36 | }↵ | | 36 | }↵
|
37 | ↵ | | |
|
38 | /**↵ | | 37 | /**↵
|
39 | * Serialize an instance, restore it, and check for equality.↵ | | 38 | * Serialize an instance, restore it, and check for equality.↵
|
40 | */↵ | | 39 | */↵
|
41 | public void testSerialization() {↵ | | 40 | public void testSerialization() {↵
|
|
42 | DefaultKeyedValues2DDataset d1 = new DefaultKeyedValues2DDataset();↵ | | 41 | DefaultKeyedValuesDataset d1 = new DefaultKeyedValuesDataset();↵
|
43 | d1.addValue(new Double(234.2), "Row1", "Col1");↵ | | 42 | d1.setValue("C1", new Double(234.2));↵
|
44 | d1.addValue(null, "Row1", "Col2");↵ | | 43 | d1.setValue("C2", null);↵
|
45 | d1.addValue(new Double(345.9), "Row2", "Col1");↵ | | 44 | d1.setValue("C3", new Double(345.9));↵
|
46 | d1.addValue(new Double(452.7), "Row2", "Col2");↵ | | 45 | d1.setValue("C4", new Double(452.7));↵
|
|
47 | DefaultKeyedValues2DDataset d2 = null;↵ | | 46 | KeyedValuesDataset d2 = null;↵
|
|
48 | try {↵ | | 47 | try {↵
|
49 | ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵ | | 48 | ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵
|
50 | ObjectOutput out = new ObjectOutputStream(buffer);↵ | | 49 | ObjectOutput out = new ObjectOutputStream(buffer);↵
|
51 | out.writeObject(d1);↵ | | 50 | out.writeObject(d1);↵
|
52 | out.close();↵ | | 51 | out.close();↵
|
|
53 | ObjectInput in = new ObjectInputStream(↵ | | 52 | ObjectInput in = new ObjectInputStream(↵
|
54 | new ByteArrayInputStream(buffer.toByteArray())↵ | | 53 | new ByteArrayInputStream(buffer.toByteArray())↵
|
55 | );↵ | | 54 | );↵
|
56 | d2 = (DefaultKeyedValues2DDataset) in.readObject();↵ | | 55 | d2 = (KeyedValuesDataset) in.readObject();↵
|
57 | in.close();↵ | | 56 | in.close();↵
|
58 | }↵ | | 57 | }↵
|
59 | catch (Exception e) {↵ | | 58 | catch (Exception e) {↵
|
60 | System.out.println(e.toString());↵ | | 59 | System.out.println(e.toString());↵
|
61 | }↵ | | 60 | }↵
|
62 | assertEquals(d1, d2) | | 61 | assertEquals(d1, d2)
|