2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package gov.nasa.jpf.util;
20 import java.util.NoSuchElementException;
22 import gov.nasa.jpf.util.test.TestJPF;
23 import org.junit.Test;
25 public abstract class ArrayIntSetTestBase extends TestJPF {
27 protected abstract ArrayIntSet createArrayIntSet();
28 protected abstract ArrayIntSet createArrayIntSet(int n);
31 public void testInsert(){
32 ArrayIntSet s = createArrayIntSet();
39 System.out.println(s);
41 assertTrue(s.size() == 4);
42 assertTrue(s.contains(0));
43 assertTrue(s.contains(41));
44 assertTrue(s.contains(42));
45 assertTrue(s.contains(43));
49 public void testRemove(){
50 ArrayIntSet s = createArrayIntSet();
52 assertTrue(s.size() == 1);
53 assertTrue(s.contains(42));
56 assertFalse(s.contains(42));
57 assertTrue(s.size() == 0);
62 assertTrue(s.size() == 3);
64 assertTrue(s.size() == 2);
65 assertFalse(s.contains(42000));
67 assertFalse(s.contains(0));
68 assertTrue(s.size() == 1);
72 public void testRemoveLast(){
73 ArrayIntSet s = createArrayIntSet(2);
78 assertTrue( s.size() == 1);
79 assertTrue( s.contains(1));
82 assertTrue( s.isEmpty());
86 public void testRemoveFirst(){
87 ArrayIntSet s = createArrayIntSet(2);
92 assertTrue( s.size() == 1);
93 assertTrue( s.contains(2));
96 assertTrue( s.isEmpty());
101 public void testIterator(){
102 ArrayIntSet s = createArrayIntSet();
108 IntIterator it = s.intIterator();
109 while (it.hasNext()){
110 System.out.print(it.next());
113 System.out.println();
116 assertTrue( !it.hasNext());
119 fail("iterator failed to throw NoSuchElementException");
120 } catch (NoSuchElementException nsex){
124 it = s.intIterator(); // fresh one
125 while (it.hasNext()){
128 assertTrue( s.size() == 2);
135 assertTrue(s.size() == 1);
136 assertTrue( !it.hasNext());
139 it = s.intIterator();
140 assertTrue(it.next() == 1);
142 assertTrue( it.next() == 42);
144 assertTrue( s.isEmpty());
148 public void testComparison(){
158 ArrayIntSet[] set = new ArrayIntSet[a.length];
160 for (int i=0; i< a.length; i++) {
161 set[i]= createArrayIntSet();
163 for (int j=0; j<v.length; j++) {
168 ArrayIntSet s1 = null, s2 = null;
169 for (int i=1; i< a.length; i++) {
172 System.out.println("comparing " + s1 + " with " + s2);
174 assertTrue(s1.hashCode() == s2.hashCode());
175 assertTrue(s1.equals(s2));
180 assertFalse( s1.hashCode() == s2.hashCode());
181 assertFalse( s1.equals(s2));