1 package edu.uci.ics.jung.graph.util;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import edu.uci.ics.jung.graph.util.Pair;
7
8 import junit.framework.TestCase;
9
10 public class PairTest extends TestCase {
11
12 Pair<Number> pair;
13
14
15 @Override
16 protected void setUp() throws Exception {
17 pair = new Pair<Number>(1,2);
18 super.setUp();
19 }
20
21 public void testGetFirst() {
22 assertEquals(pair.getFirst(), 1);
23 }
24
25 public void testGetSecond() {
26 assertEquals(pair.getSecond(), 2);
27 }
28
29 public void testEqualsObject() {
30 Pair<Number> ipair = new Pair<Number>(1,2);
31 assertTrue(pair.equals(ipair));
32 }
33
34 public void testAdd() {
35 try {
36 pair.add(3);
37 fail("should not be able to add to Pair");
38 } catch(Exception e) {
39
40 }
41 }
42
43 public void testAddAll() {
44 try {
45 List<Number> list = new ArrayList<Number>(pair);
46 pair.addAll(list);
47 fail("should not be able to addAll to Pair");
48 } catch(Exception e) {
49
50 }
51 }
52
53 public void testClear() {
54 try {
55 pair.clear();
56 fail("should not be able to clear a Pair");
57 } catch(Exception e) {
58
59 }
60 }
61
62 public void testContains() {
63 assertTrue(pair.contains(1));
64 }
65
66 public void testContainsAll() {
67 List<Number> list = new ArrayList<Number>(pair);
68 assertTrue(pair.containsAll(list));
69 }
70
71 public void testIsEmpty() {
72 assertFalse(pair.isEmpty());
73 }
74
75 public void testRemove() {
76 try {
77 pair.remove(1);
78 fail("should not be able to remove from a Pair");
79 } catch(Exception e) {
80
81 }
82 }
83
84 public void testRemoveAll() {
85 try {
86 List<Number> list = new ArrayList<Number>(pair);
87 pair.removeAll(list);
88 fail("should not be able to removeAll from Pair");
89 } catch(Exception e) {
90
91 }
92 }
93
94 public void testRetainAll() {
95 try {
96 List<Number> list = new ArrayList<Number>(pair);
97 pair.retainAll(list);
98 fail("should not be able to retainAll from Pair");
99 } catch(Exception e) {
100
101 }
102 }
103
104 public void testSize() {
105 assertEquals(pair.size(), 2);
106 }
107
108 public void testToArray() {
109 @SuppressWarnings("unused")
110 Object[] arr = pair.toArray();
111 }
112
113 public void testToArraySArray() {
114 @SuppressWarnings("unused")
115 Integer[] arr = pair.<Integer>toArray(new Integer[2]);
116 }
117
118 }