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.
19 package gov.nasa.jpf.util;
21 import gov.nasa.jpf.util.test.TestJPF;
23 import org.junit.Test;
26 * unit test for IntTable
28 public class IntTableTest extends TestJPF {
31 public void testBasicPut(){
32 IntTable<Integer> tbl = new IntTable<Integer>();
34 assert tbl.size() == 0;
37 for (int i=0; i<N; i++){
40 IntTable.Entry<Integer> e = tbl.get(i);
44 assert tbl.size() == N;
49 public void testStringKeyAdd(){
50 IntTable<String> tbl = new IntTable<String>();
52 assert tbl.size() == 0;
55 for (int i=0; i<N; i++){
56 String key = "averylonginttablekey-" + i;
59 IntTable.Entry<String> e = tbl.get(key);
63 assert tbl.size() == N;
67 public void testClone(){
68 IntTable<String> tbl = new IntTable<String>(3); // make it small so that we rehash
74 IntTable<String> t1 = tbl.clone();
76 for (int i=10; i<20; i++){
77 t1.add(Integer.toString(i), i);
80 assert tbl.size() == 3;
81 System.out.println("-- original table");
82 for (IntTable.Entry<String> e : tbl){
83 assert Integer.parseInt(e.key) == e.val;
84 System.out.println(e);
87 assert t1.size() == 13;
88 System.out.println("-- cloned+modified table");
89 for (IntTable.Entry<String> e : t1){
90 assert Integer.parseInt(e.key) == e.val;
91 System.out.println(e);
96 public void testSnapshot (){
97 IntTable<String> tbl = new IntTable<String>();
102 tbl.add("12345", 12345);
105 IntTable.Snapshot<String> snap = tbl.getSnapshot();
112 assertTrue(tbl.size() == 3);
117 assertTrue(tbl.size() == 4);
118 assertTrue(tbl.hasEntry("1"));
119 assertTrue(tbl.hasEntry("2"));
120 assertTrue(tbl.hasEntry("3"));
121 assertTrue(tbl.hasEntry("12345"));