/external/apache-harmony/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TreeMapExtendTest.java
https://gitlab.com/brian0218/rk3188_r-box_android4.2.2_sdk · Java · 1345 lines · 1009 code · 240 blank · 96 comment · 11 complexity · 0397a875e7614b624723d9d60c68ba28 MD5 · raw file
- package org.apache.harmony.luni.tests.java.util;
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- import java.util.Collection;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.NavigableMap;
- import java.util.NavigableSet;
- import java.util.NoSuchElementException;
- import java.util.Set;
- import java.util.SortedMap;
- import java.util.SortedSet;
- import java.util.TreeMap;
- import java.util.Map.Entry;
- import junit.framework.TestCase;
- import org.apache.harmony.luni.tests.java.util.TreeMapTest.MockComparator;
- //
- public class TreeMapExtendTest extends TestCase {
- TreeMap tm;
- TreeMap tm_comparator;
- SortedMap subMap_default;
- SortedMap subMap_startExcluded_endExcluded;
- SortedMap subMap_startExcluded_endIncluded;
- SortedMap subMap_startIncluded_endExcluded;
- SortedMap subMap_startIncluded_endIncluded;
- SortedMap subMap_default_beforeStart_100;
- SortedMap subMap_default_afterEnd_109;
- NavigableMap navigableMap_startExcluded_endExcluded;
- NavigableMap navigableMap_startExcluded_endIncluded;
- NavigableMap navigableMap_startIncluded_endExcluded;
- NavigableMap navigableMap_startIncluded_endIncluded;
- SortedMap subMap_default_comparator;
- SortedMap subMap_startExcluded_endExcluded_comparator;
- SortedMap subMap_startExcluded_endIncluded_comparator;
- SortedMap subMap_startIncluded_endExcluded_comparator;
- SortedMap subMap_startIncluded_endIncluded_comparator;
- Object objArray[] = new Object[1000];
- public void test_TreeMap_Constructor_Default() {
- TreeMap treeMap = new TreeMap();
- assertTrue(treeMap.isEmpty());
- assertNull(treeMap.comparator());
- assertEquals(0, treeMap.size());
- try {
- treeMap.firstKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- assertNull(treeMap.firstEntry());
- try {
- treeMap.lastKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- assertNull(treeMap.lastEntry());
- try {
- treeMap.ceilingKey(1);
- } catch (NoSuchElementException e) {
- // Expected
- }
- assertNull(treeMap.ceilingEntry(1));
- try {
- treeMap.floorKey(1);
- } catch (NoSuchElementException e) {
- // Expected
- }
- assertNull(treeMap.floorEntry(1));
- assertNull(treeMap.lowerKey(1));
- assertNull(treeMap.lowerEntry(1));
- assertNull(treeMap.higherKey(1));
- assertNull(treeMap.higherEntry(1));
- assertFalse(treeMap.containsKey(1));
- assertFalse(treeMap.containsValue(1));
- assertNull(treeMap.get(1));
- assertNull(treeMap.pollFirstEntry());
- assertNull(treeMap.pollLastEntry());
- assertEquals(0, treeMap.values().size());
- }
- public void test_TreeMap_Constructor_Comparator() {
- MockComparator mockComparator = new MockComparator();
- TreeMap treeMap = new TreeMap(mockComparator);
- assertEquals(mockComparator, treeMap.comparator());
- }
- public void test_TreeMap_Constructor_Map() {
- TreeMap treeMap = new TreeMap(tm);
- assertEquals(tm.size(), treeMap.size());
- assertEquals(tm.firstKey(), treeMap.firstKey());
- assertEquals(tm.firstEntry(), treeMap.firstEntry());
- assertEquals(tm.lastKey(), treeMap.lastKey());
- assertEquals(tm.lastEntry(), treeMap.lastEntry());
- assertEquals(tm.keySet(), treeMap.keySet());
- String key = new Integer(100).toString();
- assertEquals(tm.ceilingKey(key), treeMap.ceilingKey(key));
- assertEquals(tm.ceilingEntry(key), treeMap.ceilingEntry(key));
- assertEquals(tm.floorKey(key), treeMap.floorKey(key));
- assertEquals(tm.floorEntry(key), treeMap.floorEntry(key));
- assertEquals(tm.lowerKey(key), treeMap.lowerKey(key));
- assertEquals(tm.lowerEntry(key), treeMap.lowerEntry(key));
- assertEquals(tm.higherKey(key), treeMap.higherKey(key));
- assertEquals(tm.higherEntry(key), treeMap.higherEntry(key));
- assertEquals(tm.entrySet(), treeMap.entrySet());
- }
- public void test_TreeMap_Constructor_SortedMap() {
- TreeMap treeMap = new TreeMap(subMap_default);
- assertEquals(subMap_default.size(), treeMap.size());
- assertEquals(subMap_default.firstKey(), treeMap.firstKey());
- assertEquals(subMap_default.lastKey(), treeMap.lastKey());
- assertEquals(subMap_default.keySet(), treeMap.keySet());
- assertEquals(subMap_default.entrySet(), treeMap.entrySet());
- }
- public void test_TreeMap_clear() {
- tm.clear();
- assertEquals(0, tm.size());
- }
- public void test_TreeMap_clone() {
- TreeMap cloneTreeMap = (TreeMap) tm.clone();
- assertEquals(tm, cloneTreeMap);
- }
- public void test_SubMap_Constructor() {
- }
- public void test_SubMap_clear() {
- subMap_default.clear();
- assertEquals(0, subMap_default.size());
- }
- public void test_SubMap_comparator() {
- assertEquals(tm.comparator(), subMap_default.comparator());
- }
- public void test_SubMap_containsKey() {
- String key = null;
- for (int counter = 101; counter < 109; counter++) {
- key = objArray[counter].toString();
- assertTrue("SubMap contains incorrect elements", subMap_default
- .containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startExcluded_endExcluded.containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startExcluded_endIncluded.containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startIncluded_endExcluded.containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startIncluded_endIncluded.containsKey(key));
- }
- // Check boundary
- key = objArray[100].toString();
- assertTrue("SubMap contains incorrect elements", subMap_default
- .containsKey(key));
- assertFalse("SubMap contains incorrect elements",
- subMap_startExcluded_endExcluded.containsKey(key));
- assertFalse("SubMap contains incorrect elements",
- subMap_startExcluded_endIncluded.containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startIncluded_endExcluded.containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startIncluded_endIncluded.containsKey(key));
- key = objArray[109].toString();
- assertFalse("SubMap contains incorrect elements", subMap_default
- .containsKey(key));
- assertFalse("SubMap contains incorrect elements",
- subMap_startExcluded_endExcluded.containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startExcluded_endIncluded.containsKey(key));
- assertFalse("SubMap contains incorrect elements",
- subMap_startIncluded_endExcluded.containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startIncluded_endIncluded.containsKey(key));
- // With Comparator
- for (int counter = 101; counter < 109; counter++) {
- key = objArray[counter].toString();
- assertTrue("SubMap contains incorrect elements",
- subMap_default_comparator.containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startExcluded_endExcluded_comparator
- .containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startExcluded_endIncluded_comparator
- .containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startIncluded_endExcluded_comparator
- .containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startIncluded_endIncluded_comparator
- .containsKey(key));
- }
- // Check boundary
- key = objArray[100].toString();
- assertTrue("SubMap contains incorrect elements",
- subMap_default_comparator.containsKey(key));
- assertFalse("SubMap contains incorrect elements",
- subMap_startExcluded_endExcluded_comparator.containsKey(key));
- assertFalse("SubMap contains incorrect elements",
- subMap_startExcluded_endIncluded_comparator.containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startIncluded_endExcluded_comparator.containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startIncluded_endIncluded_comparator.containsKey(key));
- key = objArray[109].toString();
- assertFalse("SubMap contains incorrect elements",
- subMap_default_comparator.containsKey(key));
- assertFalse("SubMap contains incorrect elements",
- subMap_startExcluded_endExcluded_comparator.containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startExcluded_endIncluded_comparator.containsKey(key));
- assertFalse("SubMap contains incorrect elements",
- subMap_startIncluded_endExcluded_comparator.containsKey(key));
- assertTrue("SubMap contains incorrect elements",
- subMap_startIncluded_endIncluded_comparator.containsKey(key));
- }
- public void test_SubMap_containsValue() {
- Object value = null;
- for (int counter = 101; counter < 109; counter++) {
- value = objArray[counter];
- assertTrue("SubMap contains incorrect elements", subMap_default
- .containsValue(value));
- assertTrue("SubMap contains incorrect elements",
- subMap_startExcluded_endExcluded.containsValue(value));
- assertTrue("SubMap contains incorrect elements",
- subMap_startExcluded_endIncluded.containsValue(value));
- assertTrue("SubMap contains incorrect elements",
- subMap_startIncluded_endExcluded.containsValue(value));
- assertTrue("SubMap contains incorrect elements",
- subMap_startIncluded_endIncluded.containsValue(value));
- }
- // Check boundary
- value = objArray[100];
- assertTrue("SubMap contains incorrect elements", subMap_default
- .containsValue(value));
- assertFalse("SubMap contains incorrect elements",
- subMap_startExcluded_endExcluded.containsValue(value));
- assertFalse("SubMap contains incorrect elements",
- subMap_startExcluded_endIncluded.containsValue(value));
- assertTrue("SubMap contains incorrect elements",
- subMap_startIncluded_endExcluded.containsValue(value));
- assertTrue("SubMap contains incorrect elements",
- subMap_startIncluded_endIncluded.containsValue(value));
- value = objArray[109];
- assertFalse("SubMap contains incorrect elements", subMap_default
- .containsValue(value));
- assertFalse("SubMap contains incorrect elements",
- subMap_startExcluded_endExcluded.containsValue(value));
- assertTrue("SubMap contains incorrect elements",
- subMap_startExcluded_endIncluded.containsValue(value));
- assertFalse("SubMap contains incorrect elements",
- subMap_startIncluded_endExcluded.containsValue(value));
- assertTrue("SubMap contains incorrect elements",
- subMap_startIncluded_endIncluded.containsValue(value));
- assertFalse(subMap_default.containsValue(null));
- TreeMap tm_null = new TreeMap();
- tm_null.put("0", 1);
- tm_null.put("1", null);
- tm_null.put("2", 2);
- SortedMap subMap = tm_null.subMap("0", "2");
- assertTrue(subMap.containsValue(null));
- subMap.remove("1");
- assertFalse(subMap.containsValue(null));
- }
- public void test_SubMap_entrySet() {
- Set entrySet = subMap_default.entrySet();
- assertFalse(entrySet.isEmpty());
- assertEquals(9, entrySet.size());
- entrySet = subMap_startExcluded_endExcluded.entrySet();
- assertFalse(entrySet.isEmpty());
- assertEquals(8, entrySet.size());
- entrySet = subMap_startExcluded_endIncluded.entrySet();
- assertFalse(entrySet.isEmpty());
- assertEquals(9, entrySet.size());
- entrySet = subMap_startIncluded_endExcluded.entrySet();
- assertFalse(entrySet.isEmpty());
- assertEquals(9, entrySet.size());
- entrySet = subMap_startIncluded_endIncluded.entrySet();
- assertFalse(entrySet.isEmpty());
- assertEquals(10, entrySet.size());
- }
- public void test_SubMap_firstKey() {
- String firstKey1 = new Integer(100).toString();
- String firstKey2 = new Integer(101).toString();
- assertEquals(firstKey1, subMap_default.firstKey());
- assertEquals(firstKey2, subMap_startExcluded_endExcluded.firstKey());
- assertEquals(firstKey2, subMap_startExcluded_endIncluded.firstKey());
- assertEquals(firstKey1, subMap_startIncluded_endExcluded.firstKey());
- assertEquals(firstKey1, subMap_startIncluded_endIncluded.firstKey());
- try {
- subMap_default.subMap(firstKey1, firstKey1).firstKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endExcluded.subMap(firstKey2, firstKey2)
- .firstKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endIncluded.subMap(firstKey2, firstKey2)
- .firstKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endExcluded.subMap(firstKey1, firstKey1)
- .firstKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endIncluded.subMap(firstKey1, firstKey1)
- .firstKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- // With Comparator
- assertEquals(firstKey1, subMap_default_comparator.firstKey());
- assertEquals(firstKey2, subMap_startExcluded_endExcluded_comparator
- .firstKey());
- assertEquals(firstKey2, subMap_startExcluded_endIncluded_comparator
- .firstKey());
- assertEquals(firstKey1, subMap_startIncluded_endExcluded_comparator
- .firstKey());
- assertEquals(firstKey1, subMap_startIncluded_endIncluded_comparator
- .firstKey());
- try {
- subMap_default_comparator.subMap(firstKey1, firstKey1).firstKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endExcluded_comparator.subMap(firstKey2,
- firstKey2).firstKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endIncluded_comparator.subMap(firstKey2,
- firstKey2).firstKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endExcluded_comparator.subMap(firstKey1,
- firstKey1).firstKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endIncluded_comparator.subMap(firstKey1,
- firstKey1).firstKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- }
- public void test_SubMap_lastKey() {
- String lastKey1 = new Integer(108).toString();
- String lastKey2 = new Integer(109).toString();
- assertEquals(lastKey1, subMap_default.lastKey());
- assertEquals(lastKey1, subMap_startExcluded_endExcluded.lastKey());
- assertEquals(lastKey2, subMap_startExcluded_endIncluded.lastKey());
- assertEquals(lastKey1, subMap_startIncluded_endExcluded.lastKey());
- assertEquals(lastKey2, subMap_startIncluded_endIncluded.lastKey());
- try {
- subMap_default.subMap(lastKey1, lastKey1).lastKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endExcluded.subMap(lastKey1, lastKey1)
- .lastKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endIncluded.subMap(lastKey2, lastKey2)
- .lastKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endExcluded.subMap(lastKey1, lastKey1)
- .lastKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endIncluded.subMap(lastKey2, lastKey2)
- .lastKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- // With Comparator
- assertEquals(lastKey1, subMap_default_comparator.lastKey());
- assertEquals(lastKey1, subMap_startExcluded_endExcluded_comparator
- .lastKey());
- assertEquals(lastKey2, subMap_startExcluded_endIncluded_comparator
- .lastKey());
- assertEquals(lastKey1, subMap_startIncluded_endExcluded_comparator
- .lastKey());
- assertEquals(lastKey2, subMap_startIncluded_endIncluded_comparator
- .lastKey());
- try {
- subMap_default_comparator.subMap(lastKey1, lastKey1).lastKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endExcluded_comparator.subMap(lastKey1,
- lastKey1).lastKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endIncluded_comparator.subMap(lastKey2,
- lastKey2).lastKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endExcluded_comparator.subMap(lastKey1,
- lastKey1).lastKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endIncluded_comparator.subMap(lastKey2,
- lastKey2).lastKey();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- }
- public void test_SubMap_get() {
- // left boundary
- Integer value = new Integer(100);
- assertEquals(value, subMap_default.get(value.toString()));
- assertEquals(null, subMap_startExcluded_endExcluded.get(value
- .toString()));
- assertEquals(null, subMap_startExcluded_endIncluded.get(value
- .toString()));
- assertEquals(value, subMap_startIncluded_endExcluded.get(value
- .toString()));
- assertEquals(value, subMap_startIncluded_endIncluded.get(value
- .toString()));
- // normal value
- value = new Integer(105);
- assertEquals(value, subMap_default.get(value.toString()));
- assertEquals(value, subMap_startExcluded_endExcluded.get(value
- .toString()));
- assertEquals(value, subMap_startExcluded_endIncluded.get(value
- .toString()));
- assertEquals(value, subMap_startIncluded_endExcluded.get(value
- .toString()));
- assertEquals(value, subMap_startIncluded_endIncluded.get(value
- .toString()));
- // right boundary
- value = new Integer(109);
- assertEquals(null, subMap_default.get(value.toString()));
- assertEquals(null, subMap_startExcluded_endExcluded.get(value
- .toString()));
- assertEquals(value, subMap_startExcluded_endIncluded.get(value
- .toString()));
- assertEquals(null, subMap_startIncluded_endExcluded.get(value
- .toString()));
- assertEquals(value, subMap_startIncluded_endIncluded.get(value
- .toString()));
- // With Comparator to test inInRange
- // left boundary
- value = new Integer(100);
- assertEquals(value, subMap_default_comparator.get(value.toString()));
- // normal value
- value = new Integer(105);
- assertEquals(value, subMap_default_comparator.get(value.toString()));
- // right boundary
- value = new Integer(109);
- assertEquals(null, subMap_default_comparator.get(value.toString()));
- }
- public void test_SubMap_headMap() {
- String endKey = new Integer(99).toString();
- try {
- subMap_default.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endExcluded.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endIncluded.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endExcluded.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endIncluded.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- SortedMap headMap = null;
- endKey = new Integer(100).toString();
- headMap = subMap_default.headMap(endKey);
- assertEquals(0, headMap.size());
- headMap = subMap_startExcluded_endExcluded.headMap(endKey);
- assertEquals(0, headMap.size());
- headMap = subMap_startExcluded_endIncluded.headMap(endKey);
- assertEquals(0, headMap.size());
- headMap = subMap_startIncluded_endExcluded.headMap(endKey);
- assertEquals(0, headMap.size());
- headMap = subMap_startIncluded_endIncluded.headMap(endKey);
- assertEquals(0, headMap.size());
- for (int i = 0, j = 101; i < 8; i++) {
- endKey = new Integer(i + j).toString();
- headMap = subMap_default.headMap(endKey);
- assertEquals(i + 1, headMap.size());
- headMap = subMap_startExcluded_endExcluded.headMap(endKey);
- assertEquals(i, headMap.size());
- headMap = subMap_startExcluded_endIncluded.headMap(endKey);
- assertEquals(i, headMap.size());
- headMap = subMap_startIncluded_endExcluded.headMap(endKey);
- assertEquals(i + 1, headMap.size());
- headMap = subMap_startIncluded_endIncluded.headMap(endKey);
- assertEquals(i + 1, headMap.size());
- }
- endKey = new Integer(109).toString();
- headMap = subMap_default.headMap(endKey);
- assertEquals(9, headMap.size());
- headMap = subMap_startExcluded_endExcluded.headMap(endKey);
- assertEquals(8, headMap.size());
- headMap = subMap_startExcluded_endIncluded.headMap(endKey);
- assertEquals(8, headMap.size());
- headMap = subMap_startIncluded_endExcluded.headMap(endKey);
- assertEquals(9, headMap.size());
- headMap = subMap_startIncluded_endIncluded.headMap(endKey);
- assertEquals(9, headMap.size());
- endKey = new Integer(110).toString();
- try {
- subMap_default.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endExcluded.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endIncluded.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endExcluded.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endIncluded.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- // With Comparator
- endKey = new Integer(99).toString();
- try {
- subMap_default_comparator.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endExcluded_comparator.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endIncluded_comparator.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endExcluded_comparator.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endIncluded_comparator.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- headMap = null;
- endKey = new Integer(100).toString();
- headMap = subMap_default_comparator.headMap(endKey);
- assertEquals(0, headMap.size());
- headMap = subMap_startExcluded_endExcluded_comparator.headMap(endKey);
- assertEquals(0, headMap.size());
- headMap = subMap_startExcluded_endIncluded_comparator.headMap(endKey);
- assertEquals(0, headMap.size());
- headMap = subMap_startIncluded_endExcluded_comparator.headMap(endKey);
- assertEquals(0, headMap.size());
- headMap = subMap_startIncluded_endIncluded_comparator.headMap(endKey);
- assertEquals(0, headMap.size());
- for (int i = 0, j = 101; i < 8; i++) {
- endKey = new Integer(i + j).toString();
- headMap = subMap_default_comparator.headMap(endKey);
- assertEquals(i + 1, headMap.size());
- headMap = subMap_startExcluded_endExcluded_comparator
- .headMap(endKey);
- assertEquals(i, headMap.size());
- headMap = subMap_startExcluded_endIncluded_comparator
- .headMap(endKey);
- assertEquals(i, headMap.size());
- headMap = subMap_startIncluded_endExcluded_comparator
- .headMap(endKey);
- assertEquals(i + 1, headMap.size());
- headMap = subMap_startIncluded_endIncluded_comparator
- .headMap(endKey);
- assertEquals(i + 1, headMap.size());
- }
- endKey = new Integer(108).toString();
- headMap = subMap_default_comparator.headMap(endKey);
- assertEquals(8, headMap.size());
- headMap = subMap_startExcluded_endExcluded_comparator.headMap(endKey);
- assertEquals(7, headMap.size());
- headMap = subMap_startExcluded_endIncluded_comparator.headMap(endKey);
- assertEquals(7, headMap.size());
- headMap = subMap_startIncluded_endExcluded_comparator.headMap(endKey);
- assertEquals(8, headMap.size());
- headMap = subMap_startIncluded_endIncluded_comparator.headMap(endKey);
- assertEquals(8, headMap.size());
- endKey = new Integer(110).toString();
- try {
- subMap_default_comparator.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endExcluded_comparator.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endIncluded_comparator.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endExcluded_comparator.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endIncluded_comparator.headMap(endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- }
- public void test_SubMap_isEmpty() {
- assertFalse(subMap_default.isEmpty());
- assertFalse(subMap_startExcluded_endExcluded.isEmpty());
- assertFalse(subMap_startExcluded_endIncluded.isEmpty());
- assertFalse(subMap_startIncluded_endExcluded.isEmpty());
- assertFalse(subMap_startIncluded_endIncluded.isEmpty());
- Object startKey = new Integer(100);
- Object endKey = startKey;
- SortedMap subMap = tm.subMap(startKey.toString(), endKey.toString());
- assertTrue(subMap.isEmpty());
- subMap = subMap_default.subMap(startKey.toString(), endKey.toString());
- assertTrue(subMap.isEmpty());
- subMap = subMap_startIncluded_endExcluded.subMap(startKey.toString(),
- endKey.toString());
- assertTrue(subMap.isEmpty());
- subMap = subMap_startIncluded_endIncluded.subMap(startKey.toString(),
- endKey.toString());
- assertTrue(subMap.isEmpty());
- for (int i = 0, j = 101; i < 8; i++) {
- startKey = i + j;
- endKey = startKey;
- subMap = subMap_default.subMap(startKey.toString(), endKey
- .toString());
- assertTrue(subMap.isEmpty());
- subMap = subMap_startExcluded_endExcluded.subMap(startKey
- .toString(), endKey.toString());
- assertTrue(subMap.isEmpty());
- subMap = subMap_startExcluded_endIncluded.subMap(startKey
- .toString(), endKey.toString());
- assertTrue(subMap.isEmpty());
- subMap = subMap_startIncluded_endExcluded.subMap(startKey
- .toString(), endKey.toString());
- assertTrue(subMap.isEmpty());
- subMap = subMap_startIncluded_endIncluded.subMap(startKey
- .toString(), endKey.toString());
- assertTrue(subMap.isEmpty());
- }
- for (int i = 0, j = 101; i < 5; i++) {
- startKey = i + j;
- endKey = i + j + 4;
- subMap = subMap_default.subMap(startKey.toString(), endKey
- .toString());
- assertFalse(subMap.isEmpty());
- subMap = subMap_startExcluded_endExcluded.subMap(startKey
- .toString(), endKey.toString());
- assertFalse(subMap.isEmpty());
- subMap = subMap_startExcluded_endIncluded.subMap(startKey
- .toString(), endKey.toString());
- assertFalse(subMap.isEmpty());
- subMap = subMap_startIncluded_endExcluded.subMap(startKey
- .toString(), endKey.toString());
- assertFalse(subMap.isEmpty());
- subMap = subMap_startIncluded_endIncluded.subMap(startKey
- .toString(), endKey.toString());
- assertFalse(subMap.isEmpty());
- }
- startKey = new Integer(109).toString();
- endKey = startKey;
- subMap = tm.subMap(startKey.toString(), endKey.toString());
- assertTrue(subMap.isEmpty());
- subMap = subMap_startExcluded_endIncluded.subMap(startKey, endKey);
- assertTrue(subMap.isEmpty());
- subMap = subMap_startIncluded_endIncluded.subMap(startKey, endKey);
- assertTrue(subMap.isEmpty());
- }
- public void test_SubMap_keySet() {
- Set keySet = subMap_default.keySet();
- assertFalse(keySet.isEmpty());
- assertEquals(9, keySet.size());
- keySet = subMap_startExcluded_endExcluded.entrySet();
- assertFalse(keySet.isEmpty());
- assertEquals(8, keySet.size());
- keySet = subMap_startExcluded_endIncluded.entrySet();
- assertFalse(keySet.isEmpty());
- assertEquals(9, keySet.size());
- keySet = subMap_startIncluded_endExcluded.entrySet();
- assertFalse(keySet.isEmpty());
- assertEquals(9, keySet.size());
- keySet = subMap_startIncluded_endIncluded.entrySet();
- assertFalse(keySet.isEmpty());
- assertEquals(10, keySet.size());
- }
- public void test_SubMap_put() {
- Integer value = new Integer(100);
- int addValue = 5;
- subMap_default.put(value.toString(), value + addValue);
- assertEquals(value + addValue, subMap_default.get(value.toString()));
- try {
- subMap_startExcluded_endExcluded.put(value.toString(), value
- + addValue);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endIncluded.put(value.toString(), value
- + addValue);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- subMap_startIncluded_endExcluded
- .put(value.toString(), value + addValue);
- assertEquals(value + addValue, subMap_startIncluded_endExcluded
- .get(value.toString()));
- subMap_startIncluded_endIncluded
- .put(value.toString(), value + addValue);
- assertEquals(value + addValue, subMap_startIncluded_endIncluded
- .get(value.toString()));
- value = new Integer(109);
- try {
- subMap_default.put(value.toString(), value + addValue);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endExcluded.put(value.toString(), value
- + addValue);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- subMap_startExcluded_endIncluded
- .put(value.toString(), value + addValue);
- assertEquals(value + addValue, subMap_startExcluded_endIncluded
- .get(value.toString()));
- try {
- subMap_startIncluded_endExcluded.put(value.toString(), value
- + addValue);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- subMap_startIncluded_endIncluded
- .put(value.toString(), value + addValue);
- assertEquals(value + addValue, subMap_startIncluded_endIncluded
- .get(value.toString()));
- }
- public void test_SubMap_remove() {
- Integer value = new Integer(100);
- subMap_default.remove(value.toString());
- assertNull(subMap_default.get(value.toString()));
- subMap_startExcluded_endExcluded.remove(value.toString());
- assertNull(subMap_startExcluded_endExcluded.get(value.toString()));
- subMap_startExcluded_endIncluded.remove(value.toString());
- assertNull(subMap_startExcluded_endIncluded.get(value.toString()));
- subMap_startIncluded_endExcluded.remove(value.toString());
- assertNull(subMap_startIncluded_endExcluded.get(value.toString()));
- subMap_startIncluded_endIncluded.remove(value.toString());
- assertNull(subMap_startIncluded_endIncluded.get(value.toString()));
- value = new Integer(109);
- subMap_default.remove(value.toString());
- assertNull(subMap_default.get(value.toString()));
- subMap_startExcluded_endExcluded.remove(value.toString());
- assertNull(subMap_startExcluded_endExcluded.get(value.toString()));
- subMap_startExcluded_endIncluded.remove(value.toString());
- assertNull(subMap_startExcluded_endIncluded.get(value.toString()));
- subMap_startIncluded_endExcluded.remove(value.toString());
- assertNull(subMap_startIncluded_endExcluded.get(value.toString()));
- subMap_startIncluded_endIncluded.remove(value.toString());
- assertNull(subMap_startIncluded_endIncluded.get(value.toString()));
- }
- public void test_SubMap_subMap_NoComparator() {
- String startKey = new Integer[100].toString();
- String endKey = new Integer[100].toString();
- try {
- subMap_default.subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endExcluded.subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endIncluded.subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endExcluded.subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endIncluded.subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- SortedMap subSubMap = null;
- for (int i = 101; i < 109; i++) {
- startKey = new Integer(i).toString();
- endKey = startKey;
- subSubMap = subMap_default.subMap(startKey, endKey);
- assertEquals(0, subSubMap.size());
- subSubMap = subMap_startExcluded_endExcluded.subMap(startKey,
- endKey);
- assertEquals(0, subSubMap.size());
- subSubMap = subMap_startExcluded_endIncluded.subMap(startKey,
- endKey);
- assertEquals(0, subSubMap.size());
- subSubMap = subMap_startIncluded_endExcluded.subMap(startKey,
- endKey);
- assertEquals(0, subSubMap.size());
- subSubMap = subMap_startIncluded_endIncluded.subMap(startKey,
- endKey);
- assertEquals(0, subSubMap.size());
- }
- for (int i = 101, j = 5; i < 105; i++) {
- startKey = new Integer(i).toString();
- endKey = new Integer(i + j).toString();
- subSubMap = subMap_default.subMap(startKey, endKey);
- assertEquals(j, subSubMap.size());
- subSubMap = subMap_startExcluded_endExcluded.subMap(startKey,
- endKey);
- assertEquals(j, subSubMap.size());
- subSubMap = subMap_startExcluded_endIncluded.subMap(startKey,
- endKey);
- assertEquals(j, subSubMap.size());
- subSubMap = subMap_startIncluded_endExcluded.subMap(startKey,
- endKey);
- assertEquals(j, subSubMap.size());
- subSubMap = subMap_startIncluded_endIncluded.subMap(startKey,
- endKey);
- assertEquals(j, subSubMap.size());
- }
- startKey = new Integer(108).toString();
- endKey = new Integer(109).toString();
- subSubMap = subMap_default.subMap(startKey, endKey);
- assertEquals(1, subSubMap.size());
- subSubMap = subMap_startExcluded_endExcluded.subMap(startKey, endKey);
- assertEquals(1, subSubMap.size());
- subSubMap = subMap_startExcluded_endIncluded.subMap(startKey, endKey);
- assertEquals(1, subSubMap.size());
- subSubMap = subMap_startIncluded_endExcluded.subMap(startKey, endKey);
- assertEquals(1, subSubMap.size());
- subSubMap = subMap_startIncluded_endIncluded.subMap(startKey, endKey);
- assertEquals(1, subSubMap.size());
- startKey = new Integer(109).toString();
- endKey = new Integer(109).toString();
- try {
- subMap_default.subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endExcluded.subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- subSubMap = subMap_startExcluded_endIncluded.subMap(startKey, endKey);
- assertEquals(0, subSubMap.size());
- try {
- subMap_startIncluded_endExcluded.subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- subSubMap = subMap_startIncluded_endIncluded.subMap(startKey, endKey);
- assertEquals(0, subSubMap.size());
- }
- public void test_SubMap_subMap_Comparator() {
- String startKey = new Integer[100].toString();
- String endKey = new Integer[100].toString();
- try {
- subMap_default_comparator.subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endExcluded_comparator
- .subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endIncluded_comparator
- .subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endExcluded_comparator
- .subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startIncluded_endIncluded_comparator
- .subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- SortedMap subSubMap = null;
- for (int i = 101; i < 109; i++) {
- startKey = new Integer(i).toString();
- endKey = startKey;
- subSubMap = subMap_default_comparator.subMap(startKey, endKey);
- assertEquals(0, subSubMap.size());
- subSubMap = subMap_startExcluded_endExcluded_comparator.subMap(
- startKey, endKey);
- assertEquals(0, subSubMap.size());
- subSubMap = subMap_startExcluded_endIncluded_comparator.subMap(
- startKey, endKey);
- assertEquals(0, subSubMap.size());
- subSubMap = subMap_startIncluded_endExcluded_comparator.subMap(
- startKey, endKey);
- assertEquals(0, subSubMap.size());
- subSubMap = subMap_startIncluded_endIncluded_comparator.subMap(
- startKey, endKey);
- assertEquals(0, subSubMap.size());
- }
- for (int i = 101, j = 5; i < 105; i++) {
- startKey = new Integer(i).toString();
- endKey = new Integer(i + j).toString();
- subSubMap = subMap_default_comparator.subMap(startKey, endKey);
- assertEquals(j, subSubMap.size());
- subSubMap = subMap_startExcluded_endExcluded_comparator.subMap(
- startKey, endKey);
- assertEquals(j, subSubMap.size());
- subSubMap = subMap_startExcluded_endIncluded_comparator.subMap(
- startKey, endKey);
- assertEquals(j, subSubMap.size());
- subSubMap = subMap_startIncluded_endExcluded_comparator.subMap(
- startKey, endKey);
- assertEquals(j, subSubMap.size());
- subSubMap = subMap_startIncluded_endIncluded_comparator.subMap(
- startKey, endKey);
- assertEquals(j, subSubMap.size());
- }
- startKey = new Integer(108).toString();
- endKey = new Integer(109).toString();
- subSubMap = subMap_default_comparator.subMap(startKey, endKey);
- assertEquals(1, subSubMap.size());
- subSubMap = subMap_startExcluded_endExcluded_comparator.subMap(
- startKey, endKey);
- assertEquals(1, subSubMap.size());
- subSubMap = subMap_startExcluded_endIncluded_comparator.subMap(
- startKey, endKey);
- assertEquals(1, subSubMap.size());
- subSubMap = subMap_startIncluded_endExcluded_comparator.subMap(
- startKey, endKey);
- assertEquals(1, subSubMap.size());
- subSubMap = subMap_startIncluded_endIncluded_comparator.subMap(
- startKey, endKey);
- assertEquals(1, subSubMap.size());
- startKey = new Integer(109).toString();
- endKey = new Integer(109).toString();
- try {
- subMap_default_comparator.subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- subMap_startExcluded_endExcluded_comparator
- .subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- subSubMap = subMap_startExcluded_endIncluded_comparator.subMap(
- startKey, endKey);
- assertEquals(0, subSubMap.size());
- try {
- subMap_startIncluded_endExcluded_comparator
- .subMap(startKey, endKey);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- subSubMap = subMap_startIncluded_endIncluded_comparator.subMap(
- startKey, endKey);
- assertEquals(0, subSubMap.size());
- }
- public void test_SubMap_tailMap() {
- String startKey = new Integer(99).toString();
- try {
- subMap_default.tailMap(startKey);
- fail("should throw IllegalArgumentException");