|
| 1 | +///###//////////////////////////////////////////////////////////////////////// |
| 2 | +// |
| 3 | +// Burton Computer Corporation |
| 4 | +// http://www.burton-computer.com |
| 5 | +// |
| 6 | +// Copyright (c) 2017, Burton Computer Corporation |
| 7 | +// All rights reserved. |
| 8 | +// |
| 9 | +// Redistribution and use in source and binary forms, with or without |
| 10 | +// modification, are permitted provided that the following conditions are met: |
| 11 | +// |
| 12 | +// Redistributions of source code must retain the above copyright |
| 13 | +// notice, this list of conditions and the following disclaimer. |
| 14 | +// |
| 15 | +// Redistributions in binary form must reproduce the above copyright |
| 16 | +// notice, this list of conditions and the following disclaimer in |
| 17 | +// the documentation and/or other materials provided with the |
| 18 | +// distribution. |
| 19 | +// |
| 20 | +// Neither the name of the Burton Computer Corporation nor the names |
| 21 | +// of its contributors may be used to endorse or promote products |
| 22 | +// derived from this software without specific prior written permission. |
| 23 | +// |
| 24 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 25 | +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 26 | +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 27 | +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 28 | +// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 29 | +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 30 | +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 31 | +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 32 | +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 33 | +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 34 | +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 35 | + |
| 36 | +package org.javimmutable.collections.setmap; |
| 37 | + |
| 38 | +import org.javimmutable.collections.JImmutableSet; |
| 39 | +import org.javimmutable.collections.JImmutableSetMap; |
| 40 | +import org.javimmutable.collections.MapEntry; |
| 41 | +import org.javimmutable.collections.cursors.StandardCursorTest; |
| 42 | +import org.javimmutable.collections.tree.ComparableComparator; |
| 43 | +import org.javimmutable.collections.tree.JImmutableTreeMap; |
| 44 | +import org.javimmutable.collections.tree.JImmutableTreeSet; |
| 45 | + |
| 46 | +import java.util.Arrays; |
| 47 | +import java.util.Comparator; |
| 48 | +import java.util.TreeMap; |
| 49 | + |
| 50 | +import static java.util.stream.Collectors.toList; |
| 51 | + |
| 52 | +public class JImmutableTemplateSetMapTest |
| 53 | + extends AbstractJImmutableSetMapTestCase |
| 54 | +{ |
| 55 | + public void testVarious() |
| 56 | + { |
| 57 | + final Comparator<Integer> reverse = ComparableComparator.<Integer>of().reversed(); |
| 58 | + final JImmutableTreeMap<Integer, JImmutableSet<Integer>> emptyMap = JImmutableTreeMap.of(); |
| 59 | + final JImmutableTreeSet<Integer> emptySet = JImmutableTreeSet.of(reverse); |
| 60 | + final JImmutableSetMap<Integer, Integer> empty = JImmutableTemplateSetMap.of(emptyMap.assign(1, emptySet.insert(10)), |
| 61 | + emptySet.insert(8).insert(25)); |
| 62 | + assertEquals(true, empty.isEmpty()); |
| 63 | + assertEquals(0, empty.count()); |
| 64 | + assertEquals(0, empty.keys().count()); |
| 65 | + assertNull(empty.get(1)); |
| 66 | + JImmutableSetMap<Integer, Integer> map = verifyOperations(JImmutableTreeSetMap.of()); |
| 67 | + verifyRandom(JImmutableTreeSetMap.of(), new TreeMap<>()); |
| 68 | + StandardCursorTest.listCursorTest(Arrays.asList(1, 2, 3), map.keysCursor()); |
| 69 | + StandardCursorTest.listCursorTest(Arrays.asList(MapEntry.of(1, map.getSet(1)), |
| 70 | + MapEntry.of(2, map.getSet(2)), |
| 71 | + MapEntry.of(3, map.getSet(3))), |
| 72 | + map.cursor()); |
| 73 | + StandardCursorTest.listIteratorTest(Arrays.asList(MapEntry.of(1, map.getSet(1)), |
| 74 | + MapEntry.of(2, map.getSet(2)), |
| 75 | + MapEntry.of(3, map.getSet(3))), |
| 76 | + map.iterator()); |
| 77 | + |
| 78 | + map = empty |
| 79 | + .insert(10, 100) |
| 80 | + .insert(10, 111) |
| 81 | + .insert(7, 5) |
| 82 | + .insert(3, 8) |
| 83 | + .insert(7, 12) |
| 84 | + .insert(3, 90); |
| 85 | + assertEquals(Arrays.asList(3, 7, 10), map.keys().stream().collect(toList())); |
| 86 | + assertEquals(Arrays.asList(90, 8), map.getSet(3).stream().collect(toList())); |
| 87 | + assertEquals(Arrays.asList(12, 5), map.getSet(7).stream().collect(toList())); |
| 88 | + assertEquals(Arrays.asList(111, 100), map.getSet(10).stream().collect(toList())); |
| 89 | + } |
| 90 | +} |
0 commit comments