From fb7c4173947e89f154316415495d544766aee281 Mon Sep 17 00:00:00 2001 From: Speiger Date: Tue, 14 Jun 2022 08:55:40 +0200 Subject: [PATCH] Refactor of the Project on Github. -Added: Better System to decide what code should be generated. -Added: Unit Tests are now included in the main branch. -Added: Automatic System to test the main branch and ensure that tests work. -Added: Pull Requests now run tests too. --- .github/workflows/build_action.yml | 34 + .github/workflows/build_tests_action.yml | 84 ++ .github/workflows/build_validator.yml | 36 - .github/workflows/pull_build_tests_action.yml | 39 + .gitignore | 14 + build.gradle | 159 ++- .../java/speiger/src/builder/ClassType.java | 27 +- .../speiger/src/builder/GlobalVariables.java | 90 +- .../builder/PrimitiveCollectionsBuilder.java | 117 ++- .../CollectionTestSuiteBuilder.template | 91 ++ .../builder/DequeueTestSuiteBuilder.template | 28 + .../builder/ListTestSuiteBuilder.template | 384 +++++++ .../NavigableSetTestSuiteBuilder.template | 140 +++ .../OrderedSetTestSuiteBuilder.template | 38 + .../builder/QueueTestSuiteBuilder.template | 60 ++ .../builder/SetTestSuiteBuilder.template | 116 +++ .../SortedSetTestSuiteBuilder.template | 88 ++ .../builder/maps/MapTestSuiteBuilder.template | 304 ++++++ .../NavigableMapTestSuiteBuilder.template | 79 ++ .../maps/OrderedMapTestSuiteBuilder.template | 55 ++ .../maps/SortedMapTestSuiteBuilder.template | 90 ++ .../TestCollectionGenerator.template | 30 + .../generators/TestListGenerator.template | 16 + .../TestNavigableSetGenerator.template | 13 + .../TestOrderedSetGenerator.template | 13 + .../generators/TestQueueGenerator.template | 30 + .../generators/TestSetGenerator.template | 15 + .../TestSortedSetGenerator.template | 38 + .../generators/maps/TestMapGenerator.template | 46 + .../maps/TestOrderedMapGenerator.template | 13 + .../maps/TestSortedMapGenerator.template | 25 + .../impl/CollectionConstructorTests.template | 314 ++++++ .../impl/SimpleQueueTestGenerator.template | 82 ++ .../impl/SimpleTestGenerator.template | 221 +++++ .../SortedSetSubsetTestSetGenerator.template | 173 ++++ .../impl/maps/DerivedMapGenerators.template | 550 +++++++++++ .../impl/maps/MapConstructorTests.template | 934 ++++++++++++++++++ .../impl/maps/SimpleMapTestGenerator.template | 200 ++++ .../templates/impl/maps/TestMap.template | 92 ++ .../base/AbstractCollectionTester.template | 28 + .../base/AbstractContainerTester.template | 188 ++++ .../base/AbstractListIndexOfTester.template | 27 + .../tests/base/AbstractListTester.template | 39 + .../tests/base/AbstractQueueTester.template | 81 ++ .../tests/base/AbstractSetTester.template | 14 + .../base/maps/AbstractMapTester.template | 243 +++++ .../CollectionAddAllArrayTester.template | 151 +++ .../CollectionAddAllTester.template | 102 ++ .../collection/CollectionAddTester.template | 64 ++ .../collection/CollectionClearTester.template | 68 ++ .../CollectionConstructorTester.template | 165 ++++ .../CollectionContainsAllTester.template | 45 + .../CollectionContainsAnyTester.template | 42 + .../CollectionContainsTester.template | 27 + .../collection/CollectionCopyTester.template | 38 + .../CollectionEqualsTester.template | 24 + .../CollectionForEachTester.template | 55 ++ .../CollectionIteratorTester.template | 161 +++ .../CollectionRemoveAllTester.template | 153 +++ .../CollectionRemoveIfTester.template | 119 +++ .../CollectionRetainAllTester.template | 337 +++++++ .../CollectionStreamTester.template | 59 ++ .../CollectionToArrayTester.template | 116 +++ .../iterable/IterableCountTester.template | 47 + .../iterable/IterableDistinctTester.template | 24 + .../iterable/IterableFilterTester.template | 52 + .../iterable/IterableFindFirstTester.template | 43 + .../iterable/IterableLimitTester.template | 25 + .../tests/iterable/IterableMapTester.template | 132 +++ .../iterable/IterableMatchesTester.template | 107 ++ .../iterable/IterablePeekTester.template | 19 + .../iterable/IterableReduceTester.template | 78 ++ .../iterable/IterableSortedTester.template | 43 + .../tests/list/ListAbsentTester.template | 60 ++ .../ListAddAllArrayAtIndexTester.template | 194 ++++ .../list/ListAddAllAtIndexTester.template | 167 ++++ .../list/ListAddAllListAtIndexTester.template | 155 +++ .../tests/list/ListAddAllTester.template | 115 +++ .../tests/list/ListAddAtIndexTester.template | 112 +++ .../tests/list/ListAddTester.template | 37 + .../tests/list/ListCreationTester.template | 30 + .../tests/list/ListEqualsTester.template | 45 + .../list/ListExtractElementsTester.template | 86 ++ .../tests/list/ListFillBufferTester.template | 23 + .../tests/list/ListGetElementsTester.template | 90 ++ .../tests/list/ListGetTester.template | 35 + .../tests/list/ListIndexOfTester.template | 40 + .../tests/list/ListLastIndexOfTester.template | 40 + .../list/ListListIteratorTester.template | 73 ++ .../tests/list/ListPresentTester.template | 54 + .../tests/list/ListRemoveAllTester.template | 32 + .../list/ListRemoveAtIndexTester.template | 106 ++ .../list/ListRemoveElementsTester.template | 59 ++ .../tests/list/ListRemoveTester.template | 40 + .../tests/list/ListReplaceAllTester.template | 72 ++ .../tests/list/ListRetainAllTester.template | 59 ++ .../tests/list/ListSetTester.template | 83 ++ .../tests/list/ListSortTester.template | 102 ++ .../tests/list/ListSubListTester.template | 309 ++++++ .../list/ListSwapRemoveAtIndexTester.template | 115 +++ .../tests/list/ListSwapRemoveTester.template | 81 ++ .../tests/list/ListToArrayTester.template | 37 + .../tests/maps/MapAddToTester.template | 150 +++ .../tests/maps/MapClearTester.template | 110 +++ .../maps/MapComputeIfAbsentTester.template | 157 +++ .../maps/MapComputeIfPresentTester.template | 105 ++ .../tests/maps/MapComputeTester.template | 145 +++ .../tests/maps/MapConstructorTester.template | 249 +++++ .../tests/maps/MapContainsKeyTester.template | 67 ++ .../tests/maps/MapContainsTester.template | 74 ++ .../maps/MapContainsValueTester.template | 49 + .../tests/maps/MapCopyTester.template | 38 + .../tests/maps/MapCreatorTester.template | 40 + .../tests/maps/MapEntrySetTester.template | 56 ++ .../tests/maps/MapEqualsTester.template | 95 ++ .../tests/maps/MapForEachTester.template | 59 ++ .../tests/maps/MapGetOrDefaultTester.template | 27 + .../tests/maps/MapGetTester.template | 40 + .../tests/maps/MapHashCodeTester.template | 27 + .../tests/maps/MapIsEmptyTester.template | 30 + .../tests/maps/MapMergeBulkTester.template | 93 ++ .../tests/maps/MapMergeTester.template | 93 ++ .../tests/maps/MapPutAllArrayTester.template | 243 +++++ .../tests/maps/MapPutAllTester.template | 139 +++ .../tests/maps/MapPutIfAbsentTester.template | 72 ++ .../tests/maps/MapPutTester.template | 131 +++ .../tests/maps/MapRemoveEntryTester.template | 186 ++++ .../maps/MapRemoveOrDefaultTester.template | 121 +++ .../tests/maps/MapRemoveTester.template | 225 +++++ .../tests/maps/MapReplaceAllTester.template | 110 +++ .../tests/maps/MapReplaceEntryTester.template | 93 ++ .../tests/maps/MapReplaceTester.template | 63 ++ .../tests/maps/MapSizeTester.template | 14 + .../tests/maps/MapSubFromTester.template | 148 +++ .../maps/MapSupplyIfAbsentTester.template | 131 +++ .../tests/maps/MapToStringTester.template | 58 ++ .../NavigableMapNavigationTester.template | 333 +++++++ .../tests/maps/OrderedMapMoveTester.template | 374 +++++++ .../maps/OrderedMapNavigationTester.template | 303 ++++++ .../maps/SortedMapNavigationTester.template | 328 ++++++ .../templates/tests/misc/PairTester.template | 261 +++++ .../tests/queue/DequeueDequeueTester.template | 62 ++ .../tests/queue/DequeueEnqueueTester.template | 73 ++ .../tests/queue/DequeueLastTester.template | 48 + .../tests/queue/QueueDequeueTester.template | 48 + .../tests/queue/QueueEnqueueTester.template | 68 ++ .../tests/queue/QueueFirstTester.template | 43 + .../tests/queue/QueueRemoveTester.template | 71 ++ .../queue/iterators/QueueCountTester.template | 47 + .../iterators/QueueDistinctTester.template | 24 + .../iterators/QueueFilterTester.template | 52 + .../iterators/QueueFindFirstTester.template | 43 + .../iterators/QueueForEachTester.template | 19 + .../queue/iterators/QueueLimitTester.template | 25 + .../queue/iterators/QueueMapTester.template | 182 ++++ .../iterators/QueueMatchesTester.template | 107 ++ .../queue/iterators/QueuePeekTester.template | 19 + .../iterators/QueueReduceTester.template | 80 ++ .../iterators/QueueSortedTester.template | 43 + .../set/NavigableSetNavigationTester.template | 285 ++++++ .../set/OrderedSetIterationTester.template | 56 ++ .../tests/set/OrderedSetMoveTester.template | 271 +++++ .../set/OrderedSetNavigationTester.template | 248 +++++ .../tests/set/SetAddAllTester.template | 46 + .../templates/tests/set/SetAddTester.template | 36 + .../tests/set/SetCreationTester.template | 45 + .../tests/set/SetEqualsTester.template | 45 + .../tests/set/SetRemoveTester.template | 54 + .../set/SortedSetIterationTester.template | 43 + .../set/SortedSetNaviationTester.template | 178 ++++ .../utils/AbstractIteratorTester.template | 533 ++++++++++ .../utils/BidirectionalteratorTester.template | 34 + .../testers/templates/utils/Helpers.template | 237 +++++ .../templates/utils/IteratorTester.template | 20 + .../utils/ListIteratorTester.template | 36 + .../utils/MinimalCollection.template | 95 ++ .../templates/utils/MinimalSet.template | 84 ++ .../testers/templates/utils/Samples.template | 73 ++ .../templates/collections/ListTests.template | 358 +++++++ .../templates/collections/QueueTests.template | 89 ++ .../templates/collections/SetTests.template | 196 ++++ .../tests/templates/maps/MapTests.template | 395 ++++++++ .../JavaCollectionRemoveIfTester.java | 93 ++ .../list/JavaListListIteratorTester.java | 84 ++ .../src/testers/utils/SpecialFeature.java | 42 + .../speiger/src/testers/utils/TestUtils.java | 56 ++ 186 files changed, 19991 insertions(+), 77 deletions(-) create mode 100644 .github/workflows/build_action.yml create mode 100644 .github/workflows/build_tests_action.yml delete mode 100644 .github/workflows/build_validator.yml create mode 100644 .github/workflows/pull_build_tests_action.yml create mode 100644 src/builder/resources/speiger/assets/testers/templates/builder/CollectionTestSuiteBuilder.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/builder/DequeueTestSuiteBuilder.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/builder/ListTestSuiteBuilder.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/builder/NavigableSetTestSuiteBuilder.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/builder/OrderedSetTestSuiteBuilder.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/builder/QueueTestSuiteBuilder.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/builder/SetTestSuiteBuilder.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/builder/SortedSetTestSuiteBuilder.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/builder/maps/MapTestSuiteBuilder.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/builder/maps/NavigableMapTestSuiteBuilder.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/builder/maps/OrderedMapTestSuiteBuilder.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/builder/maps/SortedMapTestSuiteBuilder.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/generators/TestCollectionGenerator.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/generators/TestListGenerator.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/generators/TestNavigableSetGenerator.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/generators/TestOrderedSetGenerator.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/generators/TestQueueGenerator.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/generators/TestSetGenerator.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/generators/TestSortedSetGenerator.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/generators/maps/TestMapGenerator.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/generators/maps/TestOrderedMapGenerator.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/generators/maps/TestSortedMapGenerator.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/impl/CollectionConstructorTests.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/impl/SimpleQueueTestGenerator.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/impl/SimpleTestGenerator.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/impl/SortedSetSubsetTestSetGenerator.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/impl/maps/DerivedMapGenerators.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/impl/maps/MapConstructorTests.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/impl/maps/SimpleMapTestGenerator.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/impl/maps/TestMap.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractCollectionTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractContainerTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractListIndexOfTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractListTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractQueueTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractSetTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/base/maps/AbstractMapTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionAddAllArrayTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionAddAllTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionAddTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionClearTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionConstructorTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionContainsAllTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionContainsAnyTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionContainsTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionCopyTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionEqualsTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionForEachTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionIteratorTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionRemoveAllTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionRemoveIfTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionRetainAllTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionStreamTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionToArrayTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableCountTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableDistinctTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableFilterTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableFindFirstTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableLimitTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableMapTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableMatchesTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterablePeekTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableReduceTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableSortedTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListAbsentTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllArrayAtIndexTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllAtIndexTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllListAtIndexTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAtIndexTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListCreationTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListEqualsTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListExtractElementsTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListFillBufferTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListGetElementsTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListGetTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListIndexOfTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListLastIndexOfTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListListIteratorTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListPresentTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveAllTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveAtIndexTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveElementsTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListReplaceAllTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListRetainAllTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListSetTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListSortTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListSubListTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListSwapRemoveAtIndexTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListSwapRemoveTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/list/ListToArrayTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapAddToTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapClearTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfAbsentTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfPresentTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapConstructorTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapContainsKeyTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapContainsTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapContainsValueTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapCopyTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapCreatorTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapEntrySetTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapEqualsTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapForEachTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapGetOrDefaultTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapGetTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapHashCodeTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapIsEmptyTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapMergeBulkTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapMergeTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutAllArrayTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutAllTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutIfAbsentTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapRemoveEntryTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapRemoveOrDefaultTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapRemoveTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapReplaceAllTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapReplaceEntryTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapReplaceTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSizeTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSubFromTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSupplyIfAbsentTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/MapToStringTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/NavigableMapNavigationTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/OrderedMapMoveTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/OrderedMapNavigationTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/maps/SortedMapNavigationTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/misc/PairTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/DequeueDequeueTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/DequeueEnqueueTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/DequeueLastTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueDequeueTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueEnqueueTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueFirstTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueRemoveTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueCountTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueDistinctTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueFilterTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueFindFirstTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueForEachTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueLimitTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueMapTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueMatchesTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueuePeekTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueReduceTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueSortedTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/set/NavigableSetNavigationTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/set/OrderedSetIterationTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/set/OrderedSetMoveTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/set/OrderedSetNavigationTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/set/SetAddAllTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/set/SetAddTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/set/SetCreationTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/set/SetEqualsTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/set/SetRemoveTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/set/SortedSetIterationTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/tests/set/SortedSetNaviationTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/utils/AbstractIteratorTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/utils/BidirectionalteratorTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/utils/Helpers.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/utils/IteratorTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/utils/ListIteratorTester.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/utils/MinimalCollection.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/utils/MinimalSet.template create mode 100644 src/builder/resources/speiger/assets/testers/templates/utils/Samples.template create mode 100644 src/builder/resources/speiger/assets/tests/templates/collections/ListTests.template create mode 100644 src/builder/resources/speiger/assets/tests/templates/collections/QueueTests.template create mode 100644 src/builder/resources/speiger/assets/tests/templates/collections/SetTests.template create mode 100644 src/builder/resources/speiger/assets/tests/templates/maps/MapTests.template create mode 100644 src/test/java/speiger/src/testers/base/tests/collection/JavaCollectionRemoveIfTester.java create mode 100644 src/test/java/speiger/src/testers/base/tests/list/JavaListListIteratorTester.java create mode 100644 src/test/java/speiger/src/testers/utils/SpecialFeature.java create mode 100644 src/test/java/speiger/src/testers/utils/TestUtils.java diff --git a/.github/workflows/build_action.yml b/.github/workflows/build_action.yml new file mode 100644 index 00000000..e991c571 --- /dev/null +++ b/.github/workflows/build_action.yml @@ -0,0 +1,34 @@ +name: Latest Build + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + strategy: + fail-fast: false + matrix: + jdk: [8, 11, 14, 16, 17] + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up JDK ${{ matrix.jdk }} + uses: actions/setup-java@v3 + with: + java-version: ${{ matrix.jdk }} + distribution: temurin + cache: gradle + + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b + + - name: Make gradlew executable + run: chmod +x ./gradlew + + - name: Build with Gradle + run: ./gradlew build diff --git a/.github/workflows/build_tests_action.yml b/.github/workflows/build_tests_action.yml new file mode 100644 index 00000000..bff610e8 --- /dev/null +++ b/.github/workflows/build_tests_action.yml @@ -0,0 +1,84 @@ +name: Unit Tests + +on: + push: + branches: [ master ] + +jobs: + build: + name: Unit Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 11 + cache: gradle + + - name: Make gradlew executable + run: chmod +x ./gradlew + - name: Build and Test + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./gradlew generateTestSource test jacocoTestReport --info -Dfull_test_suite=true + + - name: Publish Test Result + uses: EnricoMi/publish-unit-test-result-action@v1 + id: test-results + if: always() + with: + files: build/test-results/**/*.xml + fail_on: nothing + ignore_runs: true + json_thousands_separator: . + time_unit: milliseconds + + - name: Create Badge Color + shell: bash + run: | + case ${{ fromJSON( steps.test-results.outputs.json ).conclusion }} in + success) + echo "BADGE_COLOR=31c653" >> $GITHUB_ENV + ;; + failure) + echo "BADGE_COLOR=800000" >> $GITHUB_ENV + ;; + neutral) + echo "BADGE_COLOR=696969" >> $GITHUB_ENV + ;; + esac + + - name: Create Test Badge + uses: emibcn/badge-action@v1.2.4 + with: + label: Tests + status: '${{ fromJSON( steps.test-results.outputs.json ).conclusion }}, Passed: ${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.tests_succ }}, Skipped: ${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.tests_skip }}, Failed: ${{ fromJSON( steps.test-results.outputs.json ).formatted.stats.tests_fail }}' + color: ${{ env.BADGE_COLOR }} + path: tests.svg + + - name: Create Coverage Badge + id: jacoco + uses: cicirello/jacoco-badge-generator@v2 + with: + jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv + badges-directory: null + intervals: 95 80 70 60 50 0 + + - name: Upload Test Badge + uses: exuanbo/actions-deploy-gist@v1 + with: + token: ${{ secrets.GIST_TOKEN }} + gist_id: 280257cd19cbe1dda3789bebd4ff65cf + file_path: tests.svg + + - name: Upload Coverage Badge + uses: exuanbo/actions-deploy-gist@v1 + with: + token: ${{ secrets.GIST_TOKEN }} + gist_id: 280257cd19cbe1dda3789bebd4ff65cf + file_path: jacoco.svg \ No newline at end of file diff --git a/.github/workflows/build_validator.yml b/.github/workflows/build_validator.yml deleted file mode 100644 index a6327f71..00000000 --- a/.github/workflows/build_validator.yml +++ /dev/null @@ -1,36 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle - -name: Latest Build - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - strategy: - fail-fast: false - matrix: - jdk: [8, 11, 14, 16, 17] - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK ${{ matrix.jdk }} - uses: actions/setup-java@v1 - with: - java-version: ${{ matrix.jdk }} - - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b - - name: Make gradlew executable - run: chmod +x ./gradlew - - name: Build with Gradle - run: ./gradlew build diff --git a/.github/workflows/pull_build_tests_action.yml b/.github/workflows/pull_build_tests_action.yml new file mode 100644 index 00000000..1d896f90 --- /dev/null +++ b/.github/workflows/pull_build_tests_action.yml @@ -0,0 +1,39 @@ +name: Unit Tests + +on: + pull_request: + branches: [ master ] + +jobs: + build: + name: Unit Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 11 + cache: gradle + + - name: Make gradlew executable + run: chmod +x ./gradlew + - name: Build and Test + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./gradlew generateTestSource test jacocoTestReport --info -Dfull_test_suite=true + + - name: Publish Test Result + uses: EnricoMi/publish-unit-test-result-action@v1 + id: test-results + if: always() + with: + files: build/test-results/**/*.xml + fail_on: nothing + ignore_runs: true + json_thousands_separator: . + time_unit: milliseconds \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0dd0becc..50fec4e0 100644 --- a/.gitignore +++ b/.gitignore @@ -30,5 +30,19 @@ gradle-app.setting /src/main/java/speiger/src/collections/doubles/* /src/main/java/speiger/src/collections/objects/* +#Generated Tests +/src/test/java/speiger/src/testers/booleans/* +/src/test/java/speiger/src/testers/bytes/* +/src/test/java/speiger/src/testers/shorts/* +/src/test/java/speiger/src/testers/chars/* +/src/test/java/speiger/src/testers/ints/* +/src/test/java/speiger/src/testers/longs/* +/src/test/java/speiger/src/testers/floats/* +/src/test/java/speiger/src/testers/doubles/* +/src/test/java/speiger/src/testers/objects/* +/src/test/java/speiger/src/tests/* + #Cache result /src/builder/resources/speiger/assets/collections/cache.bin +/src/builder/resources/speiger/assets/testers/cache.bin +/src/builder/resources/speiger/assets/tests/cache.bin diff --git a/build.gradle b/build.gradle index 88d223e1..64a961d4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ plugins { id 'java-library' + id "jacoco" } tasks.withType(JavaCompile) { @@ -62,7 +63,7 @@ task generateGithubSource(type: JavaExec) { description = 'Builds the sourcecode for Github Actions' classpath = sourceSets.builder.runtimeClasspath main = 'speiger.src.builder.PrimitiveCollectionsBuilder' - args = ['false', 'true'] + args = ['silent'] } task forceGenerateSource(type: JavaExec) { @@ -70,7 +71,15 @@ task forceGenerateSource(type: JavaExec) { description = 'Builds the sourcecode forceful' classpath = sourceSets.builder.runtimeClasspath main = 'speiger.src.builder.PrimitiveCollectionsBuilder' - args = ['true'] + args = ['force'] +} + +task generateTestSource(type: JavaExec) { + group = 'internal' + description = 'Builds the sourcecode for the Tests' + classpath = sourceSets.builder.runtimeClasspath + main = 'speiger.src.builder.PrimitiveCollectionsBuilder' + args = ['tests'] } task javadocJar(type: Jar) { @@ -94,8 +103,152 @@ artifacts { archives srcJar } +task testBooleans(type: Test) { + group 'tests' + description 'Tests all Boolean Collections' + filter { + excludeTestsMatching "speiger.src.testers.**.*" + includeTestsMatching "speiger.src.tests.booleans.**.*" + } + useJUnit() + ignoreFailures = true + maxHeapSize = "1024m" +} + +task testBytes(type: Test) { + group 'tests' + description 'Tests all Byte Collections' + filter { + excludeTestsMatching "speiger.src.testers.**.*" + includeTestsMatching "speiger.src.tests.bytes.**.*" + } + useJUnit() + ignoreFailures = true + maxHeapSize = "1024m" + maxParallelForks = 2 +} + +task testShorts(type: Test) { + group 'tests' + description 'Tests all Short Collections' + filter { + excludeTestsMatching "speiger.src.testers.**.*" + includeTestsMatching "speiger.src.tests.shorts.**.*" + } + useJUnit() + ignoreFailures = true + maxHeapSize = "1024m" + maxParallelForks = 2 +} + +task testChars(type: Test) { + group 'tests' + description 'Tests all Character Collections' + filter { + excludeTestsMatching "speiger.src.testers.**.*" + includeTestsMatching "speiger.src.tests.chars.**.*" + } + useJUnit() + ignoreFailures = true + maxHeapSize = "1024m" + maxParallelForks = 2 +} + +task testInts(type: Test) { + group 'tests' + description 'Tests all Int Collections' + filter { + excludeTestsMatching "speiger.src.testers.**.*" + includeTestsMatching "speiger.src.tests.ints.**.*" + } + useJUnit() + ignoreFailures = true + maxHeapSize = "1024m" + maxParallelForks = 2 +} + +task testLongs(type: Test) { + group 'tests' + description 'Tests all Long Collections' + filter { + excludeTestsMatching "speiger.src.testers.**.*" + includeTestsMatching "speiger.src.tests.longs.**.*" + } + useJUnit() + ignoreFailures = true + maxHeapSize = "1024m" + maxParallelForks = 2 +} + +task testFloats(type: Test) { + group 'tests' + description 'Tests all Float Collections' + filter { + excludeTestsMatching "speiger.src.testers.**.*" + includeTestsMatching "speiger.src.tests.floats.**.*" + } + useJUnit() + ignoreFailures = true + maxHeapSize = "1024m" + maxParallelForks = 2 +} + +task testDoubles(type: Test) { + group 'tests' + description 'Tests all Double Collections' + filter { + excludeTestsMatching "speiger.src.testers.**.*" + includeTestsMatching "speiger.src.tests.doubles.**.*" + } + useJUnit() + ignoreFailures = true + maxHeapSize = "1024m" + maxParallelForks = 2 +} + +task testObjects(type: Test) { + group 'tests' + description 'Tests all Object Collections' + filter { + excludeTestsMatching "speiger.src.testers.**.*" + includeTestsMatching "speiger.src.tests.objects.**.*" + } + useJUnit() + ignoreFailures = true + maxHeapSize = "1024m" + maxParallelForks = 2 +} + +if(System.getProperty("full_test_suite", "false").toBoolean()) { + test.dependsOn testBooleans + test.dependsOn testBytes + test.dependsOn testShorts + test.dependsOn testChars + test.dependsOn testInts + test.dependsOn testLongs + test.dependsOn testFloats + test.dependsOn testDoubles + test.dependsOn testObjects +} + test { - useJUnit() + filter { + excludeTestsMatching "speiger.src.testers.**.*" + excludeTestsMatching "speiger.src.tests.**.*" + excludeTestsMatching "tests.**.*" + } + useJUnit() + ignoreFailures = true + maxHeapSize = "1024m" +} + +jacocoTestReport { + executionData fileTree(project.buildDir.absolutePath).include("jacoco/*.exec") + reports { + xml.enabled true + html.enabled = true + csv.enabled true + } } publishing { diff --git a/src/builder/java/speiger/src/builder/ClassType.java b/src/builder/java/speiger/src/builder/ClassType.java index c73d63b0..f799e726 100644 --- a/src/builder/java/speiger/src/builder/ClassType.java +++ b/src/builder/java/speiger/src/builder/ClassType.java @@ -3,15 +3,15 @@ package speiger.src.builder; @SuppressWarnings("javadoc") public enum ClassType { - BOOLEAN("boolean", "Boolean", "Boolean", "booleans", "BOOLEAN", "false"), - BYTE("byte", "Byte", "Byte", "bytes", "BYTE", "(byte)0"), - SHORT("short", "Short", "Short", "shorts", "SHORT", "(short)0"), - CHAR("char", "Character", "Char", "chars", "CHAR", "(char)0"), - INT("int", "Integer", "Int", "ints", "INT", "0"), - LONG("long", "Long", "Long", "longs", "LONG", "0L"), - FLOAT("float", "Float", "Float", "floats", "FLOAT", "0F"), - DOUBLE("double", "Double", "Double", "doubles", "DOUBLE", "0D"), - OBJECT("T", "T", "Object", "objects", "OBJECT", "null"); + BOOLEAN("boolean", "Boolean", "Boolean", "booleans", "BOOLEAN", "false", "false"), + BYTE("byte", "Byte", "Byte", "bytes", "BYTE", "(byte)0", "(byte)-1"), + SHORT("short", "Short", "Short", "shorts", "SHORT", "(short)0", "(short)-1"), + CHAR("char", "Character", "Char", "chars", "CHAR", "(char)0", "(char)-1"), + INT("int", "Integer", "Int", "ints", "INT", "0", "-1"), + LONG("long", "Long", "Long", "longs", "LONG", "0L", "-1L"), + FLOAT("float", "Float", "Float", "floats", "FLOAT", "0F", "-1F"), + DOUBLE("double", "Double", "Double", "doubles", "DOUBLE", "0D", "-1D"), + OBJECT("T", "T", "Object", "objects", "OBJECT", "null", "null"); String keyType; String classType; @@ -19,8 +19,9 @@ public enum ClassType String pathType; String capType; String emptyValue; + String invalidValue; - private ClassType(String keyType, String classType, String fileType, String pathType, String capType, String emptyValue) + private ClassType(String keyType, String classType, String fileType, String pathType, String capType, String emptyValue, String invalidValue) { this.keyType = keyType; this.classType = classType; @@ -28,6 +29,7 @@ public enum ClassType this.pathType = pathType; this.capType = capType; this.emptyValue = emptyValue; + this.invalidValue = invalidValue; } public String getKeyType() @@ -90,6 +92,11 @@ public enum ClassType return emptyValue; } + public String getInvalidValue() + { + return invalidValue; + } + public boolean isObject() { return this == OBJECT; diff --git a/src/builder/java/speiger/src/builder/GlobalVariables.java b/src/builder/java/speiger/src/builder/GlobalVariables.java index 59a88c79..8ed82aa7 100644 --- a/src/builder/java/speiger/src/builder/GlobalVariables.java +++ b/src/builder/java/speiger/src/builder/GlobalVariables.java @@ -35,21 +35,43 @@ public class GlobalVariables addSimpleMapper("CLASS_TYPE", type.getClassType()); addSimpleMapper("CLASS_VALUE_TYPE", valueType.getClassValueType()); addSimpleMapper("KEY_TYPE", type.getKeyType()); + addSimpleMapper("KEY_OBJECT_TYPE", type.isObject() ? "Object" : type.getKeyType()); + addSimpleMapper("KEY_STRING_TYPE", type.isObject() ? "String" : type.getKeyType()); addSimpleMapper("KEY_SPECIAL_TYPE", type.isObject() ? "E" : type.getKeyType()); + addSimpleMapper("CLASS_OBJECT_TYPE", type.getClassType()); + addSimpleMapper("CLASS_OBJECT_VALUE_TYPE", valueType.getClassValueType()); + addSimpleMapper("CLASS_STRING_TYPE", type.isObject() ? "String" : type.getClassType()); + addSimpleMapper("CLASS_STRING_VALUE_TYPE", valueType.isObject() ? "String" : valueType.getClassValueType()); addSimpleMapper("VALUE_TYPE", valueType.getValueType()); + addSimpleMapper("VALUE_OBJECT_TYPE", valueType.isObject() ? "Object" : valueType.getValueType()); + addSimpleMapper("VALUE_STRING_TYPE", valueType.isObject() ? "String" : valueType.getValueType()); addSimpleMapper("VALUE_SPECIAL_TYPE", valueType.isObject() ? "E" : valueType.getKeyType()); + addSimpleMapper("KEY_JAVA_TYPE", type.getCustomJDKType().getKeyType()); + addSimpleMapper("VALUE_JAVA_TYPE", type.getCustomJDKType().getKeyType()); addSimpleMapper("EMPTY_KEY_VALUE", type.getEmptyValue()); addSimpleMapper("EMPTY_VALUE", valueType.getEmptyValue()); + addSimpleMapper("INVALID_KEY_VALUE", type.getInvalidValue()); + addSimpleMapper("INVALID_VALUE", valueType.getInvalidValue()); + + addSimpleMapper(" KEY_STRING_GENERIC_TYPE", type.isObject() ? "" : ""); + addSimpleMapper(" VALUE_STRING_GENERIC_TYPE", valueType.isObject() ? "" : ""); + addSimpleMapper(" KEY_VALUE_STRING_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "" : "") : (valueType.isObject() ? "" : "")); + + addSimpleMapper(" KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+">" : ""); addSimpleMapper(" KEY_KEY_GENERIC_TYPE", type.isObject() ? "<"+type.getKeyType()+", "+type.getKeyType()+">" : ""); + addSimpleMapper(" KEY_CLASS_GENERIC_TYPE", type.isObject() ? "<"+type.getClassType()+">" : ""); + addSimpleMapper(" VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+">" : ""); addSimpleMapper(" VALUE_VALUE_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : ""); + addSimpleMapper(" VALUE_CLASS_GENERIC_TYPE", valueType.isObject() ? "<"+valueType.getClassValueType()+">" : ""); addSimpleMapper(" KEY_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : "")); addSimpleMapper(" KEY_VALUE_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+", "+valueType.getValueType()+">" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+", "+valueType.getValueType()+">" : "")); + addInjectMapper(" KEY_VALUE_SPECIAL_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+", %s>" : "<"+type.getKeyType()+", %s>") : (valueType.isObject() ? "<"+valueType.getValueType()+", %s>" : "<%s>")).setBraceType("<>").removeBraces(); addSimpleMapper(" NO_GENERIC_TYPE", type.isObject() ? "" : ""); addSimpleMapper(" NO_KV_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "" : "") : valueType.isObject() ? "" : ""); @@ -59,6 +81,10 @@ public class GlobalVariables addSimpleMapper(" VALUE_SUPER_GENERIC_TYPE", valueType.isObject() ? "" : ""); addSimpleMapper(" KEY_VALUE_SUPER_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "" : "") : (valueType.isObject() ? "" : "")); + addSimpleMapper(" KEY_UNKNOWN_GENERIC_TYPE", type.isObject() ? "" : ""); + addSimpleMapper(" VALUE_UNKNOWN_GENERIC_TYPE", valueType.isObject() ? "" : ""); + addSimpleMapper(" KEY_VALUE_UNKNOWN_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "" : "") : (valueType.isObject() ? "" : "")); + addSimpleMapper(" KEY_ENUM_VALUE_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">, "+valueType.getValueType()+">" : "<"+type.getKeyType()+" extends Enum<"+type.getKeyType()+">>") : (valueType.isObject() ? "<"+valueType.getValueType()+">" : "")); addSimpleMapper(" KEY_VALUE_ENUM_GENERIC_TYPE", type.isObject() ? (valueType.isObject() ? "<"+type.getKeyType()+", "+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : "<"+type.getKeyType()+">") : (valueType.isObject() ? "<"+valueType.getValueType()+" extends Enum<"+valueType.getValueType()+">>" : "")); @@ -83,6 +109,7 @@ public class GlobalVariables addSimpleMapper(" GENERIC_KEY_VALUE_BRACES", type.isObject() ? (valueType.isObject() ? " <"+type.getKeyType()+", "+valueType.getValueType()+">" : " <"+type.getKeyType()+">") : (valueType.isObject() ? " <"+valueType.getValueType()+">" : "")); addSimpleMapper(" COMPAREABLE_KEY_BRACES", type.isObject() ? " <"+type.getKeyType()+" extends Comparable>" : ""); addSimpleMapper("KV_BRACES", type.isObject() || valueType.isObject() ? "<>" : ""); + addSimpleMapper("VALUE_BRACES", valueType.isObject() ? "<>" : ""); addSimpleMapper("BRACES", type.isObject() ? "<>" : ""); if(type.needsCustomJDKType()) { @@ -120,6 +147,7 @@ public class GlobalVariables addInjectMapper(fix+"_EQUALS_NULL", type.getComparableValue()+" == "+(type.isPrimitiveBlocking() || type.needsCast() ? type.getEmptyValue() : "0")).removeBraces(); addArgumentMapper(fix+"_EQUALS_NOT", type.getEquals(true)).removeBraces(); addArgumentMapper(fix+"_EQUALS", type.getEquals(false)).removeBraces(); + addSimpleMapper("FILE_"+fix+"_TYPE", type.getFileType()); addArgumentMapper("COMPAREABLE_TO_"+fix, type.isObject() ? "((Comparable<"+type.getKeyType(value)+">)%1$s).compareTo(("+type.getKeyType(value)+")%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces(); addArgumentMapper("COMPARE_TO_"+fix, type.isObject() ? "%1$s.compareTo(%2$s)" : type.getClassType(value)+".compare(%1$s, %2$s)").removeBraces(); @@ -135,7 +163,8 @@ public class GlobalVariables addSimpleMapper("EMPTY_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])ARRAYS.EMPTY_ARRAY" : "ARRAYS.EMPTY_ARRAY"); addInjectMapper("NEW_"+fix+"_ARRAY", type.isObject() ? "("+fix+"_TYPE[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces(); addInjectMapper("NEW_SPECIAL_"+fix+"_ARRAY", type.isObject() ? "(E[])new Object[%s]" : "new "+fix+"_TYPE[%s]").removeBraces(); - addInjectMapper("NEW_CLASS"+(value ? "_VALUE" : "")+"_ARRAY", type.isObject() ? "(CLASS_TYPE[])new Object[%s]" : "new CLASS_TYPE[%s]").removeBraces(); + if(value) addInjectMapper("NEW_CLASS_VALUE_ARRAY", type.isObject() ? "(CLASS_VALUE_TYPE[])new Object[%s]" : "new CLASS_VALUE_TYPE[%s]").removeBraces(); + else addInjectMapper("NEW_CLASS_ARRAY", type.isObject() ? "(CLASS_TYPE[])new Object[%s]" : "new CLASS_TYPE[%s]").removeBraces(); } public GlobalVariables createPreFunctions() @@ -186,7 +215,43 @@ public class GlobalVariables addClassMapper("RB_TREE_SET", "RBTreeSet"); addClassMapper("AVL_TREE_SET", "AVLTreeSet"); addClassMapper("ARRAY_SET", "ArraySet"); + addAbstractBiMapper("SIMPLE_TEST_MAP", "Test%sMap", "2"); + //Final UnitTest Classes + addAbstractMapper("MINIMAL_COLLECTION", "Minimal%sCollection"); + addAbstractMapper("MINIMAL_SET", "Minimal%sSet"); + addAbstractMapper("ABSTRACT_CONTAINER_TESTER", "Abstract%sContainerTester"); + addAbstractMapper("ABSTRACT_COLLECTION_TESTER", "Abstract%sCollectionTester"); + addAbstractMapper("ABSTRACT_QUEUE_TESTER", "Abstract%sQueueTester"); + addAbstractMapper("ABSTRACT_LIST_INDEX_OF_TESTER", "Abstract%sListIndexOfTester"); + addAbstractMapper("ABSTRACT_LIST_TESTER", "Abstract%sListTester"); + addAbstractMapper("ABSTRACT_SET_TESTER", "Abstract%sSetTester"); + addAbstractMapper("ABSTRACT_ITERATOR_TESTER", "Abstract%sIteratorTester"); + addAbstractBiMapper("ABSTRACT_MAP_TESTER", "Abstract%sMapTester", "2"); + addClassMapper("LIST_ITERATOR_TESTER", "ListIteratorTester"); + addClassMapper("BIDIRECTIONAL_ITERATOR_TESTER", "BidirectionalteratorTester"); + addClassMapper("ITERATOR_TESTER", "IteratorTester"); + addClassMapper("COLLECTION_TEST_BUILDER", "CollectionTestSuiteBuilder"); + addClassMapper("DEQUEUE_TEST_BUILDER", "DequeueTestSuiteBuilder"); + addClassMapper("QUEUE_TEST_BUILDER", "QueueTestSuiteBuilder"); + addClassMapper("LIST_TEST_BUILDER", "ListTestSuiteBuilder"); + addClassMapper("ORDERED_SET_TEST_BUILDER", "OrderedSetTestSuiteBuilder"); + addClassMapper("SORTED_SET_TEST_BUILDER", "SortedSetTestSuiteBuilder"); + addClassMapper("NAVIGABLE_SET_TEST_BUILDER", "NavigableSetTestSuiteBuilder"); + addClassMapper("SET_TEST_BUILDER", "SetTestSuiteBuilder"); + addAbstractBiMapper("NAVIGABLE_MAP_TEST_BUILDER", "%sNavigableMapTestSuiteBuilder", "2"); + addAbstractBiMapper("SORTED_MAP_TEST_BUILDER", "%sSortedMapTestSuiteBuilder", "2"); + addAbstractBiMapper("ORDERED_MAP_TEST_BUILDER", "%sOrderedMapTestSuiteBuilder", "2"); + addAbstractBiMapper("MAP_TEST_BUILDER", "%sMapTestSuiteBuilder", "2"); + addAbstractBiMapper("MAP_CONSTRUCTOR_TESTS", "%sMapConstructorTests", "2"); + addClassMapper("COLLECTION_CONSTRUCTOR_TESTS", "CollectionConstructorTests"); + addClassMapper("SUB_SORTED_SET_CLASS_GENERATOR", "SortedSetSubsetTestSetGenerator"); + addClassMapper("SUB_NAVIGABLE_SET_CLASS_GENERATOR", "NavigableSetSubsetTestSetGenerator"); + addClassMapper("LIST_TESTS", "ListTests"); + addClassMapper("SET_TESTS", "SetTests"); + addClassMapper("QUEUE_TESTS", "QueueTests"); + addBiClassMapper("MAP_TESTS", "MapTests", "2"); + //Abstract Classes addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection"); addAbstractMapper("ABSTRACT_PRIORITY_QUEUE", "Abstract%sPriorityQueue"); @@ -206,6 +271,24 @@ public class GlobalVariables addClassMapper("ITERATORS", "Iterators"); addClassMapper("ITERABLES", "Iterables"); addBiClassMapper("MAPS", "Maps", "2"); + addClassMapper("SAMPLE_ELEMENTS", "Samples"); + + //UnitTest Helper Classes + addClassMapper("HELPERS", "Helpers"); + addAbstractMapper("TEST_COLLECTION_GENERATOR", "Test%sCollectionGenerator"); + addAbstractMapper("TEST_QUEUE_GENERATOR", "Test%sQueueGenerator"); + addAbstractMapper("TEST_LIST_GENERATOR", "Test%sListGenerator"); + addAbstractMapper("TEST_NAVIGABLE_SET_GENERATOR", "Test%sNavigableSetGenerator"); + addAbstractMapper("TEST_SORTED_SET_GENERATOR", "Test%sSortedSetGenerator"); + addAbstractMapper("TEST_ORDERED_SET_GENERATOR", "Test%sOrderedSetGenerator"); + addAbstractMapper("TEST_SET_GENERATOR", "Test%sSetGenerator"); + addAbstractMapper("SIMPLE_TEST_GENERATOR", "Simple%sTestGenerator"); + addAbstractMapper("SIMPLE_QUEUE_TEST_GENERATOR", "Simple%sQueueTestGenerator"); + addAbstractBiMapper("SIMPLE_MAP_TEST_GENERATOR", "Simple%sMapTestGenerator", "2"); + addAbstractBiMapper("DERIVED_MAP_GENERATORS", "Derived%sMapGenerators", "2"); + addAbstractBiMapper("TEST_ORDERED_MAP_GENERATOR", "Test%sOrderedMapGenerator", "2"); + addAbstractBiMapper("TEST_SORTED_MAP_GENERATOR", "Test%sSortedMapGenerator", "2"); + addAbstractBiMapper("TEST_MAP_GENERATOR", "Test%sMapGenerator", "2"); //Interfaces addClassMapper("LIST_ITERATOR", "ListIterator"); @@ -245,7 +328,6 @@ public class GlobalVariables if(!valueType.isObject()) addSimpleMapper("VALUE_CONSUMER", valueType.getFileType()+"Consumer"); else addSimpleMapper("VALUE_CONSUMER", "Consumer"); addSimpleMapper("CONSUMER", "Consumer"); - addSimpleMapper("COMPARATOR", "Comparator"); addSimpleMapper("IARRAY", "IObjectArray"); } else @@ -256,9 +338,10 @@ public class GlobalVariables addSimpleMapper("CONSUMER", type.getFileType()+"Consumer"); } else addClassMapper("CONSUMER", "Consumer"); - addClassMapper("COMPARATOR", "Comparator"); addFunctionMappers("IARRAY", "I%sArray"); } + addSimpleMapper("VALUE_COMPARATOR", valueType.isObject() ? "Comparator" : String.format("%sComparator", valueType.getNonFileType())); + addSimpleMapper("COMPARATOR", type.isObject() ? "Comparator" : String.format("%sComparator", type.getNonFileType())); return this; } @@ -308,6 +391,7 @@ public class GlobalVariables addSimpleMapper("VALUE_TEST_VALUE", valueType.isObject() ? "getBoolean" : "get"); addSimpleMapper("TEST_VALUE", type.isObject() ? "getBoolean" : "get"); addSimpleMapper("NEW_STREAM", type.isPrimitiveBlocking() ? "" : type.getCustomJDKType().getKeyType()+"Stream"); + addSimpleMapper("VALUE_TO_ARRAY", "to"+valueType.getNonFileType()+"Array"); addSimpleMapper("TO_ARRAY", "to"+type.getNonFileType()+"Array"); addSimpleMapper("[SPACE]", " "); return this; diff --git a/src/builder/java/speiger/src/builder/PrimitiveCollectionsBuilder.java b/src/builder/java/speiger/src/builder/PrimitiveCollectionsBuilder.java index caaa285a..815e3a8a 100644 --- a/src/builder/java/speiger/src/builder/PrimitiveCollectionsBuilder.java +++ b/src/builder/java/speiger/src/builder/PrimitiveCollectionsBuilder.java @@ -6,6 +6,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; +import java.util.EnumMap; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; @@ -14,6 +16,7 @@ import java.util.Map; import java.util.Set; import java.util.StringJoiner; import java.util.function.Consumer; +import java.util.function.Predicate; import java.util.stream.Stream; import speiger.src.builder.processor.TemplateProcess; @@ -23,6 +26,7 @@ import speiger.src.builder.processor.TemplateProcessor; public class PrimitiveCollectionsBuilder extends TemplateProcessor { Map> blocked = new HashMap<>(); + EnumMap>> blockedPredicate = new EnumMap<>(ClassType.class); Map nameRemapper = new HashMap<>(); Map biRequired = new HashMap<>(); Set enumRequired = new HashSet<>(); @@ -30,6 +34,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor List variables = new ArrayList<>(); List biVariables = new ArrayList<>(); List enumVariables = new ArrayList<>(); + boolean special = false; public PrimitiveCollectionsBuilder() { @@ -51,6 +56,19 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor super(silencedSuccess, sourceFolder, outputFolder, dataFolder); } + private PrimitiveCollectionsBuilder setSpecial() { + special = true; + return this; + } + + private static PrimitiveCollectionsBuilder createTests(boolean silent) { + return new PrimitiveCollectionsBuilder(silent, Paths.get("src/builder/resources/speiger/assets/tests/templates/"), Paths.get("src/test/java/speiger/src/tests/"), Paths.get("src/builder/resources/speiger/assets/tests/")).setSpecial(); + } + + private static PrimitiveCollectionsBuilder createTesters(boolean silent) { + return new PrimitiveCollectionsBuilder(silent, Paths.get("src/builder/resources/speiger/assets/testers/templates/"), Paths.get("src/test/java/speiger/src/testers/"), Paths.get("src/builder/resources/speiger/assets/testers/")).setSpecial(); + } + @Override protected boolean isFileValid(Path fileName) { @@ -72,7 +90,7 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor @Override protected void afterFinish() { - if(getVersion() > 8) + if(!special && getVersion() > 8) { Path basePath = Paths.get("src/main/java"); try(BufferedWriter writer = Files.newBufferedWriter(basePath.resolve("module-info.java"))) @@ -119,9 +137,50 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor nameRemapper.put("ImmutableOpenHashSet", "Immutable%sOpenHashSet"); nameRemapper.put("ImmutableOpenHashMap", "Immutable%sOpenHashMap"); + addBlockage(ClassType.OBJECT, "Consumer", "Comparator", "Stack"); addBlockage(ClassType.BOOLEAN, "ArraySet", "AVLTreeSet", "RBTreeSet", "SortedSet", "OrderedSet", "NavigableSet", "OpenHashSet", "OpenCustomHashSet", "LinkedOpenHashSet", "LinkedOpenCustomHashSet"); addBlockage(ClassType.BOOLEAN, "ConcurrentOpenHashMap", "ImmutableOpenHashMap", "ImmutableOpenHashSet", "SortedMap", "OrderedMap", "NavigableMap", "ConcurrentMap", "OpenHashMap", "LinkedOpenHashMap", "OpenCustomHashMap", "LinkedOpenCustomHashMap", "ArrayMap", "RBTreeMap", "AVLTreeMap"); + + //UnitTesters + nameRemapper.put("AbstractIteratorTester", "Abstract%sIteratorTester"); + nameRemapper.put("MinimalCollection", "Minimal%sCollection"); + nameRemapper.put("MinimalSet", "Minimal%sSet"); + nameRemapper.put("TestCollectionGenerator", "Test%sCollectionGenerator"); + nameRemapper.put("TestQueueGenerator", "Test%sQueueGenerator"); + nameRemapper.put("TestListGenerator", "Test%sListGenerator"); + nameRemapper.put("TestNavigableSetGenerator", "Test%sNavigableSetGenerator"); + nameRemapper.put("TestSortedSetGenerator", "Test%sSortedSetGenerator"); + nameRemapper.put("TestOrderedSetGenerator", "Test%sOrderedSetGenerator"); + nameRemapper.put("TestSetGenerator", "Test%sSetGenerator"); + nameRemapper.put("AbstractContainerTester", "Abstract%sContainerTester"); + nameRemapper.put("AbstractCollectionTester", "Abstract%sCollectionTester"); + nameRemapper.put("AbstractQueueTester", "Abstract%sQueueTester"); + nameRemapper.put("AbstractListTester", "Abstract%sListTester"); + nameRemapper.put("AbstractListIndexOfTester", "Abstract%sListIndexOfTester"); + nameRemapper.put("AbstractSetTester", "Abstract%sSetTester"); + nameRemapper.put("SimpleTestGenerator", "Simple%sTestGenerator"); + nameRemapper.put("SimpleQueueTestGenerator", "Simple%sQueueTestGenerator"); + nameRemapper.put("TestMapGenerator", "Test%sMapGenerator"); + nameRemapper.put("TestSortedMapGenerator", "Test%sSortedMapGenerator"); + nameRemapper.put("TestOrderedMapGenerator", "Test%sOrderedMapGenerator"); + nameRemapper.put("SimpleMapTestGenerator", "Simple%sMapTestGenerator"); + nameRemapper.put("DerivedMapGenerators", "Derived%sMapGenerators"); + nameRemapper.put("AbstractMapTester", "Abstract%sMapTester"); + nameRemapper.put("TestMap", "Test%sMap"); + biRequired.put("PairTester", ""); + + addBiClass("TestMapGenerator", "TestSortedMapGenerator", "TestOrderedMapGenerator", "SimpleMapTestGenerator", "DerivedMapGenerators", "AbstractMapTester", "MapTestSuiteBuilder", "SortedMapTestSuiteBuilder", "NavigableMapTestSuiteBuilder", "OrderedMapTestSuiteBuilder", "MapTests", "MapConstructorTests", "TestMap"); + addBiClass("MapAddToTester", "MapSubFromTester", "MapClearTester", "MapComputeIfAbsentTester", "MapComputeIfPresentTester", "MapComputeTester", "MapCopyTester", "MapContainsTester", "MapContainsKeyTester", "MapContainsValueTester", "MapCreatorTester", "MapEntrySetTester", + "MapEqualsTester", "MapForEachTester", "MapGetOrDefaultTester", "MapGetTester", "MapHashCodeTester", "MapIsEmptyTester", "MapMergeTester", "MapMergeBulkTester", "MapPutAllArrayTester", "MapPutAllTester", "MapPutIfAbsentTester", "MapPutTester", + "MapRemoveEntryTester", "MapRemoveOrDefaultTester", "MapRemoveTester", "MapReplaceAllTester", "MapReplaceEntryTester", "MapReplaceTester", "MapSizeTester", "MapSupplyIfAbsentTester", "MapToStringTester", + "NavigableMapNavigationTester", "SortedMapNavigationTester", "OrderedMapNavigationTester", "OrderedMapMoveTester", "MapConstructorTester"); + + addBlockage(ClassType.OBJECT, "CollectionStreamTester", "ListFillBufferTester"); + addBlockage(ClassType.BOOLEAN, "TestOrderedSetGenerator", "TestSortedSetGenerator", "TestNavigableSetGenerator", "CollectionRemoveIfTester", "CollectionStreamTester", "ListFillBufferTester", "ListReplaceAllTester", "NavigableSetNavigationTester", "SetTests", "MapConstructorTests", "TestMap", "QueueTests"); + addBlockage(ClassType.BOOLEAN, "OrderedSetMoveTester", "OrderedSetNavigationTester", "SortedSetNaviationTester", "SetTestSuiteBuilder", "OrderedSetTestSuiteBuilder", "SortedSetTestSuiteBuilder", "NavigableSetTestSuiteBuilder", "SortedSetSubsetTestSetGenerator", "OrderedMapNavigationTester", "OrderedMapTestSuiteBuilder", "OrderedSetIterationTester", "SortedSetIterationTester"); + addBlockage(ClassType.BOOLEAN, "TestMapGenerator", "TestSortedMapGenerator", "TestOrderedMapGenerator", "SimpleMapTestGenerator", "DerivedMapGenerators", "AbstractMapTester", "MapTestSuiteBuilder", "SortedMapTestSuiteBuilder", "NavigableMapTestSuiteBuilder", "MapTests"); + addBlockage(ClassType.BOOLEAN, T -> T.endsWith("Tester") && (T.startsWith("Iterable") ||T.startsWith("Map") || T.startsWith("OrderedMap") || T.startsWith("SortedMap") || T.startsWith("NavigableMap"))); } protected void create(ClassType mainType, ClassType subType) @@ -146,6 +205,11 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor } } + protected void addBlockage(ClassType type, Predicate filter) + { + blockedPredicate.computeIfAbsent(type, T -> new ArrayList<>()).add(filter); + } + protected void addBlockage(ClassType type, String...args) { for(String s : args) @@ -166,17 +230,29 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor String splitter = biRequired.get(name); boolean valueRequired = enumRequired.contains(name); List vars = getVariablesByClass(name, splitter != null); - EnumSet types = blocked.get(name); for(int i = 0,m=vars.size();i types = blocked.get(fileName); + if(types != null && types.contains(type)) return false; + List> list = blockedPredicate.get(type); + if(list != null) { + for(int i = 0,m=list.size();i getVariablesByClass(String name, boolean bi) { if(enumRequired.contains(name)) return enumVariables; if(bi) return biVariables; @@ -236,28 +312,19 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor { try { - if(args.length == 0) { - new PrimitiveCollectionsBuilder().process(false); - } else if(args.length == 1) { - new PrimitiveCollectionsBuilder().process(Boolean.parseBoolean(args[0])); - } else if(args.length == 2) { - new PrimitiveCollectionsBuilder(Boolean.parseBoolean(args[1])).process(Boolean.parseBoolean(args[0])); - } else if(args.length == 3) { - new PrimitiveCollectionsBuilder(Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(false); - } else if(args.length == 4) { - new PrimitiveCollectionsBuilder(false, Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(Boolean.parseBoolean(args[3])); - } else if(args.length == 4) { - new PrimitiveCollectionsBuilder(Boolean.parseBoolean(args[4]), Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(Boolean.parseBoolean(args[3])); - } else { - System.out.println("Invalid argument count passed in"); - System.exit(1); - } - } - catch(InterruptedException e) - { - e.printStackTrace(); - } - catch(IOException e) + Set flags = new HashSet<>(Arrays.asList(args)); + boolean silent = flags.contains("silent"); + boolean force = flags.contains("force"); + boolean tests = flags.contains("tests"); + boolean forceTests = flags.contains("force-tests"); + + new PrimitiveCollectionsBuilder(silent).process(force); + if(tests) { + createTests(silent).process(force || forceTests); + createTesters(silent).process(force || forceTests); + } + } + catch(InterruptedException | IOException e) { e.printStackTrace(); } diff --git a/src/builder/resources/speiger/assets/testers/templates/builder/CollectionTestSuiteBuilder.template b/src/builder/resources/speiger/assets/testers/templates/builder/CollectionTestSuiteBuilder.template new file mode 100644 index 00000000..b6512098 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/builder/CollectionTestSuiteBuilder.template @@ -0,0 +1,91 @@ +package speiger.src.testers.PACKAGE.builder; + +import java.util.List; + +import com.google.common.collect.testing.AbstractTester; +import com.google.common.collect.testing.CollectionTestSuiteBuilder; +import com.google.common.collect.testing.Helpers; +import com.google.common.collect.testing.testers.CollectionRemoveIfTester; + +import speiger.src.testers.base.tests.collection.JavaCollectionRemoveIfTester; +import speiger.src.testers.PACKAGE.generators.TEST_COLLECTION_GENERATOR; +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionAddAllArrayTester; +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionAddAllTester; +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionAddTester; +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionClearTester; +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionContainsAllTester; +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionContainsAnyTester; +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionContainsTester; +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionCopyTester; +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionEqualsTester; +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionForEachTester; +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionIteratorTester; +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionRemoveAllTester; +#if !TYPE_BOOLEAN +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionRemoveIfTester; +#if !TYPE_OBJECT +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionStreamTester; +#endif +#endif +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionRetainAllTester; +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionToArrayTester; +#if !TYPE_BOOLEAN +import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableCountTester; +import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableDistinctTester; +import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableFilterTester; +import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableFindFirstTester; +import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableLimitTester; +import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableMapTester; +import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableMatchesTester; +import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterablePeekTester; +import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableReduceTester; +import speiger.src.testers.PACKAGE.tests.iterable.FILE_KEY_TYPEIterableSortedTester; +#endif + +@SuppressWarnings("javadoc") +public class COLLECTION_TEST_BUILDER KEY_GENERIC_TYPE extends CollectionTestSuiteBuilder { + public static GENERIC_KEY_BRACES COLLECTION_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_COLLECTION_GENERATOR KEY_GENERIC_TYPE generator) { + return (COLLECTION_TEST_BUILDER KEY_GENERIC_TYPE) new COLLECTION_TEST_BUILDER KEY_GENERIC_TYPE().usingGenerator(generator); + } + + @Override + @SuppressWarnings("rawtypes") + protected List> getTesters() { + List> testers = Helpers.copyToList(super.getTesters()); + testers.remove(CollectionRemoveIfTester.class); + testers.add(JavaCollectionRemoveIfTester.class); +#if !TYPE_BOOLEAN + testers.add(FILE_KEY_TYPEIterableMapTester.class); + testers.add(FILE_KEY_TYPEIterableFilterTester.class); + testers.add(FILE_KEY_TYPEIterableDistinctTester.class); + testers.add(FILE_KEY_TYPEIterableLimitTester.class); + testers.add(FILE_KEY_TYPEIterableSortedTester.class); + testers.add(FILE_KEY_TYPEIterableMatchesTester.class); + testers.add(FILE_KEY_TYPEIterablePeekTester.class); + testers.add(FILE_KEY_TYPEIterableReduceTester.class); + testers.add(FILE_KEY_TYPEIterableCountTester.class); + testers.add(FILE_KEY_TYPEIterableFindFirstTester.class); +#endif + testers.add(FILE_KEY_TYPECollectionAddAllTester.class); + testers.add(FILE_KEY_TYPECollectionAddAllArrayTester.class); + testers.add(FILE_KEY_TYPECollectionAddTester.class); + testers.add(FILE_KEY_TYPECollectionClearTester.class); + testers.add(FILE_KEY_TYPECollectionContainsAllTester.class); + testers.add(FILE_KEY_TYPECollectionContainsAnyTester.class); + testers.add(FILE_KEY_TYPECollectionContainsTester.class); + testers.add(FILE_KEY_TYPECollectionCopyTester.class); + testers.add(FILE_KEY_TYPECollectionEqualsTester.class); + testers.add(FILE_KEY_TYPECollectionForEachTester.class); + testers.add(FILE_KEY_TYPECollectionIteratorTester.class); + testers.add(FILE_KEY_TYPECollectionRemoveAllTester.class); + testers.add(FILE_KEY_TYPECollectionRetainAllTester.class); +#if !TYPE_BOOLEAN + testers.add(FILE_KEY_TYPECollectionRemoveIfTester.class); +#if !TYPE_OBJECT + testers.add(FILE_KEY_TYPECollectionStreamTester.class); +#endif +#endif + testers.add(FILE_KEY_TYPECollectionToArrayTester.class); + return testers; + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/builder/DequeueTestSuiteBuilder.template b/src/builder/resources/speiger/assets/testers/templates/builder/DequeueTestSuiteBuilder.template new file mode 100644 index 00000000..5f843f10 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/builder/DequeueTestSuiteBuilder.template @@ -0,0 +1,28 @@ +package speiger.src.testers.PACKAGE.builder; + +import java.util.List; + +import com.google.common.collect.testing.AbstractTester; + +import speiger.src.testers.PACKAGE.generators.TEST_QUEUE_GENERATOR; +import speiger.src.testers.PACKAGE.tests.queue.FILE_KEY_TYPEDequeueDequeueTester; +import speiger.src.testers.PACKAGE.tests.queue.FILE_KEY_TYPEDequeueEnqueueTester; +import speiger.src.testers.PACKAGE.tests.queue.FILE_KEY_TYPEDequeueLastTester; + +@SuppressWarnings("javadoc") +public class DEQUEUE_TEST_BUILDER KEY_GENERIC_TYPE extends QUEUE_TEST_BUILDER KEY_GENERIC_TYPE +{ + public static GENERIC_KEY_BRACES DEQUEUE_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_QUEUE_GENERATOR KEY_GENERIC_TYPE builder) { + return (DEQUEUE_TEST_BUILDER KEY_GENERIC_TYPE)new DEQUEUE_TEST_BUILDER KEY_GENERIC_TYPE().usingGenerator(builder); + } + + @Override + @SuppressWarnings("rawtypes") + protected List> getTesters() { + List> tester = super.getTesters(); + tester.add(FILE_KEY_TYPEDequeueDequeueTester.class); + tester.add(FILE_KEY_TYPEDequeueEnqueueTester.class); + tester.add(FILE_KEY_TYPEDequeueLastTester.class); + return tester; + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/builder/ListTestSuiteBuilder.template b/src/builder/resources/speiger/assets/testers/templates/builder/ListTestSuiteBuilder.template new file mode 100644 index 00000000..d4fac2e7 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/builder/ListTestSuiteBuilder.template @@ -0,0 +1,384 @@ +package speiger.src.testers.PACKAGE.builder; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER; +import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE; +import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS; +#endignore + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import com.google.common.collect.testing.AbstractTester; +import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder; +import com.google.common.collect.testing.Helpers; +import com.google.common.collect.testing.ListTestSuiteBuilder; +import com.google.common.collect.testing.OneSizeTestContainerGenerator; +import com.google.common.collect.testing.SampleElements; +import com.google.common.collect.testing.TestListGenerator; +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.Feature; +import com.google.common.collect.testing.testers.CollectionSerializationEqualTester; +import com.google.common.collect.testing.testers.ListAddAllAtIndexTester; +import com.google.common.collect.testing.testers.ListAddAllTester; +import com.google.common.collect.testing.testers.ListAddAtIndexTester; +import com.google.common.collect.testing.testers.ListAddTester; +import com.google.common.collect.testing.testers.ListCreationTester; +import com.google.common.collect.testing.testers.ListEqualsTester; +import com.google.common.collect.testing.testers.ListGetTester; +import com.google.common.collect.testing.testers.ListHashCodeTester; +import com.google.common.collect.testing.testers.ListIndexOfTester; +import com.google.common.collect.testing.testers.ListLastIndexOfTester; +import com.google.common.collect.testing.testers.ListRemoveAllTester; +import com.google.common.collect.testing.testers.ListRemoveAtIndexTester; +import com.google.common.collect.testing.testers.ListRemoveTester; +import com.google.common.collect.testing.testers.ListReplaceAllTester; +import com.google.common.collect.testing.testers.ListRetainAllTester; +import com.google.common.collect.testing.testers.ListSetTester; +import com.google.common.collect.testing.testers.ListSubListTester; +import com.google.common.collect.testing.testers.ListToArrayTester; +import com.google.common.testing.SerializableTester; + +import junit.framework.TestSuite; +import speiger.src.collections.PACKAGE.collections.ITERABLE; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.base.tests.list.JavaListListIteratorTester; +import speiger.src.testers.PACKAGE.generators.TEST_LIST_GENERATOR; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListAbsentTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListAddAllArrayAtIndexTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListAddAllAtIndexTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListAddAllListAtIndexTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListAddAllTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListAddAtIndexTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListAddTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListCreationTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListEqualsTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListExtractElementsTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListGetElementsTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListGetTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListIndexOfTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListLastIndexOfTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListListIteratorTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListPresentTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListRemoveAllTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListRemoveAtIndexTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListRemoveElementsTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListRemoveTester; +#if !TYPE_BOOLEAN +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListSortTester; +#if !TYPE_OBJECT +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListFillBufferTester; +#endif +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListReplaceAllTester; +#endif +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListRetainAllTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListSetTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListSubListTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListSwapRemoveAtIndexTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListSwapRemoveTester; +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListToArrayTester; +import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS; +#if !TYPE_BOOLEAN +import speiger.src.testers.utils.SpecialFeature; +#endif + +@SuppressWarnings("javadoc") +public class LIST_TEST_BUILDER KEY_GENERIC_TYPE extends COLLECTION_TEST_BUILDER KEY_GENERIC_TYPE { + +#if TYPE_OBJECT + KEY_TYPE[] prefixes; + KEY_TYPE[] suffixes; +#else + KEY_TYPE[] prefixes = createPrefixes(); + KEY_TYPE[] suffixes = createSuffixes(); +#endif + + public static GENERIC_KEY_BRACES LIST_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_LIST_GENERATOR KEY_GENERIC_TYPE generator) { + return (LIST_TEST_BUILDER KEY_GENERIC_TYPE) new LIST_TEST_BUILDER KEY_GENERIC_TYPE().usingGenerator(generator); + } + + public LIST_TEST_BUILDER KEY_GENERIC_TYPE setPrefixes(KEY_TYPE[] prefixes) { + this.prefixes = prefixes; + return this; + } + + public LIST_TEST_BUILDER KEY_GENERIC_TYPE setSuffixes(KEY_TYPE[] suffixes) { + this.suffixes = suffixes; + return this; + } + +#if !TYPE_OBJECT + public KEY_TYPE[] createPrefixes() { +#if TYPE_BOOLEAN + return new KEY_TYPE[]{false, false, false}; +#else if TYPE_BYTE + return new KEY_TYPE[]{(byte)-3, (byte)-2, (byte)-1}; +#else if TYPE_SHORT + return new KEY_TYPE[]{(short)-3, (short)-2, (short)-1}; +#else if TYPE_CHAR + return new KEY_TYPE[]{'^', '_', '`'}; +#else + return new KEY_TYPE[]{-3, -2, -1}; +#endif + } + + public KEY_TYPE[] createSuffixes() { +#if TYPE_BOOLEAN + return new KEY_TYPE[]{true, true, true}; +#else if TYPE_BYTE + return new KEY_TYPE[]{(byte)5, (byte)6, (byte)7}; +#else if TYPE_SHORT + return new KEY_TYPE[]{(short)5, (short)6, (short)7}; +#else if TYPE_CHAR + return new KEY_TYPE[]{'f', 'g', 'h'}; +#else + return new KEY_TYPE[]{5, 6, 7}; +#endif + } + +#endif + @Override + @SuppressWarnings("rawtypes") + protected List> getTesters() { + List> testers = Helpers.copyToList(super.getTesters()); + + testers.add(CollectionSerializationEqualTester.class); + testers.add(ListAddAllAtIndexTester.class); + testers.add(ListAddAllTester.class); + testers.add(ListAddAtIndexTester.class); + testers.add(ListAddTester.class); + testers.add(ListCreationTester.class); + testers.add(ListEqualsTester.class); + testers.add(ListGetTester.class); + testers.add(ListHashCodeTester.class); + testers.add(ListIndexOfTester.class); + testers.add(ListLastIndexOfTester.class); + testers.add(JavaListListIteratorTester.class); + testers.add(ListRemoveAllTester.class); + testers.add(ListRemoveAtIndexTester.class); + testers.add(ListRemoveTester.class); + testers.add(ListReplaceAllTester.class); + testers.add(ListRetainAllTester.class); + testers.add(ListSetTester.class); + testers.add(ListSubListTester.class); + testers.add(ListToArrayTester.class); + + testers.add(FILE_KEY_TYPEListAddAllAtIndexTester.class); + testers.add(FILE_KEY_TYPEListAddAllListAtIndexTester.class); + testers.add(FILE_KEY_TYPEListAddAllArrayAtIndexTester.class); + testers.add(FILE_KEY_TYPEListAddAllTester.class); + testers.add(FILE_KEY_TYPEListAddAtIndexTester.class); + testers.add(FILE_KEY_TYPEListAddTester.class); + testers.add(FILE_KEY_TYPEListAbsentTester.class); + testers.add(FILE_KEY_TYPEListPresentTester.class); + testers.add(FILE_KEY_TYPEListCreationTester.class); + testers.add(FILE_KEY_TYPEListEqualsTester.class); + testers.add(FILE_KEY_TYPEListGetTester.class); + testers.add(FILE_KEY_TYPEListGetElementsTester.class); + testers.add(FILE_KEY_TYPEListExtractElementsTester.class); + testers.add(FILE_KEY_TYPEListIndexOfTester.class); + testers.add(FILE_KEY_TYPEListLastIndexOfTester.class); + testers.add(FILE_KEY_TYPEListListIteratorTester.class); + testers.add(FILE_KEY_TYPEListRemoveAllTester.class); + testers.add(FILE_KEY_TYPEListRemoveAtIndexTester.class); + testers.add(FILE_KEY_TYPEListRemoveTester.class); + testers.add(FILE_KEY_TYPEListRemoveElementsTester.class); + testers.add(FILE_KEY_TYPEListSwapRemoveAtIndexTester.class); + testers.add(FILE_KEY_TYPEListSwapRemoveTester.class); +#if !TYPE_BOOLEAN + testers.add(FILE_KEY_TYPEListSortTester.class); +#if !TYPE_OBJECT + testers.add(FILE_KEY_TYPEListFillBufferTester.class); +#endif + testers.add(FILE_KEY_TYPEListReplaceAllTester.class); +#endif + testers.add(FILE_KEY_TYPEListRetainAllTester.class); + testers.add(FILE_KEY_TYPEListSetTester.class); + testers.add(FILE_KEY_TYPEListSubListTester.class); + testers.add(FILE_KEY_TYPEListToArrayTester.class); + return testers; + } + + @Override + public TestSuite createTestSuite() { +#ignore + withFeatures(KNOWN_ORDER); +#endignore + return super.createTestSuite(); + } + + @Override + protected List createDerivedSuites(FeatureSpecificTestSuiteBuilder, CLASS_TYPE>> parentBuilder) { + List derivedSuites = new ArrayList<>(super.createDerivedSuites(parentBuilder)); +#ignore + if (parentBuilder.getFeatures().contains(SERIALIZABLE)) { +#endignore + derivedSuites.add(ListTestSuiteBuilder.using(new ReserializedListGenerator(parentBuilder.getSubjectGenerator())) + .named(getName() + " reserialized") + .withFeatures(computeReserializedCollectionFeatures(parentBuilder.getFeatures())) + .suppressing(parentBuilder.getSuppressedTests()).withSetUp(parentBuilder.getSetUp()) + .withTearDown(parentBuilder.getTearDown()).createTestSuite()); + } +#ignore + if(!parentBuilder.getFeatures().contains(CollectionFeature.SUBSET_VIEW)) { +#endignore +#if !TYPE_BOOLEAN + if(prefixes != null) { + derivedSuites.add(LIST_TEST_BUILDER.using(new SubListListGeneratorBRACES(parentBuilder.getSubjectGenerator(), prefixes, null)) + .named(getName() + " subSet_prefix") + .withFeatures(computeSubListFeatures(parentBuilder.getFeatures())) + .suppressing(parentBuilder.getSuppressedTests()).withSetUp(parentBuilder.getSetUp()) + .withTearDown(parentBuilder.getTearDown()).createTestSuite()); + } + if(suffixes != null) { + derivedSuites.add(LIST_TEST_BUILDER.using(new SubListListGeneratorBRACES(parentBuilder.getSubjectGenerator(), null, suffixes)) + .named(getName() + " subSet_suffixes") + .withFeatures(computeSubListFeatures(parentBuilder.getFeatures())) + .suppressing(parentBuilder.getSuppressedTests()).withSetUp(parentBuilder.getSetUp()) + .withTearDown(parentBuilder.getTearDown()).createTestSuite()); + } + if(prefixes != null && suffixes != null) { + derivedSuites.add(LIST_TEST_BUILDER.using(new SubListListGeneratorBRACES(parentBuilder.getSubjectGenerator(), prefixes, suffixes)) + .named(getName() + " subSet") + .withFeatures(computeSubListFeatures(parentBuilder.getFeatures())) + .suppressing(parentBuilder.getSuppressedTests()).withSetUp(parentBuilder.getSetUp()) + .withTearDown(parentBuilder.getTearDown()).createTestSuite()); + } +#endif + } + return derivedSuites; + } + + static class SubListListGenerator KEY_GENERIC_TYPE implements TEST_LIST_GENERATOR KEY_GENERIC_TYPE { + TEST_LIST_GENERATOR KEY_GENERIC_TYPE generator; + KEY_TYPE[] prefix; + KEY_TYPE[] suffix; + + public SubListListGenerator(OneSizeTestContainerGenerator, CLASS_TYPE> gen, KEY_TYPE[] prefix, KEY_TYPE[] suffix) { + generator = (TEST_LIST_GENERATOR KEY_GENERIC_TYPE)gen.getInnerGenerator(); + this.prefix = prefix; + this.suffix = suffix; + } + + @Override + public SampleElements samples() { + return generator.samples(); + } + + @Override + public CLASS_TYPE[] createArray(int length) { + return generator.createArray(length); + } + + @Override + public Iterable order(List insertionOrder) { + return generator.order(insertionOrder); + } + + @Override + public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() { + return generator.getSamples(); + } + + @Override + public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) { + return generator.order(insertionOrder); + } + +#if !TYPE_OBJECT + @Override + public LIST KEY_GENERIC_TYPE create(Object... elements) { + KEY_TYPE[] array = NEW_KEY_ARRAY(elements.length); + int i = 0; + for (Object e : elements) { + array[i++] = CLASS_TO_KEY(e); + } + return create(array); + } + + @Override + public LIST KEY_GENERIC_TYPE create(KEY_TYPE... elements) { + int length = getLength(prefix); + return generator.create(merge(elements)).subList(length, length+elements.length); + } + +#else + @Override + public LIST KEY_GENERIC_TYPE create(Object... elements) { + KEY_TYPE[] array = NEW_KEY_ARRAY(elements.length); + int i = 0; + for (Object e : elements) { + array[i++] = CLASS_TO_KEY(e); + } + int length = getLength(prefix); + return generator.create(merge(array)).subList(length, length+elements.length); + } + +#endif + private int getLength(KEY_TYPE[] keys) { + return keys == null ? 0 : keys.length; + } + + private KEY_TYPE[] merge(KEY_TYPE[] input) { + int prefixLength = getLength(prefix); + int suffixLength = getLength(suffix); + KEY_TYPE[] result = NEW_KEY_ARRAY(input.length+prefixLength+suffixLength); + if(prefixLength != 0) System.arraycopy(prefix, 0, result, 0, prefixLength); + System.arraycopy(input, 0, result, prefixLength, input.length); + if(suffixLength != 0) System.arraycopy(suffix, 0, result, prefixLength+input.length, suffixLength); + return result; + } + } + + static class ReserializedListGenerator implements TestListGenerator { + final OneSizeTestContainerGenerator, E> gen; + + private ReserializedListGenerator(OneSizeTestContainerGenerator, E> gen) { + this.gen = gen; + } + + @Override + public SampleElements samples() { + return gen.samples(); + } + + @Override + public List create(Object... elements) { + return (List) SerializableTester.reserialize(gen.create(elements)); + } + + @Override + public E[] createArray(int length) { + return gen.createArray(length); + } + + @Override + public Iterable order(List insertionOrder) { + return gen.order(insertionOrder); + } + } + +#if !TYPE_BOOLEAN + private static Set> computeSubListFeatures(Set> features) { + Set> derivedFeatures = new HashSet<>(features); +#ignore + derivedFeatures.add(CollectionFeature.SUBSET_VIEW); + derivedFeatures.remove(SpecialFeature.COPYING); + derivedFeatures.remove(SpecialFeature.CHILDREN_COPY); +#endignore + return derivedFeatures; + } + +#endif + private static Set> computeReserializedCollectionFeatures(Set> features) { + Set> derivedFeatures = new HashSet<>(features); +#ignore + derivedFeatures.remove(SERIALIZABLE); + derivedFeatures.remove(SERIALIZABLE_INCLUDING_VIEWS); +#endignore + return derivedFeatures; + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/builder/NavigableSetTestSuiteBuilder.template b/src/builder/resources/speiger/assets/testers/templates/builder/NavigableSetTestSuiteBuilder.template new file mode 100644 index 00000000..0c66f408 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/builder/NavigableSetTestSuiteBuilder.template @@ -0,0 +1,140 @@ +package speiger.src.testers.PACKAGE.builder; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.DESCENDING_VIEW; +import static com.google.common.collect.testing.features.CollectionFeature.SUBSET_VIEW; +#endignore + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import com.google.common.collect.testing.AbstractTester; +import com.google.common.collect.testing.DerivedCollectionGenerators.Bound; +import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder; +import com.google.common.collect.testing.Helpers; +import com.google.common.collect.testing.OneSizeTestContainerGenerator; +import com.google.common.collect.testing.SampleElements; +import com.google.common.collect.testing.features.Feature; +import com.google.common.collect.testing.testers.NavigableSetNavigationTester; + +import junit.framework.TestSuite; +import speiger.src.collections.PACKAGE.collections.ITERABLE; +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET; +import speiger.src.collections.PACKAGE.utils.LISTS; +import speiger.src.testers.PACKAGE.generators.TEST_NAVIGABLE_SET_GENERATOR; +import speiger.src.testers.PACKAGE.generators.TEST_SORTED_SET_GENERATOR; +import speiger.src.testers.PACKAGE.impl.SUB_SORTED_SET_CLASS_GENERATOR.SUB_NAVIGABLE_SET_CLASS_GENERATOR; +import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPENavigableSetNavigationTester; +import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS; +import speiger.src.testers.utils.SpecialFeature; + +@SuppressWarnings("javadoc") +public class NAVIGABLE_SET_TEST_BUILDER KEY_GENERIC_TYPE extends SORTED_SET_TEST_BUILDER KEY_GENERIC_TYPE { + public static GENERIC_KEY_BRACES NAVIGABLE_SET_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE generator) { + return (NAVIGABLE_SET_TEST_BUILDER KEY_GENERIC_TYPE) new NAVIGABLE_SET_TEST_BUILDER KEY_GENERIC_TYPE().usingGenerator(generator); + } + + @Override + @SuppressWarnings("rawtypes") + protected List> getTesters() { + List> testers = Helpers.copyToList(super.getTesters()); + testers.add(NavigableSetNavigationTester.class); + testers.add(FILE_KEY_TYPENavigableSetNavigationTester.class); + return testers; + } + + @Override + protected List createDerivedSuites(FeatureSpecificTestSuiteBuilder, CLASS_TYPE>> parentBuilder) { + List derivedSuites = new ArrayList<>(super.createDerivedSuites(parentBuilder)); + +#ignore + if (!parentBuilder.getFeatures().contains(SUBSET_VIEW)) { +#endignore + // Other combinations are inherited from SortedSetTestSuiteBuilder. + derivedSuites.add(createSubsetSuite(parentBuilder, Bound.NO_BOUND, Bound.INCLUSIVE)); + derivedSuites.add(createSubsetSuite(parentBuilder, Bound.EXCLUSIVE, Bound.NO_BOUND)); + derivedSuites.add(createSubsetSuite(parentBuilder, Bound.EXCLUSIVE, Bound.EXCLUSIVE)); + derivedSuites.add(createSubsetSuite(parentBuilder, Bound.EXCLUSIVE, Bound.INCLUSIVE)); + derivedSuites.add(createSubsetSuite(parentBuilder, Bound.INCLUSIVE, Bound.INCLUSIVE)); + } +#ignore + if (!parentBuilder.getFeatures().contains(DESCENDING_VIEW)) { +#endignore + derivedSuites.add(createDescendingSuite(parentBuilder)); + } + return derivedSuites; + } + + @Override + SORTED_SET_TEST_BUILDER KEY_GENERIC_TYPE newBuilderUsing(TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE delegate, Bound to, Bound from) { + return NAVIGABLE_SET_TEST_BUILDER.using(new SUB_NAVIGABLE_SET_CLASS_GENERATORBRACES(delegate, to, from)); + } + + private TestSuite createDescendingSuite(FeatureSpecificTestSuiteBuilder, CLASS_TYPE>> parentBuilder) { + TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE delegate = (TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE) parentBuilder.getSubjectGenerator().getInnerGenerator(); + + List> features = new ArrayList<>(); +#ignore + features.add(DESCENDING_VIEW); + features.addAll(parentBuilder.getFeatures()); + features.remove(SpecialFeature.COPYING); + features.remove(SpecialFeature.CHILDREN_COPY); +#endignore + + return NAVIGABLE_SET_TEST_BUILDER.using(new TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE() { + + @Override + public SampleElements samples() { + return delegate.samples(); + } + + @Override + public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() { + return delegate.getSamples(); + } + + @Override + public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) { + LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); + delegate.order(insertionOrder).forEach(list::add); + LISTS.reverse(list); + return list; + } + + @Override + public Iterable order(List insertionOrder) { + LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); + for(CLASS_TYPE entry : delegate.order(insertionOrder)) + { + list.add(OBJ_TO_KEY(entry)); + } + LISTS.reverse(list); + return list; + } + @Override + public KEY_TYPE belowSamplesLesser() { return delegate.aboveSamplesGreater(); } + @Override + public KEY_TYPE belowSamplesGreater() { return delegate.aboveSamplesLesser(); } + @Override + public KEY_TYPE aboveSamplesLesser() { return delegate.belowSamplesGreater(); } + @Override + public KEY_TYPE aboveSamplesGreater() { return delegate.belowSamplesLesser(); } + +#if !TYPE_OBJECT + @Override + public NAVIGABLE_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements) { + return delegate.create(elements).descendingSet(); + } + +#endif + @Override + public NAVIGABLE_SET KEY_GENERIC_TYPE create(Object... elements) { + return delegate.create(elements).descendingSet(); + } + }).named(parentBuilder.getName() + " descending").withFeatures(features) + .suppressing(parentBuilder.getSuppressedTests()).createTestSuite(); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/builder/OrderedSetTestSuiteBuilder.template b/src/builder/resources/speiger/assets/testers/templates/builder/OrderedSetTestSuiteBuilder.template new file mode 100644 index 00000000..2c4818e6 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/builder/OrderedSetTestSuiteBuilder.template @@ -0,0 +1,38 @@ +package speiger.src.testers.PACKAGE.builder; + +import java.util.List; + +import com.google.common.collect.testing.AbstractTester; +import com.google.common.collect.testing.Helpers; +import com.google.common.collect.testing.features.CollectionFeature; + +import junit.framework.TestSuite; +import speiger.src.testers.PACKAGE.generators.TEST_ORDERED_SET_GENERATOR; +import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPEOrderedSetMoveTester; +import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPEOrderedSetIterationTester; +import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPEOrderedSetNavigationTester; + +@SuppressWarnings("javadoc") +public class ORDERED_SET_TEST_BUILDER KEY_GENERIC_TYPE extends SET_TEST_BUILDER KEY_GENERIC_TYPE { + public static GENERIC_KEY_BRACES ORDERED_SET_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE generator) { + return (ORDERED_SET_TEST_BUILDER KEY_GENERIC_TYPE) new ORDERED_SET_TEST_BUILDER KEY_GENERIC_TYPE().usingGenerator(generator); + } + + @Override + @SuppressWarnings("rawtypes") + protected List> getTesters() { + List> testers = Helpers.copyToList(super.getTesters()); + testers.add(FILE_KEY_TYPEOrderedSetNavigationTester.class); + testers.add(FILE_KEY_TYPEOrderedSetMoveTester.class); + testers.add(FILE_KEY_TYPEOrderedSetIterationTester.class); + return testers; + } + + @Override + public TestSuite createTestSuite() { +#ignore + withFeatures(CollectionFeature.KNOWN_ORDER); +#endignore + return super.createTestSuite(); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/builder/QueueTestSuiteBuilder.template b/src/builder/resources/speiger/assets/testers/templates/builder/QueueTestSuiteBuilder.template new file mode 100644 index 00000000..a7e72286 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/builder/QueueTestSuiteBuilder.template @@ -0,0 +1,60 @@ +package speiger.src.testers.PACKAGE.builder; + +import java.util.ArrayList; +import java.util.List; + +import com.google.common.collect.testing.AbstractTester; +import com.google.common.collect.testing.PerCollectionSizeTestSuiteBuilder; + +import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE; +import speiger.src.testers.PACKAGE.generators.TEST_QUEUE_GENERATOR; +import speiger.src.testers.PACKAGE.tests.queue.FILE_KEY_TYPEQueueDequeueTester; +import speiger.src.testers.PACKAGE.tests.queue.FILE_KEY_TYPEQueueEnqueueTester; +import speiger.src.testers.PACKAGE.tests.queue.FILE_KEY_TYPEQueueFirstTester; +import speiger.src.testers.PACKAGE.tests.queue.FILE_KEY_TYPEQueueRemoveTester; +import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueCountTester; +import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueDistinctTester; +import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueFilterTester; +import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueFindFirstTester; +import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueLimitTester; +import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueMapTester; +import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueMatchesTester; +import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueuePeekTester; +import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueForEachTester; +import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueReduceTester; +import speiger.src.testers.PACKAGE.tests.queue.iterators.FILE_KEY_TYPEQueueSortedTester; + +@SuppressWarnings("javadoc") +public class QUEUE_TEST_BUILDER KEY_GENERIC_TYPE extends PerCollectionSizeTestSuiteBuilder +{ + public static GENERIC_KEY_BRACES QUEUE_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_QUEUE_GENERATOR KEY_GENERIC_TYPE builder) { + return new QUEUE_TEST_BUILDER KEY_GENERIC_TYPE().usingGenerator(builder); + } + + @Override + @SuppressWarnings("rawtypes") + protected List> getTesters() + { + List> testers = new ArrayList<>(); + testers.add(FILE_KEY_TYPEQueueEnqueueTester.class); + testers.add(FILE_KEY_TYPEQueueDequeueTester.class); + testers.add(FILE_KEY_TYPEQueueFirstTester.class); + testers.add(FILE_KEY_TYPEQueueRemoveTester.class); + testers.add(FILE_KEY_TYPEQueueCountTester.class); + testers.add(FILE_KEY_TYPEQueueCountTester.class); + testers.add(FILE_KEY_TYPEQueueDequeueTester.class); + testers.add(FILE_KEY_TYPEQueueDistinctTester.class); + testers.add(FILE_KEY_TYPEQueueFilterTester.class); + testers.add(FILE_KEY_TYPEQueueFindFirstTester.class); + testers.add(FILE_KEY_TYPEQueueFirstTester.class); + testers.add(FILE_KEY_TYPEQueueLimitTester.class); + testers.add(FILE_KEY_TYPEQueueMapTester.class); + testers.add(FILE_KEY_TYPEQueueMatchesTester.class); + testers.add(FILE_KEY_TYPEQueuePeekTester.class); + testers.add(FILE_KEY_TYPEQueueForEachTester.class); + testers.add(FILE_KEY_TYPEQueueReduceTester.class); + testers.add(FILE_KEY_TYPEQueueSortedTester.class); + return testers; + } + +} diff --git a/src/builder/resources/speiger/assets/testers/templates/builder/SetTestSuiteBuilder.template b/src/builder/resources/speiger/assets/testers/templates/builder/SetTestSuiteBuilder.template new file mode 100644 index 00000000..afe82bf3 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/builder/SetTestSuiteBuilder.template @@ -0,0 +1,116 @@ +package speiger.src.testers.PACKAGE.builder; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE; +import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS; +#endignore + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import com.google.common.collect.testing.AbstractTester; +import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder; +import com.google.common.collect.testing.Helpers; +import com.google.common.collect.testing.OneSizeTestContainerGenerator; +import com.google.common.collect.testing.SampleElements; +import com.google.common.collect.testing.SetTestSuiteBuilder; +import com.google.common.collect.testing.TestSetGenerator; +import com.google.common.collect.testing.features.Feature; +import com.google.common.collect.testing.testers.CollectionSerializationEqualTester; +import com.google.common.collect.testing.testers.SetAddAllTester; +import com.google.common.collect.testing.testers.SetAddTester; +import com.google.common.collect.testing.testers.SetCreationTester; +import com.google.common.collect.testing.testers.SetEqualsTester; +import com.google.common.collect.testing.testers.SetHashCodeTester; +import com.google.common.collect.testing.testers.SetRemoveTester; +import com.google.common.testing.SerializableTester; + +import junit.framework.TestSuite; +import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR; +import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPESetAddAllTester; +import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPESetAddTester; +import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPESetCreationTester; +import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPESetEqualsTester; +import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPESetRemoveTester; + +@SuppressWarnings("javadoc") +public class SET_TEST_BUILDER KEY_GENERIC_TYPE extends COLLECTION_TEST_BUILDER KEY_GENERIC_TYPE { + public static GENERIC_KEY_BRACES SET_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_SET_GENERATOR KEY_GENERIC_TYPE generator) { + return (SET_TEST_BUILDER KEY_GENERIC_TYPE) new SET_TEST_BUILDER KEY_GENERIC_TYPE().usingGenerator(generator); + } + + @Override + @SuppressWarnings("rawtypes") + protected List> getTesters() { + List> testers = Helpers.copyToList(super.getTesters()); + testers.add(CollectionSerializationEqualTester.class); + testers.add(SetAddAllTester.class); + testers.add(SetAddTester.class); + testers.add(SetCreationTester.class); + testers.add(SetHashCodeTester.class); + testers.add(SetEqualsTester.class); + testers.add(SetRemoveTester.class); + + testers.add(FILE_KEY_TYPESetAddAllTester.class); + testers.add(FILE_KEY_TYPESetAddTester.class); + testers.add(FILE_KEY_TYPESetCreationTester.class); + testers.add(FILE_KEY_TYPESetEqualsTester.class); + testers.add(FILE_KEY_TYPESetRemoveTester.class); + return testers; + } + + @Override + protected List createDerivedSuites( + FeatureSpecificTestSuiteBuilder, CLASS_TYPE>> parentBuilder) { + List derivedSuites = new ArrayList<>(super.createDerivedSuites(parentBuilder)); + + if (parentBuilder.getFeatures().contains(SERIALIZABLE)) { + derivedSuites.add(SetTestSuiteBuilder.using(new ReserializedSetGenerator(parentBuilder.getSubjectGenerator())) + .named(getName() + " reserialized") + .withFeatures(computeReserializedCollectionFeatures(parentBuilder.getFeatures())) + .suppressing(parentBuilder.getSuppressedTests()).withSetUp(parentBuilder.getSetUp()) + .withTearDown(parentBuilder.getTearDown()).createTestSuite()); + } + return derivedSuites; + } + + static class ReserializedSetGenerator implements TestSetGenerator { + final OneSizeTestContainerGenerator, E> gen; + + private ReserializedSetGenerator(OneSizeTestContainerGenerator, E> gen) { + this.gen = gen; + } + + @Override + public SampleElements samples() { + return gen.samples(); + } + + @Override + public Set create(Object... elements) { + return (Set) SerializableTester.reserialize(gen.create(elements)); + } + + @Override + public E[] createArray(int length) { + return gen.createArray(length); + } + + @Override + public Iterable order(List insertionOrder) { + return gen.order(insertionOrder); + } + } + + private static Set> computeReserializedCollectionFeatures(Set> features) { + Set> derivedFeatures = new HashSet<>(features); +#ignore + derivedFeatures.remove(SERIALIZABLE); + derivedFeatures.remove(SERIALIZABLE_INCLUDING_VIEWS); +#endignore + return derivedFeatures; + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/builder/SortedSetTestSuiteBuilder.template b/src/builder/resources/speiger/assets/testers/templates/builder/SortedSetTestSuiteBuilder.template new file mode 100644 index 00000000..c13e4098 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/builder/SortedSetTestSuiteBuilder.template @@ -0,0 +1,88 @@ +package speiger.src.testers.PACKAGE.builder; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import com.google.common.collect.testing.AbstractTester; +import com.google.common.collect.testing.DerivedCollectionGenerators.Bound; +import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder; +import com.google.common.collect.testing.Helpers; +import com.google.common.collect.testing.OneSizeTestContainerGenerator; +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.Feature; +import com.google.common.collect.testing.testers.SortedSetNavigationTester; + +import junit.framework.TestSuite; +import speiger.src.testers.PACKAGE.generators.TEST_SORTED_SET_GENERATOR; +import speiger.src.testers.PACKAGE.impl.SUB_SORTED_SET_CLASS_GENERATOR; +import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPESortedSetIterationTester; +import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPESortedSetNaviationTester; +import speiger.src.testers.utils.SpecialFeature; + +@SuppressWarnings("javadoc") +public class SORTED_SET_TEST_BUILDER KEY_GENERIC_TYPE extends SET_TEST_BUILDER KEY_GENERIC_TYPE { + public static GENERIC_KEY_BRACES SORTED_SET_TEST_BUILDER KEY_GENERIC_TYPE using(TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE generator) { + return (SORTED_SET_TEST_BUILDER KEY_GENERIC_TYPE) new SORTED_SET_TEST_BUILDER KEY_GENERIC_TYPE().usingGenerator(generator); + } + + @Override + @SuppressWarnings("rawtypes") + protected List> getTesters() { + List> testers = Helpers.copyToList(super.getTesters()); + testers.add(SortedSetNavigationTester.class); + testers.add(FILE_KEY_TYPESortedSetIterationTester.class); + testers.add(FILE_KEY_TYPESortedSetNaviationTester.class); + return testers; + } + + @Override + public TestSuite createTestSuite() { + if (!getFeatures().contains(CollectionFeature.KNOWN_ORDER)) { + List> features = Helpers.copyToList(getFeatures()); +#ignore + features.add(CollectionFeature.KNOWN_ORDER); +#endignore + withFeatures(features); + } + return super.createTestSuite(); + } + + @Override + protected List createDerivedSuites( + FeatureSpecificTestSuiteBuilder, CLASS_TYPE>> parentBuilder) { + List derivedSuites = super.createDerivedSuites(parentBuilder); + +#ignore + if (!parentBuilder.getFeatures().contains(CollectionFeature.SUBSET_VIEW)) { +#endignore + derivedSuites.add(createSubsetSuite(parentBuilder, Bound.NO_BOUND, Bound.EXCLUSIVE)); + derivedSuites.add(createSubsetSuite(parentBuilder, Bound.INCLUSIVE, Bound.NO_BOUND)); + derivedSuites.add(createSubsetSuite(parentBuilder, Bound.INCLUSIVE, Bound.EXCLUSIVE)); + } + + return derivedSuites; + } + + final TestSuite createSubsetSuite( + FeatureSpecificTestSuiteBuilder, CLASS_TYPE>> parentBuilder, + Bound from, Bound to) { + TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE delegate = (TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE) parentBuilder.getSubjectGenerator().getInnerGenerator(); + + List> features = new ArrayList<>(parentBuilder.getFeatures()); +#ignore + features.remove(CollectionFeature.ALLOWS_NULL_VALUES); + features.add(CollectionFeature.SUBSET_VIEW); + features.remove(SpecialFeature.COPYING); + features.remove(SpecialFeature.CHILDREN_COPY); +#endignore + + return newBuilderUsing(delegate, to, from).named(parentBuilder.getName() + " subSet " + from + "-" + to) + .withFeatures(features).suppressing(parentBuilder.getSuppressedTests()) + .withSetUp(parentBuilder.getSetUp()).withTearDown(parentBuilder.getTearDown()).createTestSuite(); + } + + SORTED_SET_TEST_BUILDER KEY_GENERIC_TYPE newBuilderUsing(TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE delegate, Bound to, Bound from) { + return using(new SUB_SORTED_SET_CLASS_GENERATORBRACES(delegate, to, from)); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/builder/maps/MapTestSuiteBuilder.template b/src/builder/resources/speiger/assets/testers/templates/builder/maps/MapTestSuiteBuilder.template new file mode 100644 index 00000000..9d609b0f --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/builder/maps/MapTestSuiteBuilder.template @@ -0,0 +1,304 @@ +package speiger.src.testers.PACKAGE.builder.maps; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.google.common.collect.testing.AbstractTester; +import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder; +import com.google.common.collect.testing.MapTestSuiteBuilder; +import com.google.common.collect.testing.OneSizeTestContainerGenerator; +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.Feature; +import com.google.common.collect.testing.features.MapFeature; +import com.google.common.collect.testing.testers.CollectionIteratorTester; +#if VALUE_BOOLEAN +import com.google.common.collect.testing.testers.CollectionRemoveTester; +import com.google.common.collect.testing.testers.CollectionRetainAllTester; +#endif + +import junit.framework.TestSuite; +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.testers.VALUE_PACKAGE.builder.VALUE_COLLECTION_TEST_BUILDER; +import speiger.src.testers.VALUE_PACKAGE.generators.VALUE_TEST_COLLECTION_GENERATOR; +#if !TYPE_OBJECT +import speiger.src.testers.PACKAGE.builder.SET_TEST_BUILDER; +import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR; +#endif +import speiger.src.testers.PACKAGE.generators.maps.TEST_MAP_GENERATOR; +import speiger.src.testers.PACKAGE.impl.maps.DERIVED_MAP_GENERATORS; +#if TYPE_CHAR || TYPE_FLOAT || TYPE_DOUBLE +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionIteratorTester; +#if !SAME_TYPE && !VALUE_OBJECT +import speiger.src.testers.VALUE_PACKAGE.tests.collection.FILE_VALUE_TYPECollectionIteratorTester; +#endif +#else if TYPE_OBJECT && !VALUE_OBJECT +import speiger.src.testers.VALUE_PACKAGE.tests.collection.FILE_VALUE_TYPECollectionIteratorTester; +#endif +#if VALUE_PRIMITIVES +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapAddToTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSubFromTester; +#endif +#if VALUE_BOOLEAN +#if !TYPE_CHAR && !TYPE_FLOAT && !TYPE_DOUBLE && !TYPE_OBJECT +import speiger.src.testers.VALUE_PACKAGE.tests.collection.FILE_VALUE_TYPECollectionIteratorTester; +#endif +import speiger.src.testers.VALUE_PACKAGE.tests.collection.FILE_VALUE_TYPECollectionRemoveAllTester; +import speiger.src.testers.VALUE_PACKAGE.tests.collection.FILE_VALUE_TYPECollectionRetainAllTester; +#endif + +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapClearTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapCopyTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsKeyTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsValueTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapEntrySetTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapEqualsTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapForEachTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapGetOrDefaultTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapGetTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapHashCodeTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapIsEmptyTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapMergeTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapMergeBulkTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutAllArrayTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutAllTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutIfAbsentTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveEntryTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveOrDefaultTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceAllTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceEntryTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSizeTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapToStringTester; +import speiger.src.testers.objects.builder.ObjectSetTestSuiteBuilder; +import speiger.src.testers.objects.generators.TestObjectSetGenerator; +import speiger.src.testers.objects.tests.collection.ObjectCollectionIteratorTester; +import speiger.src.testers.objects.tests.collection.ObjectCollectionRemoveAllTester; +import speiger.src.testers.objects.tests.collection.ObjectCollectionRetainAllTester; +import speiger.src.testers.utils.SpecialFeature; +import speiger.src.testers.utils.TestUtils; + +@SuppressWarnings("javadoc") +public class MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MapTestSuiteBuilder { + boolean shouldBlockKeys; + + public static GENERIC_KEY_VALUE_BRACES MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE using(TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator) { + return (MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE) new MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE().usingGenerator(generator); + } + + public MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE shouldBlockKeys(boolean value) { + shouldBlockKeys = value; + return this; + } + + @Override + @SuppressWarnings("rawtypes") + protected List> getTesters() { + List> testers = new ArrayList<>(); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapClearTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapCopyTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsKeyTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsValueTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapEntrySetTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapEqualsTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapForEachTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapGetTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapGetOrDefaultTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapHashCodeTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapIsEmptyTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapMergeTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapMergeBulkTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutTester.class); +#if VALUE_PRIMITIVES + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapAddToTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapSubFromTester.class); +#endif + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutAllTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutAllArrayTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutIfAbsentTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveEntryTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveOrDefaultTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceAllTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceEntryTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapSizeTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapToStringTester.class); + return testers; + } + + @Override + protected List createDerivedSuites(FeatureSpecificTestSuiteBuilder, Map.Entry>> parentBuilder) { + List derivedSuites = new ArrayList<>(); + derivedSuites.add(createDerivedEntrySetSuite( + DERIVED_MAP_GENERATORS.entrySetGenerator(parentBuilder.getSubjectGenerator())) + .withFeatures(computeEntrySetFeatures(parentBuilder.getFeatures())) + .named(parentBuilder.getName() + " entrySet") + .suppressing(getEntrySetSuppressing(parentBuilder.getSuppressedTests())).suppressing(getSuppressing(1)) + .withSetUp(parentBuilder.getSetUp()).withTearDown(parentBuilder.getTearDown()) + .createTestSuite()); + + derivedSuites.add(createDerivedKeySetSuite( + DERIVED_MAP_GENERATORS.keySetGenerator(parentBuilder.getSubjectGenerator())) + .withFeatures(computeKeySetFeatures(parentBuilder.getFeatures())) + .named(parentBuilder.getName() + " keys").suppressing(parentBuilder.getSuppressedTests()).suppressing(getSuppressing(0)) + .withSetUp(parentBuilder.getSetUp()).withTearDown(parentBuilder.getTearDown()) + .createTestSuite()); +#if !TYPE_CHAR && !TYPE_OBJECT && !TYPE_FLOAT && !TYPE_DOUBLE || !VALUE_BOOLEAN + derivedSuites.add(createDerivedValueCollectionSuite( + new DERIVED_MAP_GENERATORS.MapValueCollectionGeneratorKV_BRACES(parentBuilder.getSubjectGenerator())) + .named(parentBuilder.getName() + " values") + .withFeatures(computeValuesCollectionFeatures(parentBuilder.getFeatures())) + .suppressing(parentBuilder.getSuppressedTests()).suppressing(getSuppressing(2)).withSetUp(parentBuilder.getSetUp()) + .withTearDown(parentBuilder.getTearDown()).createTestSuite()); +#endif + return derivedSuites; + } + + protected ObjectSetTestSuiteBuilder createDerivedEntrySetSuite(TestObjectSetGenerator entrySetGenerator) { + return ObjectSetTestSuiteBuilder.using(entrySetGenerator); + } + + protected SET_TEST_BUILDER KEY_GENERIC_TYPE createDerivedKeySetSuite(TEST_SET_GENERATOR KEY_GENERIC_TYPE generator) { + return SET_TEST_BUILDER.using(generator); + } + + protected VALUE_COLLECTION_TEST_BUILDER VALUE_GENERIC_TYPE createDerivedValueCollectionSuite(VALUE_TEST_COLLECTION_GENERATOR VALUE_GENERIC_TYPE generator) { + return VALUE_COLLECTION_TEST_BUILDER.using(generator); + } + + private Method[] getSuppressing(int type) { +#if TYPE_CHAR || TYPE_OBJECT || TYPE_FLOAT || TYPE_DOUBLE + if(shouldBlockKeys) { + switch(type) { + case 0: return TestUtils.getSurpession(FILE_KEY_TYPECollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported"); + case 1: return TestUtils.getSurpession(ObjectCollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported"); + case 2: { + List result = new ArrayList<>(); + TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported"); +#if VALUE_BOOLEAN + TestUtils.getSurpession(result, CollectionRemoveTester.class, "testRemove_present"); + TestUtils.getSurpession(result, CollectionRetainAllTester.class); + TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionIteratorTester.class, "testIterator_removeAffectsBackingCollection"); + TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionRemoveAllTester.class, "testRemoveAll_someFetchRemovedElements"); + TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionRetainAllTester.class); +#endif + return result.toArray(new Method[result.size()]); + } + } + } + return new Method[0]; +#else if VALUE_BOOLEAN + if(type == 2) { + List result = new ArrayList<>(); + TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported"); +#if VALUE_BOOLEAN + TestUtils.getSurpession(result, CollectionRemoveTester.class, "testRemove_present"); + TestUtils.getSurpession(result, CollectionRetainAllTester.class); + TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionIteratorTester.class, "testIterator_removeAffectsBackingCollection"); + TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionRemoveAllTester.class, "testRemoveAll_someFetchRemovedElements"); + TestUtils.getSurpession(result, FILE_VALUE_TYPECollectionRetainAllTester.class); +#endif + return result.toArray(new Method[result.size()]); + } + return new Method[0]; +#else + return new Method[0]; +#endif + } + + private static Set> computeEntrySetFeatures(Set> mapFeatures) { + Set> entrySetFeatures = MapTestSuiteBuilder.computeCommonDerivedCollectionFeatures(mapFeatures); +#ignore + if (mapFeatures.contains(MapFeature.ALLOWS_NULL_ENTRY_QUERIES)) { + entrySetFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES); + } + if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) { + entrySetFeatures.add(SpecialFeature.COPYING); + } + else { + entrySetFeatures.remove(SpecialFeature.COPYING); + } + if(mapFeatures.contains(SpecialFeature.MODIFIABLE)) { + entrySetFeatures.add(SpecialFeature.MODIFIABLE); + } + else { + entrySetFeatures.remove(SpecialFeature.MODIFIABLE); + } + entrySetFeatures.add(SpecialFeature.MAP_ENTRY); +#endignore + return entrySetFeatures; + } + + private static Set> computeKeySetFeatures(Set> mapFeatures) { + Set> keySetFeatures = MapTestSuiteBuilder.computeCommonDerivedCollectionFeatures(mapFeatures); +#ignore + keySetFeatures.add(CollectionFeature.SUBSET_VIEW); + if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEYS)) { + keySetFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES); + } else if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEY_QUERIES)) { + keySetFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES); + } + if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) { + keySetFeatures.add(SpecialFeature.COPYING); + } + else { + keySetFeatures.remove(SpecialFeature.COPYING); + } + if(mapFeatures.contains(SpecialFeature.MODIFIABLE)) { + keySetFeatures.add(SpecialFeature.MODIFIABLE); + } + else { + keySetFeatures.remove(SpecialFeature.MODIFIABLE); + } +#endignore + return keySetFeatures; + } + +#if !TYPE_CHAR && !TYPE_OBJECT && !TYPE_FLOAT && !TYPE_DOUBLE || !VALUE_BOOLEAN + private static Set> computeValuesCollectionFeatures(Set> mapFeatures) { + Set> valuesCollectionFeatures = MapTestSuiteBuilder.computeCommonDerivedCollectionFeatures(mapFeatures); +#ignore + if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUE_QUERIES)) { + valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES); + } + if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUES)) { + valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES); + } + if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) { + valuesCollectionFeatures.add(SpecialFeature.COPYING); + } + else { + valuesCollectionFeatures.remove(SpecialFeature.COPYING); + } +#endignore + return valuesCollectionFeatures; + } + +#endif + private static Set getEntrySetSuppressing(Set suppressing) { + TestUtils.getSurpession(suppressing, CollectionIteratorTester.class, "testIterator_removeAffectsBackingCollection"); + TestUtils.getSurpession(suppressing, ObjectCollectionIteratorTester.class, "testIterator_removeAffectsBackingCollection"); + TestUtils.getSurpession(suppressing, ObjectCollectionRemoveAllTester.class, "testRemoveAll_someFetchRemovedElements"); + TestUtils.getSurpession(suppressing, ObjectCollectionRetainAllTester.class, "testRetainAllExtra_disjointPreviouslyNonEmpty", "testRetainAllExtra_containsDuplicatesSizeSeveral", "testRetainAllExtra_subset", "testRetainAllExtra_partialOverlap"); +#if TYPE_DOUBLE || TYPE_FLOAT + TestUtils.getSurpession(suppressing, CollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported"); + TestUtils.getSurpession(suppressing, ObjectCollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported"); +#endif + return suppressing; + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/builder/maps/NavigableMapTestSuiteBuilder.template b/src/builder/resources/speiger/assets/testers/templates/builder/maps/NavigableMapTestSuiteBuilder.template new file mode 100644 index 00000000..9a759d77 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/builder/maps/NavigableMapTestSuiteBuilder.template @@ -0,0 +1,79 @@ +package speiger.src.testers.PACKAGE.builder.maps; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.google.common.collect.testing.AbstractTester; +import com.google.common.collect.testing.DerivedCollectionGenerators.Bound; +import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder; +import com.google.common.collect.testing.OneSizeTestContainerGenerator; +import com.google.common.collect.testing.features.Feature; + +import junit.framework.TestSuite; +import speiger.src.testers.PACKAGE.builder.NAVIGABLE_SET_TEST_BUILDER; +import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR; +import speiger.src.testers.PACKAGE.generators.TEST_NAVIGABLE_SET_GENERATOR; +import speiger.src.testers.PACKAGE.generators.maps.TEST_SORTED_MAP_GENERATOR; +import speiger.src.testers.PACKAGE.impl.maps.DERIVED_MAP_GENERATORS; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPENavigableMapNavigationTester; +import speiger.src.testers.utils.SpecialFeature; + +@SuppressWarnings("javadoc") +public class NAVIGABLE_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends SORTED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE +{ + public static GENERIC_KEY_VALUE_BRACES NAVIGABLE_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE using(TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator) { + return (NAVIGABLE_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE)new NAVIGABLE_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE().usingGenerator(generator); + } + + @Override + @SuppressWarnings("rawtypes") + protected List> getTesters() { + List> testers = super.getTesters(); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPENavigableMapNavigationTester.class); + return testers; + } + + @Override + protected List createDerivedSuites(FeatureSpecificTestSuiteBuilder, Map.Entry>> parentBuilder) { + List derivedSuites = super.createDerivedSuites(parentBuilder); +#ignore + if (!parentBuilder.getFeatures().contains(SpecialFeature.DESCENDING)) { + derivedSuites.add(createDescendingSuite(parentBuilder)); + } + if (!parentBuilder.getFeatures().contains(SpecialFeature.SUBMAP)) { + derivedSuites.add(createSubmapSuite(parentBuilder, Bound.NO_BOUND, Bound.INCLUSIVE)); + derivedSuites.add(createSubmapSuite(parentBuilder, Bound.EXCLUSIVE, Bound.NO_BOUND)); + derivedSuites.add(createSubmapSuite(parentBuilder, Bound.EXCLUSIVE, Bound.EXCLUSIVE)); + derivedSuites.add(createSubmapSuite(parentBuilder, Bound.EXCLUSIVE, Bound.INCLUSIVE)); + derivedSuites.add(createSubmapSuite(parentBuilder, Bound.INCLUSIVE, Bound.INCLUSIVE)); + } +#endignore + return derivedSuites; + } + + @Override + NAVIGABLE_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE newBuilderUsing(TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE delegate, Bound to, Bound from) { + return NAVIGABLE_MAP_TEST_BUILDER.using(new DERIVED_MAP_GENERATORS.NavigableMapGeneratorKV_BRACES(delegate, to, from)); + } + + private TestSuite createDescendingSuite(FeatureSpecificTestSuiteBuilder, Map.Entry>> parentBuilder) { + TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE delegate = (TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) parentBuilder.getSubjectGenerator().getInnerGenerator(); + + List> features = new ArrayList<>(); +#ignore + features.add(SpecialFeature.DESCENDING); + features.addAll(parentBuilder.getFeatures()); + features.remove(SpecialFeature.COPYING); + features.remove(SpecialFeature.CHILDREN_COPY); +#endignore + return NAVIGABLE_MAP_TEST_BUILDER.using(new DERIVED_MAP_GENERATORS.DescendingTestMapGeneratorKV_BRACES(delegate)) + .named(parentBuilder.getName() + " descending").withFeatures(features) + .suppressing(parentBuilder.getSuppressedTests()).createTestSuite(); + } + + @Override + protected NAVIGABLE_SET_TEST_BUILDER KEY_GENERIC_TYPE createDerivedKeySetSuite(TEST_SET_GENERATOR KEY_GENERIC_TYPE keySetGenerator) { + return NAVIGABLE_SET_TEST_BUILDER.using((TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE) keySetGenerator); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/builder/maps/OrderedMapTestSuiteBuilder.template b/src/builder/resources/speiger/assets/testers/templates/builder/maps/OrderedMapTestSuiteBuilder.template new file mode 100644 index 00000000..8aeb1ce9 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/builder/maps/OrderedMapTestSuiteBuilder.template @@ -0,0 +1,55 @@ +package speiger.src.testers.PACKAGE.builder.maps; + +import java.util.List; + +import com.google.common.collect.testing.AbstractTester; +import com.google.common.collect.testing.features.CollectionFeature; + +import junit.framework.TestSuite; +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.testers.PACKAGE.builder.ORDERED_SET_TEST_BUILDER; +import speiger.src.testers.PACKAGE.builder.SET_TEST_BUILDER; +import speiger.src.testers.PACKAGE.generators.TEST_ORDERED_SET_GENERATOR; +import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR; +import speiger.src.testers.PACKAGE.generators.maps.TEST_ORDERED_MAP_GENERATOR; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapMoveTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester; +#if !TYPE_OBJECT +import speiger.src.testers.objects.builder.ObjectSetTestSuiteBuilder; +import speiger.src.testers.objects.generators.TestObjectSetGenerator; +import speiger.src.testers.objects.builder.ObjectOrderedSetTestSuiteBuilder; +import speiger.src.testers.objects.generators.TestObjectOrderedSetGenerator; +#endif + +@SuppressWarnings("javadoc") +public class ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE +{ + public static GENERIC_KEY_VALUE_BRACES ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE using(TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator) { + return (ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE) new ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE().usingGenerator(generator); + } + + @Override + @SuppressWarnings("rawtypes") + protected List> getTesters() { + List> testers = super.getTesters(); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapMoveTester.class); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester.class); + return testers; + } + + @Override + public TestSuite createTestSuite() { +#ignore + withFeatures(CollectionFeature.KNOWN_ORDER); +#endignore + return super.createTestSuite(); + } + + protected ObjectSetTestSuiteBuilder createDerivedEntrySetSuite(TestObjectSetGenerator entrySetGenerator) { + return ObjectOrderedSetTestSuiteBuilder.using((TestObjectOrderedSetGenerator)entrySetGenerator); + } + + protected SET_TEST_BUILDER KEY_GENERIC_TYPE createDerivedKeySetSuite(TEST_SET_GENERATOR KEY_GENERIC_TYPE generator) { + return ORDERED_SET_TEST_BUILDER.using((TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE)generator); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/builder/maps/SortedMapTestSuiteBuilder.template b/src/builder/resources/speiger/assets/testers/templates/builder/maps/SortedMapTestSuiteBuilder.template new file mode 100644 index 00000000..83b5bf84 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/builder/maps/SortedMapTestSuiteBuilder.template @@ -0,0 +1,90 @@ +package speiger.src.testers.PACKAGE.builder.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER; +#endignore + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.google.common.collect.testing.AbstractTester; +import com.google.common.collect.testing.DerivedCollectionGenerators.Bound; +import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder; +import com.google.common.collect.testing.Helpers; +import com.google.common.collect.testing.OneSizeTestContainerGenerator; +import com.google.common.collect.testing.features.Feature; + +import junit.framework.TestSuite; +import speiger.src.testers.PACKAGE.generators.maps.TEST_SORTED_MAP_GENERATOR; +import speiger.src.testers.PACKAGE.impl.maps.DERIVED_MAP_GENERATORS; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPESortedMapNavigationTester; +import speiger.src.testers.PACKAGE.builder.SET_TEST_BUILDER; +import speiger.src.testers.PACKAGE.builder.SORTED_SET_TEST_BUILDER; +import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR; +import speiger.src.testers.PACKAGE.generators.TEST_SORTED_SET_GENERATOR; +import speiger.src.testers.utils.SpecialFeature; + +@SuppressWarnings("javadoc") +public class SORTED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE { + public static GENERIC_KEY_VALUE_BRACES SORTED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE using(TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator) { + return (SORTED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE) new SORTED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE().usingGenerator(generator); + } + + @Override + @SuppressWarnings("rawtypes") + protected List> getTesters() { + List> testers = super.getTesters(); + testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPESortedMapNavigationTester.class); + return testers; + } + + @Override + public TestSuite createTestSuite() { +#ignore + if (!getFeatures().contains(KNOWN_ORDER)) { + List> features = Helpers.copyToList(getFeatures()); + features.add(KNOWN_ORDER); + withFeatures(features); + } +#endignore + return super.createTestSuite(); + } + + @Override + protected List createDerivedSuites(FeatureSpecificTestSuiteBuilder, Map.Entry>> parentBuilder) { + List derivedSuites = super.createDerivedSuites(parentBuilder); +#ignore + if (!parentBuilder.getFeatures().contains(SpecialFeature.SUBMAP)) { + derivedSuites.add(createSubmapSuite(parentBuilder, Bound.NO_BOUND, Bound.EXCLUSIVE)); + derivedSuites.add(createSubmapSuite(parentBuilder, Bound.INCLUSIVE, Bound.NO_BOUND)); + derivedSuites.add(createSubmapSuite(parentBuilder, Bound.INCLUSIVE, Bound.EXCLUSIVE)); + } +#endignore + return derivedSuites; + } + + @Override + protected SET_TEST_BUILDER KEY_GENERIC_TYPE createDerivedKeySetSuite(TEST_SET_GENERATOR KEY_GENERIC_TYPE keySetGenerator) { + return keySetGenerator instanceof TEST_SORTED_SET_GENERATOR ? SORTED_SET_TEST_BUILDER.using((TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE) keySetGenerator) : SET_TEST_BUILDER.using(keySetGenerator); + } + + TestSuite createSubmapSuite(FeatureSpecificTestSuiteBuilder, Map.Entry>> parentBuilder, Bound from, Bound to) { + TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE delegate = (TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) parentBuilder.getSubjectGenerator().getInnerGenerator(); + List> features = new ArrayList<>(); +#ignore + features.add(SpecialFeature.SUBMAP); + features.addAll(parentBuilder.getFeatures()); + features.remove(SpecialFeature.COPYING); + features.remove(SpecialFeature.CHILDREN_COPY); +#endignore + + return newBuilderUsing(delegate, to, from).named(parentBuilder.getName() + " subMap " + from + "-" + to) + .withFeatures(features).suppressing(parentBuilder.getSuppressedTests()) + .withSetUp(parentBuilder.getSetUp()).withTearDown(parentBuilder.getTearDown()).createTestSuite(); + } + + SORTED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE newBuilderUsing(TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE delegate, Bound to, Bound from) { + return using(new DERIVED_MAP_GENERATORS.SortedMapGeneratorKV_BRACES(delegate, to, from)); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/generators/TestCollectionGenerator.template b/src/builder/resources/speiger/assets/testers/templates/generators/TestCollectionGenerator.template new file mode 100644 index 00000000..09234fe5 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/generators/TestCollectionGenerator.template @@ -0,0 +1,30 @@ +package speiger.src.testers.PACKAGE.generators; + +import java.util.List; + +import com.google.common.collect.testing.SampleElements; +import com.google.common.collect.testing.TestCollectionGenerator; + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.collections.ITERABLE; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS; + +@SuppressWarnings("javadoc") +public interface TEST_COLLECTION_GENERATOR KEY_GENERIC_TYPE extends TestCollectionGenerator +{ + public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples(); +#if !TYPE_OBJECT + public COLLECTION KEY_GENERIC_TYPE create(KEY_TYPE...elements); +#endif + public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder); + + @Override + public default SampleElements samples() {return getSamples().toSamples();} + @Override + public COLLECTION KEY_GENERIC_TYPE create(Object... elements); + @Override + public default CLASS_TYPE[] createArray(int length) { return NEW_CLASS_ARRAY(length); } + @Override + public Iterable order(List insertionOrder); +} diff --git a/src/builder/resources/speiger/assets/testers/templates/generators/TestListGenerator.template b/src/builder/resources/speiger/assets/testers/templates/generators/TestListGenerator.template new file mode 100644 index 00000000..37731ab3 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/generators/TestListGenerator.template @@ -0,0 +1,16 @@ +package speiger.src.testers.PACKAGE.generators; + +import com.google.common.collect.testing.TestListGenerator; + +import speiger.src.collections.PACKAGE.lists.LIST; + +@SuppressWarnings("javadoc") +public interface TEST_LIST_GENERATOR KEY_GENERIC_TYPE extends TestListGenerator, TEST_COLLECTION_GENERATOR KEY_GENERIC_TYPE +{ + @Override + LIST KEY_GENERIC_TYPE create(Object... elements); +#if !TYPE_OBJECT + @Override + LIST KEY_GENERIC_TYPE create(KEY_TYPE... elements); +#endif +} diff --git a/src/builder/resources/speiger/assets/testers/templates/generators/TestNavigableSetGenerator.template b/src/builder/resources/speiger/assets/testers/templates/generators/TestNavigableSetGenerator.template new file mode 100644 index 00000000..26ce02f3 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/generators/TestNavigableSetGenerator.template @@ -0,0 +1,13 @@ +package speiger.src.testers.PACKAGE.generators; + +import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET; + +@SuppressWarnings("javadoc") +public interface TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE extends TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE { +#if !TYPE_OBJECT + @Override + NAVIGABLE_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements); +#endif + @Override + NAVIGABLE_SET KEY_GENERIC_TYPE create(Object... elements); +} diff --git a/src/builder/resources/speiger/assets/testers/templates/generators/TestOrderedSetGenerator.template b/src/builder/resources/speiger/assets/testers/templates/generators/TestOrderedSetGenerator.template new file mode 100644 index 00000000..30a7c0eb --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/generators/TestOrderedSetGenerator.template @@ -0,0 +1,13 @@ +package speiger.src.testers.PACKAGE.generators; + +import speiger.src.collections.PACKAGE.sets.ORDERED_SET; + +@SuppressWarnings("javadoc") +public interface TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE extends TEST_SET_GENERATOR KEY_GENERIC_TYPE { +#if !TYPE_OBJECT + @Override + ORDERED_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements); +#endif + @Override + ORDERED_SET KEY_GENERIC_TYPE create(Object... elements); +} diff --git a/src/builder/resources/speiger/assets/testers/templates/generators/TestQueueGenerator.template b/src/builder/resources/speiger/assets/testers/templates/generators/TestQueueGenerator.template new file mode 100644 index 00000000..5aabec2b --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/generators/TestQueueGenerator.template @@ -0,0 +1,30 @@ +package speiger.src.testers.PACKAGE.generators; + +import java.util.List; + +import com.google.common.collect.testing.SampleElements; +import com.google.common.collect.testing.TestContainerGenerator; + +import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE; +import speiger.src.collections.PACKAGE.collections.ITERABLE; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS; + +@SuppressWarnings("javadoc") +public interface TEST_QUEUE_GENERATOR KEY_GENERIC_TYPE extends TestContainerGenerator +{ + public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples(); +#if !TYPE_OBJECT + public PRIORITY_QUEUE KEY_GENERIC_TYPE create(KEY_TYPE...elements); +#endif + public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder); + + @Override + public default SampleElements samples() {return getSamples().toSamples();} + @Override + public PRIORITY_QUEUE KEY_GENERIC_TYPE create(Object... elements); + @Override + public default CLASS_TYPE[] createArray(int length) { return NEW_CLASS_ARRAY(length); } + @Override + public Iterable order(List insertionOrder); +} diff --git a/src/builder/resources/speiger/assets/testers/templates/generators/TestSetGenerator.template b/src/builder/resources/speiger/assets/testers/templates/generators/TestSetGenerator.template new file mode 100644 index 00000000..5b965864 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/generators/TestSetGenerator.template @@ -0,0 +1,15 @@ +package speiger.src.testers.PACKAGE.generators; + +import com.google.common.collect.testing.TestSetGenerator; + +import speiger.src.collections.PACKAGE.sets.SET; + +@SuppressWarnings("javadoc") +public interface TEST_SET_GENERATOR KEY_GENERIC_TYPE extends TEST_COLLECTION_GENERATOR KEY_GENERIC_TYPE, TestSetGenerator { +#if !TYPE_OBJECT + @Override + SET KEY_GENERIC_TYPE create(KEY_TYPE...elements); +#endif + @Override + SET KEY_GENERIC_TYPE create(Object...elements); +} diff --git a/src/builder/resources/speiger/assets/testers/templates/generators/TestSortedSetGenerator.template b/src/builder/resources/speiger/assets/testers/templates/generators/TestSortedSetGenerator.template new file mode 100644 index 00000000..c380bee3 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/generators/TestSortedSetGenerator.template @@ -0,0 +1,38 @@ +package speiger.src.testers.PACKAGE.generators; + +import speiger.src.collections.PACKAGE.sets.SORTED_SET; + +@SuppressWarnings("javadoc") +public interface TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE extends TEST_SET_GENERATOR KEY_GENERIC_TYPE { +#if !TYPE_OBJECT + @Override + SORTED_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements); +#endif + @Override + SORTED_SET KEY_GENERIC_TYPE create(Object... elements); + + + /** + * Returns an element less than the {@link #samples()} and less than {@link + * #belowSamplesGreater()}. + */ + KEY_TYPE belowSamplesLesser(); + + /** + * Returns an element less than the {@link #samples()} but greater than {@link + * #belowSamplesLesser()}. + */ + KEY_TYPE belowSamplesGreater(); + + /** + * Returns an element greater than the {@link #samples()} but less than {@link + * #aboveSamplesGreater()}. + */ + KEY_TYPE aboveSamplesLesser(); + + /** + * Returns an element greater than the {@link #samples()} and greater than {@link + * #aboveSamplesLesser()}. + */ + KEY_TYPE aboveSamplesGreater(); +} diff --git a/src/builder/resources/speiger/assets/testers/templates/generators/maps/TestMapGenerator.template b/src/builder/resources/speiger/assets/testers/templates/generators/maps/TestMapGenerator.template new file mode 100644 index 00000000..3afe254a --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/generators/maps/TestMapGenerator.template @@ -0,0 +1,46 @@ +package speiger.src.testers.PACKAGE.generators.maps; + +import java.util.Map; + +import com.google.common.collect.testing.Helpers; +import com.google.common.collect.testing.SampleElements; +import com.google.common.collect.testing.TestMapGenerator; + +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.objects.collections.ObjectIterable; +import speiger.src.collections.objects.lists.ObjectList; +import speiger.src.testers.objects.utils.ObjectSamples; + +@SuppressWarnings("javadoc") +public interface TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE extends TestMapGenerator { + public ObjectSamples getSamples(); + public ObjectIterable order(ObjectList insertionOrder); + public MAP KEY_VALUE_GENERIC_TYPE create(MAP.Entry KEY_VALUE_GENERIC_TYPE... elements); + @Override + default MAP KEY_VALUE_GENERIC_TYPE create(Object... elements) { + MAP.Entry KEY_VALUE_GENERIC_TYPE[] result = new MAP.Entry[elements.length]; + for(int i = 0;i> samples() { + ObjectSamples samples = getSamples(); + return new SampleElements<>( + Helpers.mapEntry(samples.e0().ENTRY_KEY(), samples.e0().ENTRY_VALUE()), + Helpers.mapEntry(samples.e1().ENTRY_KEY(), samples.e1().ENTRY_VALUE()), + Helpers.mapEntry(samples.e2().ENTRY_KEY(), samples.e2().ENTRY_VALUE()), + Helpers.mapEntry(samples.e3().ENTRY_KEY(), samples.e3().ENTRY_VALUE()), + Helpers.mapEntry(samples.e4().ENTRY_KEY(), samples.e4().ENTRY_VALUE()) + ); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/generators/maps/TestOrderedMapGenerator.template b/src/builder/resources/speiger/assets/testers/templates/generators/maps/TestOrderedMapGenerator.template new file mode 100644 index 00000000..629517ff --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/generators/maps/TestOrderedMapGenerator.template @@ -0,0 +1,13 @@ +package speiger.src.testers.PACKAGE.generators.maps; + +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP; + +@SuppressWarnings("javadoc") +public interface TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE extends TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE +{ + @Override + default ORDERED_MAP KEY_VALUE_GENERIC_TYPE create(Object... elements) { return (ORDERED_MAP KEY_VALUE_GENERIC_TYPE) TEST_MAP_GENERATOR.super.create(elements); } + @Override + ORDERED_MAP KEY_VALUE_GENERIC_TYPE create(MAP.Entry KEY_VALUE_GENERIC_TYPE... elements); +} diff --git a/src/builder/resources/speiger/assets/testers/templates/generators/maps/TestSortedMapGenerator.template b/src/builder/resources/speiger/assets/testers/templates/generators/maps/TestSortedMapGenerator.template new file mode 100644 index 00000000..a757e24e --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/generators/maps/TestSortedMapGenerator.template @@ -0,0 +1,25 @@ +package speiger.src.testers.PACKAGE.generators.maps; + +import com.google.common.collect.testing.TestSortedMapGenerator; + +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.MAP.Entry; +import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP; + +@SuppressWarnings("javadoc") +public interface TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE extends TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE, TestSortedMapGenerator +{ + @Override + default SORTED_MAP KEY_VALUE_GENERIC_TYPE create(Object... elements) { return (SORTED_MAP KEY_VALUE_GENERIC_TYPE) TEST_MAP_GENERATOR.super.create(elements); } + @Override + SORTED_MAP KEY_VALUE_GENERIC_TYPE create(MAP.Entry KEY_VALUE_GENERIC_TYPE... elements); + + @Override + Entry KEY_VALUE_GENERIC_TYPE belowSamplesLesser(); + @Override + Entry KEY_VALUE_GENERIC_TYPE belowSamplesGreater(); + @Override + Entry KEY_VALUE_GENERIC_TYPE aboveSamplesLesser(); + @Override + Entry KEY_VALUE_GENERIC_TYPE aboveSamplesGreater(); +} diff --git a/src/builder/resources/speiger/assets/testers/templates/impl/CollectionConstructorTests.template b/src/builder/resources/speiger/assets/testers/templates/impl/CollectionConstructorTests.template new file mode 100644 index 00000000..8cd24c74 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/impl/CollectionConstructorTests.template @@ -0,0 +1,314 @@ +package speiger.src.testers.PACKAGE.impl; + +#if TYPE_OBJECT +import java.util.Arrays; +import java.util.Comparator; +import java.util.Objects; +#endif + +import org.junit.Ignore; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LINKED_LIST; +import speiger.src.collections.PACKAGE.lists.COPY_ON_WRITE_LIST; +import speiger.src.collections.PACKAGE.lists.IMMUTABLE_LIST; +#if !TYPE_BOOLEAN +import speiger.src.collections.PACKAGE.sets.AVL_TREE_SET; +import speiger.src.collections.PACKAGE.sets.ARRAY_SET; +import speiger.src.collections.PACKAGE.sets.LINKED_CUSTOM_HASH_SET; +import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET; +import speiger.src.collections.PACKAGE.sets.CUSTOM_HASH_SET; +import speiger.src.collections.PACKAGE.sets.HASH_SET; +import speiger.src.collections.PACKAGE.sets.RB_TREE_SET; +import speiger.src.collections.PACKAGE.sets.IMMUTABLE_HASH_SET; +import speiger.src.collections.PACKAGE.utils.STRATEGY; +#endif +#if TYPE_OBJECT +import speiger.src.collections.objects.utils.StringSortTest; +#endif +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionConstructorTester; + +@Ignore +@SuppressWarnings("javadoc") +public class COLLECTION_CONSTRUCTOR_TESTS +{ + public static class ArrayList extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE + { + @SuppressWarnings("deprecation") + public ArrayList() { + setSimpleConstructor(ARRAY_LIST::new); + setSizeConstructor(T -> new ARRAY_LISTBRACES(T)); + setPArrayConstructor(T -> new ARRAY_LISTBRACES(T)); + setPCollectionConstructor(T -> new ARRAY_LISTBRACES(T)); + setCollectionConstructor(T -> new ARRAY_LISTBRACES(T)); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } +#endif + } + + public static class LinkedList extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE + { + @SuppressWarnings("deprecation") + public LinkedList() { + setSimpleConstructor(LINKED_LIST::new); + setPArrayConstructor(T -> new LINKED_LISTBRACES(T)); + setPCollectionConstructor(T -> new LINKED_LISTBRACES(T)); + setCollectionConstructor(T -> new LINKED_LISTBRACES(T)); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } +#endif + } + + public static class CopyOnWriteArrayList extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE + { + @SuppressWarnings("deprecation") + public CopyOnWriteArrayList() { + setSimpleConstructor(COPY_ON_WRITE_LIST::new); + setPArrayConstructor(T -> new COPY_ON_WRITE_LISTBRACES(T)); + setPCollectionConstructor(T -> new COPY_ON_WRITE_LISTBRACES(T)); + setCollectionConstructor(T -> new COPY_ON_WRITE_LISTBRACES(T)); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } +#endif + } + + public static class ImmutableList extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE + { + @SuppressWarnings("deprecation") + public ImmutableList() { + setPArrayConstructor(T -> new IMMUTABLE_LISTBRACES(T)); + setPCollectionConstructor(T -> new IMMUTABLE_LISTBRACES(T)); + setCollectionConstructor(T -> new IMMUTABLE_LISTBRACES(T)); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } +#endif + } + +#if !TYPE_BOOLEAN + public static class HashSet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE + { + @SuppressWarnings("deprecation") + public HashSet() { + setSimpleConstructor(HASH_SET::new); + setSizeConstructor(T -> new HASH_SETBRACES(T)); + setPArrayConstructor(T -> new HASH_SETBRACES(T)); + setPCollectionConstructor(T -> new HASH_SETBRACES(T)); + setCollectionConstructor(T -> new HASH_SETBRACES(T)); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } +#endif + } + + public static class LinkedHashSet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE + { + @SuppressWarnings("deprecation") + public LinkedHashSet() { + setSimpleConstructor(LINKED_HASH_SET::new); + setSizeConstructor(T -> new LINKED_HASH_SETBRACES(T)); + setPArrayConstructor(T -> new LINKED_HASH_SETBRACES(T)); + setPCollectionConstructor(T -> new LINKED_HASH_SETBRACES(T)); + setCollectionConstructor(T -> new LINKED_HASH_SETBRACES(T)); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } +#endif + } + + public static class CustomHashSet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE + { + @SuppressWarnings("deprecation") + public CustomHashSet() { + setSimpleConstructor(() -> new CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(HashStrategy.INSTANCE)); + setSizeConstructor(T -> new CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE)); + setPArrayConstructor(T -> new CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE)); + setPCollectionConstructor(T -> new CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE)); + setCollectionConstructor(T -> new CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE)); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } +#endif + } + + public static class LinkedCustomHashSet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE + { + @SuppressWarnings("deprecation") + public LinkedCustomHashSet() { + setSimpleConstructor(() -> new LINKED_CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(HashStrategy.INSTANCE)); + setSizeConstructor(T -> new LINKED_CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE)); + setPArrayConstructor(T -> new LINKED_CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE)); + setPCollectionConstructor(T -> new LINKED_CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE)); + setCollectionConstructor(T -> new LINKED_CUSTOM_HASH_SET KEY_STRING_GENERIC_TYPE(T, HashStrategy.INSTANCE)); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } +#endif + } + + public static class ImmutableHashSet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE + { + @SuppressWarnings("deprecation") + public ImmutableHashSet() { + setPArrayConstructor(T -> new IMMUTABLE_HASH_SETBRACES(T)); + setPCollectionConstructor(T -> new IMMUTABLE_HASH_SETBRACES(T)); + setCollectionConstructor(T -> new IMMUTABLE_HASH_SETBRACES(T)); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } +#endif + } + + public static class ArraySet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE + { + @SuppressWarnings("deprecation") + public ArraySet() { + setSimpleConstructor(ARRAY_SET::new); + setSizeConstructor(T -> new ARRAY_SETBRACES(T)); + setPArrayConstructor(T -> new ARRAY_SETBRACES(T)); + setPCollectionConstructor(T -> new ARRAY_SETBRACES(T)); + setCollectionConstructor(T -> new ARRAY_SETBRACES(T)); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } +#endif + } + + public static class RBTreeSet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE + { + @SuppressWarnings("deprecation") + public RBTreeSet() { + setSimpleConstructor(RB_TREE_SET::new); + setPArrayConstructor(T -> new RB_TREE_SETBRACES(T)); + setPCollectionConstructor(T -> new RB_TREE_SETBRACES(T)); + setCollectionConstructor(T -> new RB_TREE_SETBRACES(T)); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } +#endif + } + + public static class AVLTreeSet extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE + { + @SuppressWarnings("deprecation") + public AVLTreeSet() { + setSimpleConstructor(AVL_TREE_SET::new); + setPArrayConstructor(T -> new AVL_TREE_SETBRACES(T)); + setPCollectionConstructor(T -> new AVL_TREE_SETBRACES(T)); + setCollectionConstructor(T -> new AVL_TREE_SETBRACES(T)); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } +#endif + } + + public static class RBTreeSetComparator extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE + { + @SuppressWarnings("deprecation") + public RBTreeSetComparator() { +#if TYPE_OBJECT + setSimpleConstructor(() -> new RB_TREE_SET(Comparator.naturalOrder())); + setPArrayConstructor(T -> new RB_TREE_SET<>(T, Comparator.naturalOrder())); + setPCollectionConstructor(T -> new RB_TREE_SET<>(T, Comparator.naturalOrder())); + setCollectionConstructor(T -> new RB_TREE_SET<>(T, Comparator.naturalOrder())); +#else + setSimpleConstructor(() -> new RB_TREE_SET(CLASS_TYPE::compare)); + setPArrayConstructor(T -> new RB_TREE_SET(T, CLASS_TYPE::compare)); + setPCollectionConstructor(T -> new RB_TREE_SET(T, CLASS_TYPE::compare)); + setCollectionConstructor(T -> new RB_TREE_SET(T, CLASS_TYPE::compare)); +#endif + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } +#endif + } + + public static class AVLTreeSetComparator extends FILE_KEY_TYPECollectionConstructorTester KEY_STRING_GENERIC_TYPE + { + @SuppressWarnings("deprecation") + public AVLTreeSetComparator() { +#if TYPE_OBJECT + setSimpleConstructor(() -> new AVL_TREE_SET(Comparator.naturalOrder())); + setPArrayConstructor(T -> new AVL_TREE_SET<>(T, Comparator.naturalOrder())); + setPCollectionConstructor(T -> new AVL_TREE_SET<>(T, Comparator.naturalOrder())); + setCollectionConstructor(T -> new AVL_TREE_SET<>(T, Comparator.naturalOrder())); +#else + setSimpleConstructor(() -> new AVL_TREE_SET(CLASS_TYPE::compare)); + setPArrayConstructor(T -> new AVL_TREE_SET(T, CLASS_TYPE::compare)); + setPCollectionConstructor(T -> new AVL_TREE_SET(T, CLASS_TYPE::compare)); + setCollectionConstructor(T -> new AVL_TREE_SET(T, CLASS_TYPE::compare)); +#endif + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } +#endif + } + + private static class HashStrategy implements STRATEGY KEY_STRING_GENERIC_TYPE { + static final HashStrategy INSTANCE = new HashStrategy(); + @Override + public int hashCode(KEY_STRING_TYPE o) { return KEY_TO_HASH(o); } + @Override + public boolean equals(KEY_STRING_TYPE key, KEY_STRING_TYPE value) { return KEY_EQUALS(key, value); } + } +#endif +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/impl/SimpleQueueTestGenerator.template b/src/builder/resources/speiger/assets/testers/templates/impl/SimpleQueueTestGenerator.template new file mode 100644 index 00000000..eb3abd2d --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/impl/SimpleQueueTestGenerator.template @@ -0,0 +1,82 @@ +package speiger.src.testers.PACKAGE.impl; + +import java.util.List; +import java.util.function.Function; + +import speiger.src.collections.PACKAGE.collections.ITERABLE; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE; +#if TYPE_OBJECT +import speiger.src.collections.objects.utils.ObjectArrays; +#endif +import speiger.src.testers.PACKAGE.generators.TEST_QUEUE_GENERATOR; +import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS; + +@SuppressWarnings("javadoc") +public class SIMPLE_QUEUE_TEST_GENERATOR KEY_GENERIC_TYPE implements TEST_QUEUE_GENERATOR KEY_GENERIC_TYPE +{ + Function mapper; +#if TYPE_OBJECT + KEY_TYPE[] keys; +#endif + + public SIMPLE_QUEUE_TEST_GENERATOR(Function mapper) { + this.mapper = mapper; + } + +#if TYPE_OBJECT + public SIMPLE_QUEUE_TEST_GENERATOR KEY_GENERIC_TYPE setElements(KEY_TYPE...keys) { + this.keys = keys; + return this; + } + +#endif + public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() { +#if TYPE_BOOLEAN + return new SAMPLE_ELEMENTS(true, false, true, false, true); +#else if TYPE_BYTE + return new SAMPLE_ELEMENTS((byte)0, (byte)1, (byte)2, (byte)3, (byte)4); +#else if TYPE_SHORT + return new SAMPLE_ELEMENTS((short)0, (short)1, (short)2, (short)3, (short)4); +#else if TYPE_CHAR + return new SAMPLE_ELEMENTS((char)0, (char)1, (char)2, (char)3, (char)4); +#else if TYPE_OBJECT + return new SAMPLE_ELEMENTSBRACES(keys[0], keys[1], keys[2], keys[3], keys[4]); +#else + return new SAMPLE_ELEMENTS(0, 1, 2, 3, 4); +#endif + } + +#if !TYPE_OBJECT + public PRIORITY_QUEUE KEY_GENERIC_TYPE create(KEY_TYPE... elements) { + return mapper.apply(elements); + } + + public PRIORITY_QUEUE KEY_GENERIC_TYPE create(Object... elements) { + KEY_TYPE[] array = NEW_KEY_ARRAY(elements.length); + int i = 0; + for (Object e : elements) { + array[i++] = CLASS_TO_KEY(e); + } + return mapper.apply(array); + } + +#else + public PRIORITY_QUEUE KEY_GENERIC_TYPE create(Object... elements) { + T[] array = (T[])ObjectArrays.newArray(keys[0].getClass(), elements.length); + int i = 0; + for (Object e : elements) { + array[i++] = CLASS_TO_KEY(e); + } + return mapper.apply(array); + } + +#endif + public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) { + return insertionOrder; + } + + public Iterable order(List insertionOrder) { + return insertionOrder; + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/impl/SimpleTestGenerator.template b/src/builder/resources/speiger/assets/testers/templates/impl/SimpleTestGenerator.template new file mode 100644 index 00000000..92c2c398 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/impl/SimpleTestGenerator.template @@ -0,0 +1,221 @@ +package speiger.src.testers.PACKAGE.impl; + +import java.util.List; +import java.util.function.Function; + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.collections.ITERABLE; +import speiger.src.collections.PACKAGE.lists.LIST; +#if !TYPE_BOOLEAN +import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET; +import speiger.src.collections.PACKAGE.sets.ORDERED_SET; +import speiger.src.collections.PACKAGE.sets.SET; +import speiger.src.collections.PACKAGE.sets.SORTED_SET; +#if TYPE_OBJECT +import speiger.src.collections.objects.utils.ObjectArrays; +#endif +#endif +import speiger.src.testers.PACKAGE.generators.TEST_COLLECTION_GENERATOR; +import speiger.src.testers.PACKAGE.generators.TEST_LIST_GENERATOR; +#if !TYPE_BOOLEAN +import speiger.src.testers.PACKAGE.generators.TEST_NAVIGABLE_SET_GENERATOR; +import speiger.src.testers.PACKAGE.generators.TEST_ORDERED_SET_GENERATOR; +import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR; +import speiger.src.testers.PACKAGE.generators.TEST_SORTED_SET_GENERATOR; +#endif +import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS; + +@SuppressWarnings("javadoc") +public class SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE { + Function mapper; +#if TYPE_OBJECT + KEY_TYPE[] keys; +#endif + + public SIMPLE_TEST_GENERATOR(Function mapper) { + this.mapper = mapper; + } + +#if TYPE_OBJECT + public SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE setElements(KEY_TYPE...keys) { + this.keys = keys; + return this; + } + +#endif + public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() { +#if TYPE_BOOLEAN + return new SAMPLE_ELEMENTS(true, false, true, false, true); +#else if TYPE_BYTE + return new SAMPLE_ELEMENTS((byte)0, (byte)1, (byte)2, (byte)3, (byte)4); +#else if TYPE_SHORT + return new SAMPLE_ELEMENTS((short)0, (short)1, (short)2, (short)3, (short)4); +#else if TYPE_CHAR + return new SAMPLE_ELEMENTS((char)0, (char)1, (char)2, (char)3, (char)4); +#else if TYPE_OBJECT + return new SAMPLE_ELEMENTSBRACES(keys[0], keys[1], keys[2], keys[3], keys[4]); +#else + return new SAMPLE_ELEMENTS(0, 1, 2, 3, 4); +#endif + } + +#if !TYPE_OBJECT + public E create(KEY_TYPE... elements) { + return mapper.apply(elements); + } + + public E create(Object... elements) { + KEY_TYPE[] array = NEW_KEY_ARRAY(elements.length); + int i = 0; + for (Object e : elements) { + array[i++] = CLASS_TO_KEY(e); + } + return mapper.apply(array); + } + +#else + public E create(Object... elements) { + T[] array = (T[])ObjectArrays.newArray(keys[0].getClass(), elements.length); + int i = 0; + for (Object e : elements) { + array[i++] = CLASS_TO_KEY(e); + } + return mapper.apply(array); + } + +#endif + public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) { + return insertionOrder; + } + + public Iterable order(List insertionOrder) { + return insertionOrder; + } + + public static class Collections KEY_GENERIC_TYPE extends SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE implements TEST_COLLECTION_GENERATOR KEY_GENERIC_TYPE + { + public Collections(Function mapper) { + super(mapper); + } + } + + public static class Lists KEY_GENERIC_TYPE extends SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE implements TEST_LIST_GENERATOR KEY_GENERIC_TYPE + { + public Lists(Function mapper) { + super(mapper); + } + } + +#if !TYPE_BOOLEAN + public static class Sets KEY_GENERIC_TYPE extends SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE implements TEST_SET_GENERATOR KEY_GENERIC_TYPE + { + public Sets(Function mapper) { + super(mapper); + } + } + + public static class OrderedSets KEY_GENERIC_TYPE extends SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE implements TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE + { + public OrderedSets(Function mapper) { + super(mapper); + } + } + + public static class SortedSets KEY_GENERIC_TYPE extends SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE implements TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE + { + public SortedSets(Function mapper) { + super(mapper); + } + + @Override + public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) { + insertionOrder.sort(null); + return insertionOrder; + } + + @Override + public Iterable order(List insertionOrder) { + insertionOrder.sort(null); + return insertionOrder; + } + +#if TYPE_CHAR + @Override + public KEY_TYPE belowSamplesLesser() { return '_'; } + @Override + public KEY_TYPE belowSamplesGreater() { return '`'; } + @Override + public KEY_TYPE aboveSamplesLesser() { return 'f'; } + @Override + public KEY_TYPE aboveSamplesGreater() { return 'g'; } +#else if TYPE_OBJECT + @Override + public KEY_TYPE belowSamplesLesser() { return keys[5]; } + @Override + public KEY_TYPE belowSamplesGreater() { return keys[6]; } + @Override + public KEY_TYPE aboveSamplesLesser() { return keys[7]; } + @Override + public KEY_TYPE aboveSamplesGreater() { return keys[8]; } +#else + @Override + public KEY_TYPE belowSamplesLesser() { return -2; } + @Override + public KEY_TYPE belowSamplesGreater() { return -1; } + @Override + public KEY_TYPE aboveSamplesLesser() { return 5; } + @Override + public KEY_TYPE aboveSamplesGreater() { return 6; } +#endif + } + + public static class NavigableSets KEY_GENERIC_TYPE extends SIMPLE_TEST_GENERATOR KKS_GENERIC_TYPE implements TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE + { + public NavigableSets(Function mapper) { + super(mapper); + } + + @Override + public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) { + insertionOrder.sort(null); + return insertionOrder; + } + + @Override + public Iterable order(List insertionOrder) { + insertionOrder.sort(null); + return insertionOrder; + } + +#if TYPE_CHAR + public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() { return new SAMPLE_ELEMENTS('a', 'b', 'c', 'd', 'e'); } + @Override + public KEY_TYPE belowSamplesLesser() { return '_'; } + @Override + public KEY_TYPE belowSamplesGreater() { return '`'; } + @Override + public KEY_TYPE aboveSamplesLesser() { return 'f'; } + @Override + public KEY_TYPE aboveSamplesGreater() { return 'g'; } +#else if TYPE_OBJECT + @Override + public KEY_TYPE belowSamplesLesser() { return keys[5]; } + @Override + public KEY_TYPE belowSamplesGreater() { return keys[6]; } + @Override + public KEY_TYPE aboveSamplesLesser() { return keys[7]; } + @Override + public KEY_TYPE aboveSamplesGreater() { return keys[8]; } +#else + @Override + public KEY_TYPE belowSamplesLesser() { return -2; } + @Override + public KEY_TYPE belowSamplesGreater() { return -1; } + @Override + public KEY_TYPE aboveSamplesLesser() { return 5; } + @Override + public KEY_TYPE aboveSamplesGreater() { return 6; } +#endif + } +#endif +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/impl/SortedSetSubsetTestSetGenerator.template b/src/builder/resources/speiger/assets/testers/templates/impl/SortedSetSubsetTestSetGenerator.template new file mode 100644 index 00000000..806e6106 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/impl/SortedSetSubsetTestSetGenerator.template @@ -0,0 +1,173 @@ +package speiger.src.testers.PACKAGE.impl; + +#if TYPE_OBJECT +import java.util.Comparator; +#endif +import java.util.List; + +import com.google.common.collect.testing.DerivedCollectionGenerators.Bound; + +import speiger.src.collections.PACKAGE.collections.ITERABLE; +#if !TYPE_OBJECT +import speiger.src.collections.PACKAGE.functions.COMPARATOR; +#endif +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET; +import speiger.src.collections.PACKAGE.sets.SORTED_SET; +import speiger.src.testers.PACKAGE.generators.TEST_SORTED_SET_GENERATOR; +import speiger.src.testers.PACKAGE.generators.TEST_NAVIGABLE_SET_GENERATOR; +import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS; + +@SuppressWarnings("javadoc") +public class SUB_SORTED_SET_CLASS_GENERATOR KEY_GENERIC_TYPE implements TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE +{ + final Bound to; + final Bound from; + final KEY_TYPE firstInclusive; + final KEY_TYPE lastInclusive; + private final COMPARATOR KEY_GENERIC_TYPE comparator; + private final TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE delegate; + + public SUB_SORTED_SET_CLASS_GENERATOR(TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE delegate, Bound to, Bound from) { + this.to = to; + this.from = from; + this.delegate = delegate; + + SORTED_SET KEY_GENERIC_TYPE emptySet = delegate.create(NEW_KEY_ARRAY(0)); + comparator = emptySet.comparator(); + + SAMPLE_ELEMENTS KEY_GENERIC_TYPE samples = delegate.getSamples(); + LIST KEY_GENERIC_TYPE samplesList = new ARRAY_LISTBRACES(samples.asList()); + samplesList.sort(comparator); + firstInclusive = samplesList.GET_KEY(0); + lastInclusive = samplesList.GET_KEY(samplesList.size() - 1); + } + + public final TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE getInnerGenerator() { + return delegate; + } + + public final Bound getTo() { + return to; + } + + public final Bound getFrom() { + return from; + } + + SORTED_SET KEY_GENERIC_TYPE createSubSet(SORTED_SET KEY_GENERIC_TYPE set, KEY_TYPE firstExclusive, KEY_TYPE lastExclusive) { + if (from == Bound.NO_BOUND && to == Bound.EXCLUSIVE) { + return set.headSet(lastExclusive); + } else if (from == Bound.INCLUSIVE && to == Bound.NO_BOUND) { + return set.tailSet(firstInclusive); + } else if (from == Bound.INCLUSIVE && to == Bound.EXCLUSIVE) { + return set.subSet(firstInclusive, lastExclusive); + } else { + throw new IllegalArgumentException(); + } + } + + @Override + public KEY_TYPE belowSamplesLesser() { + throw new UnsupportedOperationException(); + } + + @Override + public KEY_TYPE belowSamplesGreater() { + throw new UnsupportedOperationException(); + } + + @Override + public KEY_TYPE aboveSamplesLesser() { + throw new UnsupportedOperationException(); + } + + @Override + public KEY_TYPE aboveSamplesGreater() { + throw new UnsupportedOperationException(); + } + + @Override + public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() { + return delegate.getSamples(); + } + + @Override + public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) { + return delegate.order(insertionOrder); + } + + @Override + public Iterable order(List insertionOrder) { + return delegate.order(insertionOrder); + } + + @Override + public SORTED_SET KEY_GENERIC_TYPE create(KEY_OBJECT_TYPE... elements) { +#if TYPE_OBJECT + LIST KEY_GENERIC_TYPE normalValues = (LIST KEY_GENERIC_TYPE)ARRAY_LIST.wrap(elements); +#else + LIST KEY_GENERIC_TYPE normalValues = ARRAY_LIST.wrap(elements); +#endif + LIST KEY_GENERIC_TYPE extremeValues = new ARRAY_LISTBRACES(); + KEY_TYPE firstExclusive = delegate.belowSamplesGreater(); + KEY_TYPE lastExclusive = delegate.aboveSamplesLesser(); + if (from != Bound.NO_BOUND) { + extremeValues.add(delegate.belowSamplesLesser()); + extremeValues.add(delegate.belowSamplesGreater()); + } + if (to != Bound.NO_BOUND) { + extremeValues.add(delegate.aboveSamplesLesser()); + extremeValues.add(delegate.aboveSamplesGreater()); + } + LIST KEY_GENERIC_TYPE allEntries = new ARRAY_LISTBRACES(); + allEntries.addAll(extremeValues); + allEntries.addAll(normalValues); + SORTED_SET KEY_GENERIC_TYPE set = delegate.create(allEntries.toArray()); + + return createSubSet(set, firstExclusive, lastExclusive); + } + +#if !TYPE_OBJECT + @Override + public SORTED_SET KEY_GENERIC_TYPE create(Object... elements) { + KEY_TYPE[] array = NEW_KEY_ARRAY(elements.length); + int i = 0; + for (Object e : elements) { + array[i++] = CLASS_TO_KEY(e); + } + return create(array); + } + +#endif + public static final class SUB_NAVIGABLE_SET_CLASS_GENERATOR KEY_GENERIC_TYPE extends SUB_SORTED_SET_CLASS_GENERATOR KEY_GENERIC_TYPE implements TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE { + public SUB_NAVIGABLE_SET_CLASS_GENERATOR(TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE delegate, Bound to, Bound from) { + super(delegate, to, from); + } + +#if !TYPE_OBJECT + @Override + public NAVIGABLE_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements) { + return (NAVIGABLE_SET KEY_GENERIC_TYPE)super.create(elements); + } + +#endif + @Override + public NAVIGABLE_SET KEY_GENERIC_TYPE create(Object... elements) { + return (NAVIGABLE_SET KEY_GENERIC_TYPE)super.create(elements); + } + + @Override + NAVIGABLE_SET KEY_GENERIC_TYPE createSubSet(SORTED_SET KEY_GENERIC_TYPE sortedSet, KEY_TYPE firstExclusive, KEY_TYPE lastExclusive) { + NAVIGABLE_SET KEY_GENERIC_TYPE set = (NAVIGABLE_SET KEY_GENERIC_TYPE) sortedSet; + if (from == Bound.NO_BOUND && to == Bound.INCLUSIVE) return set.headSet(lastInclusive, true); + else if (from == Bound.EXCLUSIVE && to == Bound.NO_BOUND) return set.tailSet(firstExclusive, false); + else if (from == Bound.EXCLUSIVE && to == Bound.EXCLUSIVE) return set.subSet(firstExclusive, false, lastExclusive, false); + else if (from == Bound.EXCLUSIVE && to == Bound.INCLUSIVE) return set.subSet(firstExclusive, false, lastInclusive, true); + else if (from == Bound.INCLUSIVE && to == Bound.INCLUSIVE) return set.subSet(firstInclusive, true, lastInclusive, true); + return (NAVIGABLE_SET KEY_GENERIC_TYPE)super.createSubSet(set, firstExclusive, lastExclusive); + + } + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/impl/maps/DerivedMapGenerators.template b/src/builder/resources/speiger/assets/testers/templates/impl/maps/DerivedMapGenerators.template new file mode 100644 index 00000000..7b7b4235 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/impl/maps/DerivedMapGenerators.template @@ -0,0 +1,550 @@ +package speiger.src.testers.PACKAGE.impl.maps; + +import java.util.Comparator; +import java.util.List; +import java.util.Map; +#if VALUE_OBJECT +import java.util.Objects; +#endif + +import com.google.common.collect.testing.DerivedCollectionGenerators.Bound; +import com.google.common.collect.testing.OneSizeTestContainerGenerator; + +#if !TYPE_OBJECT +import speiger.src.collections.PACKAGE.functions.COMPARATOR; +import speiger.src.collections.PACKAGE.collections.ITERABLE; +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +#endif +import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.MAP.Entry; +import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP; +#if !TYPE_OBJECT +import speiger.src.collections.PACKAGE.sets.SET; +import speiger.src.collections.PACKAGE.sets.ORDERED_SET; +#endif +import speiger.src.collections.PACKAGE.sets.SORTED_SET; +import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET; +#if !TYPE_OBJECT +import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR; +#endif +import speiger.src.testers.PACKAGE.generators.TEST_ORDERED_SET_GENERATOR; +import speiger.src.testers.PACKAGE.generators.TEST_SORTED_SET_GENERATOR; +import speiger.src.testers.PACKAGE.generators.TEST_NAVIGABLE_SET_GENERATOR; +import speiger.src.testers.PACKAGE.generators.maps.TEST_MAP_GENERATOR; +import speiger.src.testers.PACKAGE.generators.maps.TEST_SORTED_MAP_GENERATOR; +import speiger.src.testers.PACKAGE.generators.maps.TEST_ORDERED_MAP_GENERATOR; +#if !TYPE_OBJECT +import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS; +#endif +import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION; +#if !VALUE_OBJECT && !SAME_TYPE +import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERABLE; +import speiger.src.collections.VALUE_PACKAGE.lists.VALUE_LIST; +import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_COMPARATOR; +#endif +import speiger.src.testers.VALUE_PACKAGE.generators.VALUE_TEST_COLLECTION_GENERATOR; +#if !VALUE_OBJECT && !SAME_TYPE +import speiger.src.testers.VALUE_PACKAGE.utils.VALUE_SAMPLE_ELEMENTS; +#endif +import speiger.src.collections.objects.collections.ObjectIterable; +import speiger.src.collections.objects.lists.ObjectArrayList; +import speiger.src.collections.objects.lists.ObjectList; +import speiger.src.collections.objects.sets.ObjectSet; +import speiger.src.collections.objects.sets.ObjectOrderedSet; +import speiger.src.collections.objects.utils.ObjectIterators; +import speiger.src.collections.objects.utils.ObjectLists; +import speiger.src.testers.objects.generators.TestObjectSetGenerator; +#if !TYPE_OBJECT +import speiger.src.testers.objects.generators.TestObjectOrderedSetGenerator; +#endif +import speiger.src.testers.objects.utils.ObjectSamples; + +@SuppressWarnings("javadoc") +public class DERIVED_MAP_GENERATORS { + public static class NavigableMapGenerator KEY_VALUE_GENERIC_TYPE extends SortedMapGenerator KEY_VALUE_GENERIC_TYPE { + public NavigableMapGenerator(TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent, Bound to, Bound from) { + super(parent, to, from); + } + + @Override + NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE createSubMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE sortedMap, KEY_TYPE firstExclusive, KEY_TYPE lastExclusive) { + NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE map = (NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE) sortedMap; + if (from == Bound.NO_BOUND && to == Bound.INCLUSIVE) { + return map.headMap(lastInclusive, true); + } else if (from == Bound.EXCLUSIVE && to == Bound.NO_BOUND) { + return map.tailMap(firstExclusive, false); + } else if (from == Bound.EXCLUSIVE && to == Bound.EXCLUSIVE) { + return map.subMap(firstExclusive, false, lastExclusive, false); + } else if (from == Bound.EXCLUSIVE && to == Bound.INCLUSIVE) { + return map.subMap(firstExclusive, false, lastInclusive, true); + } else if (from == Bound.INCLUSIVE && to == Bound.INCLUSIVE) { + return map.subMap(firstInclusive, true, lastInclusive, true); + } else { + return (NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE) super.createSubMap(map, firstExclusive, lastExclusive); + } + } + } + + public static class SortedMapGenerator KEY_VALUE_GENERIC_TYPE extends MapGenerator KEY_VALUE_GENERIC_TYPE implements TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE { + TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent; + Bound to; + Bound from; + KEY_TYPE firstInclusive; + KEY_TYPE lastInclusive; + Comparator entryComparator; + + public SortedMapGenerator(TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent, Bound to, Bound from) { + super(parent); + this.parent = parent; + this.to = to; + this.from = from; + SORTED_MAP KEY_VALUE_GENERIC_TYPE map = parent.create(); + entryComparator = DERIVED_MAP_GENERATORS.entryComparator(map.comparator()); + ObjectList samples = parent.getSamples().asList(); + samples.sort(entryComparator); + firstInclusive = samples.get(0).ENTRY_KEY(); + lastInclusive = samples.get(samples.size() - 1).ENTRY_KEY(); + } + + @Override + public SORTED_MAP KEY_VALUE_GENERIC_TYPE create(Entry KEY_VALUE_GENERIC_TYPE... elements) { + ObjectList entries = new ObjectArrayList<>(); + if (from != Bound.NO_BOUND) { + entries.add(parent.belowSamplesLesser()); + entries.add(parent.belowSamplesGreater()); + } + if (to != Bound.NO_BOUND) { + entries.add(parent.aboveSamplesLesser()); + entries.add(parent.aboveSamplesGreater()); + } + entries.addAll(elements); + return createSubMap(parent.create(entries.toArray(Entry[]::new)), parent.belowSamplesGreater().ENTRY_KEY(), parent.aboveSamplesLesser().ENTRY_KEY()); + } + + SORTED_MAP KEY_VALUE_GENERIC_TYPE createSubMap(SORTED_MAP KEY_VALUE_GENERIC_TYPE map, KEY_TYPE firstExclusive, KEY_TYPE lastExclusive) { + if (from == Bound.NO_BOUND && to == Bound.EXCLUSIVE) { + return map.headMap(lastExclusive); + } else if (from == Bound.INCLUSIVE && to == Bound.NO_BOUND) { + return map.tailMap(firstInclusive); + } else if (from == Bound.INCLUSIVE && to == Bound.EXCLUSIVE) { + return map.subMap(firstInclusive, lastExclusive); + } else { + throw new IllegalArgumentException(); + } + } + + @Override + public Entry KEY_VALUE_GENERIC_TYPE belowSamplesLesser() { + throw new UnsupportedOperationException(); + } + + @Override + public Entry KEY_VALUE_GENERIC_TYPE belowSamplesGreater() { + throw new UnsupportedOperationException(); + } + + @Override + public Entry KEY_VALUE_GENERIC_TYPE aboveSamplesLesser() { + throw new UnsupportedOperationException(); + } + + @Override + public Entry KEY_VALUE_GENERIC_TYPE aboveSamplesGreater() { + throw new UnsupportedOperationException(); + } + } + + public static class DescendingTestMapGenerator KEY_VALUE_GENERIC_TYPE extends MapGenerator KEY_VALUE_GENERIC_TYPE implements TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE + { + TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent; + + public DescendingTestMapGenerator(TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent) { + super(parent); + this.parent = parent; + } + + @Override + public NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE create(Entry KEY_VALUE_GENERIC_TYPE... elements) { + return ((NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE)parent.create(elements)).descendingMap(); + } + + @Override + public Iterable> order(List> insertionOrder) { + ObjectList> values = ObjectIterators.pour(ObjectIterators.wrap(parent.order(insertionOrder).iterator())); + ObjectLists.reverse(values); + return values; + } + + @Override + public ObjectIterable order(ObjectList insertionOrder) { + ObjectList values = parent.order(insertionOrder).pourAsList(); + ObjectLists.reverse(values); + return values; + } + + @Override + public Entry KEY_VALUE_GENERIC_TYPE belowSamplesLesser() { + return parent.aboveSamplesGreater(); + } + + @Override + public Entry KEY_VALUE_GENERIC_TYPE belowSamplesGreater() { + return parent.aboveSamplesLesser(); + } + + @Override + public Entry KEY_VALUE_GENERIC_TYPE aboveSamplesLesser() { + return parent.belowSamplesGreater(); + } + + @Override + public Entry KEY_VALUE_GENERIC_TYPE aboveSamplesGreater() { + return parent.belowSamplesLesser(); + } + } + + public static class MapGenerator KEY_VALUE_GENERIC_TYPE implements TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE + { + TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent; + + public MapGenerator(TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent) { + this.parent = parent; + } + + @Override + public Iterable> order(List> insertionOrder) { + return parent.order(insertionOrder); + } + + @Override + public ObjectSamples getSamples() { + return parent.getSamples(); + } + + @Override + public ObjectIterable order(ObjectList insertionOrder) { + return parent.order(insertionOrder); + } + + @Override + public MAP KEY_VALUE_GENERIC_TYPE create(Entry KEY_VALUE_GENERIC_TYPE... elements) { + return parent.create(elements); + } + } + + public static GENERIC_KEY_VALUE_BRACES TestObjectSetGenerator entrySetGenerator(OneSizeTestContainerGenerator, Map.Entry> inner) { + if(inner.getInnerGenerator() instanceof TEST_ORDERED_MAP_GENERATOR) { + ObjectSet set = ((TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) inner.getInnerGenerator()).create().ENTRY_SET(); + if(set instanceof ObjectOrderedSet) return new OrderedMapEntrySetGeneratorKV_BRACES(inner); + } + return new MapEntrySetGeneratorKV_BRACES(inner); + } + + public static class OrderedMapEntrySetGenerator KEY_VALUE_GENERIC_TYPE extends MapEntrySetGenerator KEY_VALUE_GENERIC_TYPE implements TestObjectOrderedSetGenerator { + + public OrderedMapEntrySetGenerator(OneSizeTestContainerGenerator, Map.Entry> inner) { + super(inner); + } + + public ObjectOrderedSet create(Object... elements) { + return (ObjectOrderedSet)super.create(elements); + } + } + + public static class MapEntrySetGenerator KEY_VALUE_GENERIC_TYPE implements TestObjectSetGenerator { + TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator; + + public MapEntrySetGenerator(OneSizeTestContainerGenerator, Map.Entry> inner) { + generator = (TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) inner.getInnerGenerator(); + } + + @Override + public ObjectSamples getSamples() { + return generator.getSamples(); + } + + @Override + public ObjectIterable order(ObjectList insertionOrder) { + return generator.order(insertionOrder); + } + + @Override + public Iterable order(List insertionOrder) { + return generator.order(new ObjectArrayList(insertionOrder)); + } + + @Override + public Entry KEY_VALUE_GENERIC_TYPE[] createArray(int length) { + return new Entry[length]; + } + + @Override + public ObjectSet create(Object... elements) { + return generator.create(elements).ENTRY_SET(); + } + } + + public static GENERIC_KEY_VALUE_BRACES TEST_SET_GENERATOR KEY_GENERIC_TYPE keySetGenerator(OneSizeTestContainerGenerator, Map.Entry> inner) { + if (inner.getInnerGenerator() instanceof TEST_SORTED_MAP_GENERATOR) { + SET KEY_GENERIC_TYPE set = ((TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) inner.getInnerGenerator()).create().keySet(); + if(set instanceof NAVIGABLE_SET) return new MapNavigableKeySetGeneratorKV_BRACES(inner); + if(set instanceof SORTED_SET) return new MapSortedKeySetGeneratorKV_BRACES(inner); + } + if(inner.getInnerGenerator() instanceof TEST_ORDERED_MAP_GENERATOR) { + SET KEY_GENERIC_TYPE set = ((TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) inner.getInnerGenerator()).create().keySet(); + if(set instanceof ORDERED_SET) return new MapOrderedKeySetGeneratorKV_BRACES(inner); + } + return new MapKeySetGeneratorKV_BRACES(inner); + } + + public static class MapNavigableKeySetGenerator KEY_VALUE_GENERIC_TYPE extends MapSortedKeySetGenerator KEY_VALUE_GENERIC_TYPE implements TEST_NAVIGABLE_SET_GENERATOR KEY_GENERIC_TYPE { + public MapNavigableKeySetGenerator(OneSizeTestContainerGenerator, Map.Entry> inner) { + super(inner); + } + +#if !TYPE_OBJECT + @Override + public NAVIGABLE_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements) { + return (NAVIGABLE_SET KEY_GENERIC_TYPE) super.create(elements); + } + +#endif + @Override + public NAVIGABLE_SET KEY_GENERIC_TYPE create(Object... elements) { + return (NAVIGABLE_SET KEY_GENERIC_TYPE) super.create(elements); + } + } + + public static class MapSortedKeySetGenerator KEY_VALUE_GENERIC_TYPE extends MapKeySetGenerator KEY_VALUE_GENERIC_TYPE implements TEST_SORTED_SET_GENERATOR KEY_GENERIC_TYPE { + TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator; + + public MapSortedKeySetGenerator(OneSizeTestContainerGenerator, Map.Entry> inner) { + super(inner); + generator = (TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) inner.getInnerGenerator(); + } + +#if !TYPE_OBJECT + @Override + public SORTED_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements) { + return (SORTED_SET KEY_GENERIC_TYPE) super.create(elements); + } + +#endif + @Override + public SORTED_SET KEY_GENERIC_TYPE create(Object... elements) { + return (SORTED_SET KEY_GENERIC_TYPE) super.create(elements); + } + + @Override + public KEY_TYPE belowSamplesLesser() { + return generator.belowSamplesLesser().ENTRY_KEY(); + } + + @Override + public KEY_TYPE belowSamplesGreater() { + return generator.belowSamplesGreater().ENTRY_KEY(); + } + + @Override + public KEY_TYPE aboveSamplesLesser() { + return generator.aboveSamplesLesser().ENTRY_KEY(); + } + + @Override + public KEY_TYPE aboveSamplesGreater() { + return generator.aboveSamplesGreater().ENTRY_KEY(); + } + } + + public static class MapOrderedKeySetGenerator KEY_VALUE_GENERIC_TYPE extends MapKeySetGenerator KEY_VALUE_GENERIC_TYPE implements TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE { + + public MapOrderedKeySetGenerator(OneSizeTestContainerGenerator, Map.Entry> inner) { + super(inner); + } + +#if !TYPE_OBJECT + @Override + public ORDERED_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements) { + return (ORDERED_SET KEY_GENERIC_TYPE) super.create(elements); + } + +#endif + @Override + public ORDERED_SET KEY_GENERIC_TYPE create(Object... elements) { + return (ORDERED_SET KEY_GENERIC_TYPE) super.create(elements); + } + } + + public static class MapKeySetGenerator KEY_VALUE_GENERIC_TYPE implements TEST_SET_GENERATOR KEY_GENERIC_TYPE { + TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator; + SAMPLE_ELEMENTS KEY_GENERIC_TYPE samples; + + public MapKeySetGenerator(OneSizeTestContainerGenerator, Map.Entry> inner) { + generator = (TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) inner.getInnerGenerator(); + ObjectSamples samples = generator.getSamples(); + this.samples = new SAMPLE_ELEMENTSBRACES(samples.e0().ENTRY_KEY(), samples.e1().ENTRY_KEY(), samples.e2().ENTRY_KEY(), samples.e3().ENTRY_KEY(), samples.e4().ENTRY_KEY()); + } + + @Override + public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() { + return samples; + } + + @Override + public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) { + VALUE_TYPE value = generator.getSamples().e0().ENTRY_VALUE(); + ObjectList entries = new ObjectArrayList<>(); + for (KEY_TYPE key : insertionOrder) { + entries.add(new ABSTRACT_MAP.BasicEntryKV_BRACES(key, value)); + } + LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); + for (Entry KEY_VALUE_GENERIC_TYPE entry : generator.order(entries)) { + list.add(entry.ENTRY_KEY()); + } + return list; + } + + @Override + public Iterable order(List insertionOrder) { + VALUE_TYPE value = generator.getSamples().e0().ENTRY_VALUE(); + ObjectList entries = new ObjectArrayList<>(); + for (KEY_TYPE key : insertionOrder) { + entries.add(new ABSTRACT_MAP.BasicEntryKV_BRACES(key, value)); + } + LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); + for (Entry KEY_VALUE_GENERIC_TYPE entry : generator.order(entries)) { + list.add(entry.ENTRY_KEY()); + } + return list; + } + +#if !TYPE_OBJECT + @Override + public SET KEY_GENERIC_TYPE create(KEY_TYPE... elements) { + Entry KEY_VALUE_GENERIC_TYPE[] result = new Entry[elements.length]; + int index = 0; + for (Entry KEY_VALUE_GENERIC_TYPE entry : generator.getSamples().asList().subList(0, elements.length)) { + result[index] = new ABSTRACT_MAP.BasicEntryKV_BRACES(elements[index++], entry.ENTRY_VALUE()); + } + return generator.create(result).keySet(); + } + +#endif + @Override + public SET KEY_GENERIC_TYPE create(Object... elements) { + Entry KEY_VALUE_GENERIC_TYPE[] result = new Entry[elements.length]; + int index = 0; + for (Entry KEY_VALUE_GENERIC_TYPE entry : generator.getSamples().asList().subList(0, elements.length)) { + result[index] = new ABSTRACT_MAP.BasicEntryKV_BRACES((CLASS_TYPE) elements[index++], entry.getValue()); + } + return generator.create(result).keySet(); + } + } + + public static class MapValueCollectionGenerator KEY_VALUE_GENERIC_TYPE implements VALUE_TEST_COLLECTION_GENERATOR VALUE_GENERIC_TYPE { + TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE generator; + VALUE_SAMPLE_ELEMENTS VALUE_GENERIC_TYPE samples; + + public MapValueCollectionGenerator(OneSizeTestContainerGenerator, Map.Entry> inner) { + generator = (TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) inner.getInnerGenerator(); + ObjectSamples samples = generator.getSamples(); + this.samples = new VALUE_SAMPLE_ELEMENTSVALUE_BRACES(samples.e0().ENTRY_VALUE(), samples.e1().ENTRY_VALUE(), samples.e2().ENTRY_VALUE(), samples.e3().ENTRY_VALUE(), samples.e4().ENTRY_VALUE()); + } + + @Override + public VALUE_SAMPLE_ELEMENTS VALUE_GENERIC_TYPE getSamples() { + return samples; + } + + @Override + public VALUE_ITERABLE VALUE_GENERIC_TYPE order(VALUE_LIST VALUE_GENERIC_TYPE insertionOrder) { + ObjectList list = generator.order(generator.getSamples().asList()).pourAsList(); +#if VALUE_OBJECT + insertionOrder.sort(new Comparator() { +#else + insertionOrder.sort(new VALUE_COMPARATOR VALUE_GENERIC_TYPE() { +#endif + @Override + public int compare(VALUE_TYPE key, VALUE_TYPE value) { + return Integer.signum(indexOf(key) - indexOf(value)); + } + + protected int indexOf(VALUE_TYPE entry) { + for(int i = 0,m=list.size();i order(List insertionOrder) { + ObjectList list = generator.order(generator.getSamples().asList()).pourAsList(); + insertionOrder.sort(new Comparator() { + @Override + public int compare(CLASS_VALUE_TYPE key, CLASS_VALUE_TYPE value) { + return Integer.signum(indexOf(key) - indexOf(value)); + } + + protected int indexOf(CLASS_VALUE_TYPE entry) { + for(int i = 0,m=list.size();i> entryObjectComparator(Comparator keyComparator) { + return new Comparator>() { + @Override + public int compare(Map.Entry a, Map.Entry b) { + if(keyComparator == null) { + return COMPAREABLE_TO_KEY(OBJ_TO_KEY(a.getKey()), OBJ_TO_KEY(b.getKey())); + } + return keyComparator.compare(OBJ_TO_KEY(a.getKey()), OBJ_TO_KEY(b.getKey())); + } + }; + } + + public static KEY_VALUE_GENERIC_TYPE Comparator entryComparator(COMPARATOR KEY_GENERIC_TYPE keyComparator) { + return new Comparator() { + @Override + public int compare(Entry KEY_VALUE_GENERIC_TYPE a, Entry KEY_VALUE_GENERIC_TYPE b) { + if(keyComparator == null) { + return COMPAREABLE_TO_KEY(a.ENTRY_KEY(), b.ENTRY_KEY()); + } + return keyComparator.compare(a.ENTRY_KEY(), b.ENTRY_KEY()); + } + }; + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/impl/maps/MapConstructorTests.template b/src/builder/resources/speiger/assets/testers/templates/impl/maps/MapConstructorTests.template new file mode 100644 index 00000000..18dc8412 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/impl/maps/MapConstructorTests.template @@ -0,0 +1,934 @@ +package speiger.src.testers.PACKAGE.impl.maps; + +#if TYPE_OBJECT || VALUE_OBJECT +import java.util.Arrays; +#endif +#if TYPE_OBJECT +import java.util.Objects; +import java.util.Comparator; +#endif + +#if TYPE_OBJECT +import org.junit.Assert; +#endif +import org.junit.Ignore; +import org.junit.Test; + +#if TYPE_OBJECT +import com.google.common.collect.testing.AnEnum; +#endif + +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.PACKAGE.maps.impl.hash.HASH_MAP; +import speiger.src.collections.PACKAGE.maps.impl.hash.LINKED_HASH_MAP; +import speiger.src.collections.PACKAGE.maps.impl.customHash.CUSTOM_HASH_MAP; +import speiger.src.collections.PACKAGE.maps.impl.customHash.LINKED_CUSTOM_HASH_MAP; +import speiger.src.collections.PACKAGE.maps.impl.concurrent.CONCURRENT_HASH_MAP; +#if TYPE_OBJECT +import speiger.src.collections.PACKAGE.maps.impl.misc.ENUM_MAP; +import speiger.src.collections.PACKAGE.maps.impl.misc.LINKED_ENUM_MAP; +#endif + +import speiger.src.collections.PACKAGE.maps.impl.tree.RB_TREE_MAP; +import speiger.src.collections.PACKAGE.maps.impl.tree.AVL_TREE_MAP; +import speiger.src.collections.PACKAGE.utils.STRATEGY; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester; +#if TYPE_OBJECT || VALUE_OBJECT +import speiger.src.collections.objects.utils.StringSortTest; +#endif + +@Ignore +@SuppressWarnings("javadoc") +public class MAP_CONSTRUCTOR_TESTS +{ + public static class HashMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public HashMap() { + setSimpleConstructor(MAP.builder()::map); + setSizeConstructor(MAP.builder()::map); + setPArrayConstructor(MAP.builder()::map); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor(MAP.builder()::map); +#endif + setPMapConstructor(MAP.builder()::map); + setMapConstructor(MAP.builder()::map); + } + + @Test + public void testWrongLoadFactorSize() { + setSizeConstructor(T -> new HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 0F)); + try { + testSizeConstructor_smallSize(); + fail("A Constructor using a 0 LoadFactor should error"); + } catch(IllegalStateException e) { + } + + setSizeConstructor(T -> new HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 1F)); + try { + testSizeConstructor_smallSize(); + fail("A Constructor using a 1 LoadFactor should error"); + } catch(IllegalStateException e) { + } + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class LinkedHashMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public LinkedHashMap() { + setSimpleConstructor(MAP.builder()::linkedMap); + setSizeConstructor(MAP.builder()::linkedMap); + setPArrayConstructor(MAP.builder()::linkedMap); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor(MAP.builder()::linkedMap); +#endif + setPMapConstructor(MAP.builder()::linkedMap); + setMapConstructor(MAP.builder()::linkedMap); + } + + @Test + public void testWrongLoadFactorSize() { + setSizeConstructor(T -> new LINKED_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 0F)); + try { + testSizeConstructor_smallSize(); + fail("A Constructor using a 0 LoadFactor should error"); + } catch(IllegalStateException e) { + } + + setSizeConstructor(T -> new LINKED_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 1F)); + try { + testSizeConstructor_smallSize(); + fail("A Constructor using a 1 LoadFactor should error"); + } catch(IllegalStateException e) { + } + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + +#if TYPE_OBJECT +#if VALUE_OBJECT + public static class EnumMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester +#else + public static class EnumMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester +#endif + { + public EnumMap() { + setSimpleConstructor(() -> new ENUM_MAP<>(AnEnum.class)); + setPArrayConstructor(ENUM_MAP::new); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor(ENUM_MAP::new); +#endif + setPMapConstructor(ENUM_MAP::new); + setMapConstructor(ENUM_MAP::new); + } + + @Test + public void testEnumMapConstructor() { + if(pMapConstructor == null) return; + Assert.assertTrue(pMapConstructor.apply(new ENUM_MAP<>(new LINKED_HASH_MAPKV_BRACES(keys, values))) != null); + } + + @Test + public void testObjectEnumMapConstructor() { + if(pMapConstructor == null) return; + Assert.assertTrue(mapConstructor.apply(new ENUM_MAP<>(new LINKED_HASH_MAPKV_BRACES(keys, values))) != null); + } + + @Override + protected AnEnum[] createKeyElements() { + return AnEnum.values(); + } + +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOf(StringSortTest.NAMES, AnEnum.values().length); + } +#else + @Override + protected int getSize() { + return AnEnum.values().length; + } +#endif + } + +#if VALUE_OBJECT + public static class LinkedEnumMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester +#else + public static class LinkedEnumMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester +#endif + { + public LinkedEnumMap() { + setSimpleConstructor(() -> new LINKED_ENUM_MAP<>(AnEnum.class)); + setPArrayConstructor(LINKED_ENUM_MAP::new); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor(LINKED_ENUM_MAP::new); +#endif + setPMapConstructor(LINKED_ENUM_MAP::new); + setMapConstructor(LINKED_ENUM_MAP::new); + } + + @Test + public void testEnumMapConstructor() { + if(pMapConstructor == null) return; + Assert.assertTrue(pMapConstructor.apply(new LINKED_ENUM_MAP<>(new LINKED_HASH_MAPKV_BRACES(keys, values))) != null); + Assert.assertTrue(pMapConstructor.apply(new ENUM_MAP<>(new LINKED_HASH_MAPKV_BRACES(keys, values))) != null); + } + + @Test + public void testObjectEnumMapConstructor() { + if(mapConstructor == null) return; + Assert.assertTrue(mapConstructor.apply(new LINKED_ENUM_MAP<>(new LINKED_HASH_MAPKV_BRACES(keys, values))) != null); + Assert.assertTrue(mapConstructor.apply(new ENUM_MAP<>(new LINKED_HASH_MAPKV_BRACES(keys, values))) != null); + } + + @Override + protected AnEnum[] createKeyElements() { + return AnEnum.values(); + } + +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOf(StringSortTest.NAMES, AnEnum.values().length); + } +#else + @Override + protected int getSize() { + return AnEnum.values().length; + } +#endif + } + +#endif + public static class CustomHashMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public CustomHashMap() { + setSimpleConstructor(() -> MAP.builder().customMap(HashStrategy.INSTANCE)); + setSizeConstructor(T -> MAP.builder().customMap(T, HashStrategy.INSTANCE)); + setPArrayConstructor((K, V) -> MAP.builder().customMap(K, V, HashStrategy.INSTANCE)); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> MAP.builder().customMap(K, V, HashStrategy.INSTANCE)); +#endif + setPMapConstructor(T -> MAP.builder().customMap(T, HashStrategy.INSTANCE)); + setMapConstructor(T -> MAP.builder().customMap(T, HashStrategy.INSTANCE)); + } + + @Test + public void testWrongLoadFactorSize() { + setSizeConstructor(T -> new CUSTOM_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 0F, HashStrategy.INSTANCE)); + try { + testSizeConstructor_smallSize(); + fail("A Constructor using a 0 LoadFactor should error"); + } catch(IllegalStateException e) { + } + + setSizeConstructor(T -> new CUSTOM_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 1F, HashStrategy.INSTANCE)); + try { + testSizeConstructor_smallSize(); + fail("A Constructor using a 1 LoadFactor should error"); + } catch(IllegalStateException e) { + } + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class LinkedCustomHashMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public LinkedCustomHashMap() { + setSimpleConstructor(() -> MAP.builder().customLinkedMap(HashStrategy.INSTANCE)); + setSizeConstructor(T -> MAP.builder().customLinkedMap(T, HashStrategy.INSTANCE)); + setPArrayConstructor((K, V) -> MAP.builder().customLinkedMap(K, V, HashStrategy.INSTANCE)); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> MAP.builder().customLinkedMap(K, V, HashStrategy.INSTANCE)); +#endif + setPMapConstructor(T -> MAP.builder().customLinkedMap(T, HashStrategy.INSTANCE)); + setMapConstructor(T -> MAP.builder().customLinkedMap(T, HashStrategy.INSTANCE)); + } + + @Test + public void testWrongLoadFactorSize() { + setSizeConstructor(T -> new LINKED_CUSTOM_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 0F, HashStrategy.INSTANCE)); + try { + testSizeConstructor_smallSize(); + fail("A Constructor using a 0 LoadFactor should error"); + } catch(IllegalStateException e) { + } + + setSizeConstructor(T -> new LINKED_CUSTOM_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 1F, HashStrategy.INSTANCE)); + try { + testSizeConstructor_smallSize(); + fail("A Constructor using a 1 LoadFactor should error"); + } catch(IllegalStateException e) { + } + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class ImmutableHashMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public ImmutableHashMap() { + setPArrayConstructor(MAP.builder()::immutable); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor(MAP.builder()::immutable); +#endif + setPMapConstructor(MAP.builder()::immutable); + setMapConstructor(MAP.builder()::immutable); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class ConcurrentHashMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public ConcurrentHashMap() { + setSimpleConstructor(CONCURRENT_HASH_MAP::new); + setSizeConstructor(CONCURRENT_HASH_MAP::new); + setPArrayConstructor(CONCURRENT_HASH_MAP::new); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor(CONCURRENT_HASH_MAP::new); +#endif + setPMapConstructor(CONCURRENT_HASH_MAP::new); + setMapConstructor(CONCURRENT_HASH_MAP::new); + } + + @Test + public void testWrongLoadFactorSize() { + setSizeConstructor(T -> new CONCURRENT_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 0F)); + try { + testSizeConstructor_smallSize(); + fail("A Constructor using a 0 LoadFactor should error"); + } catch(IllegalStateException e) { + } + + setSizeConstructor(T -> new CONCURRENT_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 1F)); + try { + testSizeConstructor_smallSize(); + fail("A Constructor using a 1 LoadFactor should error"); + } catch(IllegalStateException e) { + } + } + + @Test + public void testWrongConcurrency() { + setSizeConstructor(T -> new CONCURRENT_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, 0)); + try { + testSizeConstructor_smallSize(); + fail("A Constructor using a 0 Concurrency should error"); + } catch(IllegalStateException e) { + } + + setSizeConstructor(T -> new CONCURRENT_HASH_MAP KEY_VALUE_STRING_GENERIC_TYPE(T, Integer.MAX_VALUE)); + try { + testSizeConstructor_smallSize(); + fail("A Constructor using a 65536 or larger Concurrency should error"); + } catch(IllegalStateException e) { + } + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class ArrayMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public ArrayMap() { + setSimpleConstructor(MAP.builder()::arrayMap); + setSizeConstructor(MAP.builder()::arrayMap); + setPArrayConstructor(MAP.builder()::arrayMap); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor(MAP.builder()::arrayMap); +#endif + setPMapConstructor(MAP.builder()::arrayMap); + setMapConstructor(MAP.builder()::arrayMap); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class RBTreeMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public RBTreeMap() { + setSimpleConstructor(MAP.builder()::rbTreeMap); + setPArrayConstructor(RB_TREE_MAP::new); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor(RB_TREE_MAP::new); +#endif + setPMapConstructor(RB_TREE_MAP::new); + setMapConstructor(RB_TREE_MAP::new); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class RBTreeMapComparator extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public RBTreeMapComparator() { +#if TYPE_OBJECT + setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPErbTreeMap(Comparator.naturalOrder())); + setPArrayConstructor((K, V) -> MAP.builder().rbTreeMap(K, V, Comparator.naturalOrder())); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> MAP.builder().rbTreeMap(K, V, Comparator.naturalOrder())); +#endif + setPMapConstructor(T -> MAP.builder().rbTreeMap(T, Comparator.naturalOrder())); + setMapConstructor(T -> MAP.builder().rbTreeMap(T, Comparator.naturalOrder())); +#else + setSimpleConstructor(() -> MAP.builder().rbTreeMap(CLASS_TYPE::compare)); + setPArrayConstructor((K, V) -> MAP.builder().rbTreeMap(K, V, CLASS_TYPE::compare)); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> MAP.builder().rbTreeMap(K, V, CLASS_TYPE::compare)); +#endif + setPMapConstructor(T -> MAP.builder().rbTreeMap(T, CLASS_TYPE::compare)); + setMapConstructor(T -> MAP.builder().rbTreeMap(T, CLASS_TYPE::compare)); +#endif + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class AVLTreeMap extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public AVLTreeMap() { + setSimpleConstructor(MAP.builder()::avlTreeMap); + setPArrayConstructor(AVL_TREE_MAP::new); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor(AVL_TREE_MAP::new); +#endif + setPMapConstructor(AVL_TREE_MAP::new); + setMapConstructor(AVL_TREE_MAP::new); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class AVLTreeMapComparator extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public AVLTreeMapComparator() { +#if TYPE_OBJECT + setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEavlTreeMap(Comparator.naturalOrder())); + setPArrayConstructor((K, V) -> MAP.builder().avlTreeMap(K, V, Comparator.naturalOrder())); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> MAP.builder().avlTreeMap(K, V, Comparator.naturalOrder())); +#endif + setPMapConstructor(T -> MAP.builder().avlTreeMap(T, Comparator.naturalOrder())); + setMapConstructor(T -> MAP.builder().avlTreeMap(T, Comparator.naturalOrder())); +#else + setSimpleConstructor(() -> MAP.builder().avlTreeMap(CLASS_TYPE::compare)); + setPArrayConstructor((K, V) -> MAP.builder().avlTreeMap(K, V, CLASS_TYPE::compare)); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> MAP.builder().avlTreeMap(K, V, CLASS_TYPE::compare)); +#endif + setPMapConstructor(T -> MAP.builder().avlTreeMap(T, CLASS_TYPE::compare)); + setMapConstructor(T -> MAP.builder().avlTreeMap(T, CLASS_TYPE::compare)); +#endif + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + private static class HashStrategy implements STRATEGY KEY_STRING_GENERIC_TYPE { + static final HashStrategy INSTANCE = new HashStrategy(); + @Override + public int hashCode(KEY_STRING_TYPE o) { return KEY_TO_HASH(o); } + @Override + public boolean equals(KEY_STRING_TYPE key, KEY_STRING_TYPE value) { return KEY_EQUALS(key, value); } + } + + public static class HashMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public HashMapBuilder() { + setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().map()); + setSizeConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(T).map()); + setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).map()); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).map()); +#endif + setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).map()); + setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).map()); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class LinkedHashMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public LinkedHashMapBuilder() { + setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().linkedMap()); + setSizeConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(T).linkedMap()); + setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).linkedMap()); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).linkedMap()); +#endif + setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).linkedMap()); + setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).linkedMap()); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class CustomHashMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public CustomHashMapBuilder() { + setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().customMap(HashStrategy.INSTANCE)); + setSizeConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(T).customMap(HashStrategy.INSTANCE)); + setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).customMap(HashStrategy.INSTANCE)); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).customMap(HashStrategy.INSTANCE)); +#endif + setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).customMap(HashStrategy.INSTANCE)); + setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).customMap(HashStrategy.INSTANCE)); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class LinkedCustomHashMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public LinkedCustomHashMapBuilder() { + setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().customLinkedMap(HashStrategy.INSTANCE)); + setSizeConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(T).customLinkedMap(HashStrategy.INSTANCE)); + setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).customLinkedMap(HashStrategy.INSTANCE)); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).customLinkedMap(HashStrategy.INSTANCE)); +#endif + setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).customLinkedMap(HashStrategy.INSTANCE)); + setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).customLinkedMap(HashStrategy.INSTANCE)); + + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class ImmutableHashMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public ImmutableHashMapBuilder() { + setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).immutable()); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).immutable()); +#endif + setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).immutable()); + setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).immutable()); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class ConcurrentHashMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public ConcurrentHashMapBuilder() { + setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().concurrentMap()); + setSizeConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(T).concurrentMap()); + setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).concurrentMap()); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).concurrentMap()); +#endif + setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).concurrentMap()); + setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).concurrentMap()); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class ArrayMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public ArrayMapBuilder() { + setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().arrayMap()); + setSizeConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(T).arrayMap()); + setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).arrayMap()); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).arrayMap()); +#endif + setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).arrayMap()); + setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).arrayMap()); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class RBTreeMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public RBTreeMapBuilder() { + setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().rbTreeMap()); + setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).rbTreeMap()); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).rbTreeMap()); +#endif + setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).rbTreeMap()); + setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).rbTreeMap()); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class RBTreeMapComparatorBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public RBTreeMapComparatorBuilder() { +#if TYPE_OBJECT + setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().rbTreeMap(Comparator.naturalOrder())); + setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).rbTreeMap(Comparator.naturalOrder())); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).rbTreeMap(Comparator.naturalOrder())); +#endif + setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).rbTreeMap(Comparator.naturalOrder())); + setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).rbTreeMap(Comparator.naturalOrder())); +#else + setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().rbTreeMap(CLASS_TYPE::compare)); + setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).rbTreeMap(CLASS_TYPE::compare)); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).rbTreeMap(CLASS_TYPE::compare)); +#endif + setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).rbTreeMap(CLASS_TYPE::compare)); + setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).rbTreeMap(CLASS_TYPE::compare)); +#endif + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class AVLTreeMapBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public AVLTreeMapBuilder() { + setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().avlTreeMap()); + setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).avlTreeMap()); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).avlTreeMap()); +#endif + setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).avlTreeMap()); + setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).avlTreeMap()); + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + public static class AVLTreeMapComparatorBuilder extends FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_STRING_GENERIC_TYPE + { + public AVLTreeMapComparatorBuilder() { +#if TYPE_OBJECT + setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().avlTreeMap(Comparator.naturalOrder())); + setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).avlTreeMap(Comparator.naturalOrder())); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).avlTreeMap(Comparator.naturalOrder())); +#endif + setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).avlTreeMap(Comparator.naturalOrder())); + setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).avlTreeMap(Comparator.naturalOrder())); +#else + setSimpleConstructor(() -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().avlTreeMap(CLASS_TYPE::compare)); + setPArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).avlTreeMap(CLASS_TYPE::compare)); +#if !TYPE_OBJECT || !VALUE_OBJECT + setArrayConstructor((K, V) -> putAll(MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart(), K, V).avlTreeMap(CLASS_TYPE::compare)); +#endif + setPMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).avlTreeMap(CLASS_TYPE::compare)); + setMapConstructor(T -> MAP.builder(). KEY_VALUE_STRING_GENERIC_TYPEstart().putAll(T).avlTreeMap(CLASS_TYPE::compare)); +#endif + } + +#if TYPE_OBJECT + @Override + protected String[] createKeyElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 0, 100); + } + +#endif +#if VALUE_OBJECT + @Override + protected String[] createValueElements() { + return Arrays.copyOfRange(StringSortTest.NAMES, 100, 200); + } + +#endif + } + + private static MAP.BuilderCache KEY_VALUE_STRING_GENERIC_TYPE putAll(MAP.BuilderCache KEY_VALUE_STRING_GENERIC_TYPE cache, KEY_STRING_TYPE[] keys, VALUE_STRING_TYPE[] values) { + if(keys.length != values.length) throw new IllegalStateException("Keys & Values lengths must match"); + for(int i = 0;i +{ + BiFunction mapper; +#if TYPE_BYTE + KEY_TYPE[] keys = new KEY_TYPE[]{(byte)0, (byte)1, (byte)2, (byte)3, (byte)4, (byte)-2, (byte)-1, (byte)5, (byte)6}; +#else if TYPE_SHORT + KEY_TYPE[] keys = new KEY_TYPE[]{(short)0, (short)1, (short)2, (short)3, (short)4, (short)-2, (short)-1, (short)5, (short)6}; +#else if TYPE_CHAR + KEY_TYPE[] keys = new KEY_TYPE[]{(char)0, (char)1, (char)2, (char)3, (char)4}; +#else if TYPE_OBJECT + KEY_TYPE[] keys; +#else + KEY_TYPE[] keys = new KEY_TYPE[]{0, 1, 2, 3, 4, -2, -1, 5, 6}; +#endif +#if VALUE_BOOLEAN + VALUE_TYPE[] values = new VALUE_TYPE[]{true, true, true, false, true, false, true, false, true}; +#else if VALUE_BYTE + VALUE_TYPE[] values = new VALUE_TYPE[]{(byte)0, (byte)1, (byte)2, (byte)3, (byte)4, (byte)-2, (byte)-1, (byte)5, (byte)6}; +#else if VALUE_SHORT + VALUE_TYPE[] values = new VALUE_TYPE[]{(short)0, (short)1, (short)2, (short)3, (short)4, (short)-2, (short)-1, (short)5, (short)6}; +#else if VALUE_CHAR + VALUE_TYPE[] values = new VALUE_TYPE[]{(char)0, (char)1, (char)2, (char)3, (char)4}; +#else if VALUE_OBJECT + VALUE_TYPE[] values; +#else + VALUE_TYPE[] values = new VALUE_TYPE[]{0, 1, 2, 3, 4, -2, -1, 5, 6}; +#endif + + public SIMPLE_MAP_TEST_GENERATOR(BiFunction mapper) { + this.mapper = mapper; + } + +#if TYPE_OBJECT || TYPE_CHAR + public void setKeys(KEY_TYPE... keys) { + this.keys = keys; + } + +#endif +#if VALUE_OBJECT || VALUE_CHAR + public void setValues(VALUE_TYPE... values) { + this.values = values; + } + +#endif + public ObjectSamples getSamples() { + return new ObjectSamples( + new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[0], values[0]), + new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[1], values[1]), + new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[2], values[2]), + new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[3], values[3]), + new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[4], values[4]) + ); + } + + public E create(MAP.Entry KEY_VALUE_GENERIC_TYPE... elements) { +#if TYPE_OBJECT + KEY_TYPE[] keys = (T[])ObjectArrays.newArray(getSamples().e0().ENTRY_KEY().getClass(), elements.length); +#else + KEY_TYPE[] keys = NEW_KEY_ARRAY(elements.length); +#endif +#if VALUE_OBJECT + VALUE_TYPE[] values = (V[])ObjectArrays.newArray(getSamples().e0().ENTRY_VALUE().getClass(), elements.length); +#else + VALUE_TYPE[] values = NEW_VALUE_ARRAY(elements.length); +#endif + for(int i = 0;i> order(List> insertionOrder) { + return insertionOrder; + } + + public ObjectIterable order(ObjectList insertionOrder) { + return insertionOrder; + } + + public static class Maps KEY_VALUE_GENERIC_TYPE extends SIMPLE_MAP_TEST_GENERATOR KEY_VALUE_SPECIAL_GENERIC_TYPE implements TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE + { + public Maps(BiFunction mapper) { + super(mapper); + } + } + + public static class OrderedMaps KEY_VALUE_GENERIC_TYPE extends SIMPLE_MAP_TEST_GENERATOR KEY_VALUE_SPECIAL_GENERIC_TYPE implements TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE + { + public OrderedMaps(BiFunction mapper) { + super(mapper); + } + } + + public static class ConcurrentMaps KEY_VALUE_GENERIC_TYPE extends SIMPLE_MAP_TEST_GENERATOR KEY_VALUE_SPECIAL_GENERIC_TYPE implements TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE + { + Consumer> sorter; + + public ConcurrentMaps(BiFunction mapper, Consumer> sorter) { + super(mapper); + this.sorter = sorter; + } + + public Iterable> order(List> insertionOrder) { + ObjectList newList = new ObjectArrayList<>(); + for(Map.Entry entry : insertionOrder) { + newList.add(new ABSTRACT_MAP.BasicEntryKV_BRACES(entry.getKey(), entry.getValue())); + } + order(newList); + insertionOrder.sort(new Comparator>() { + @Override + public int compare(Map.Entry key, Map.Entry value) { + return Integer.signum(indexOf(OBJ_TO_KEY(key.getKey())) - indexOf(OBJ_TO_KEY(value.getKey()))); + } + + protected int indexOf(KEY_TYPE key) { + for(int i = 0,m=newList.size();i order(ObjectList insertionOrder) { + sorter.accept(insertionOrder); + return insertionOrder; + } + } + + public static class SortedMaps KEY_VALUE_GENERIC_TYPE extends SIMPLE_MAP_TEST_GENERATOR KEY_VALUE_SPECIAL_GENERIC_TYPE implements TEST_SORTED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE + { + public SortedMaps(BiFunction mapper) { + super(mapper); +#if TYPE_CHAR + setKeys(new KEY_TYPE[]{'a', 'b', 'c', 'd', 'e', '_', '`', 'f', 'g'}); +#endif +#if VALUE_CHAR + setValues(new VALUE_TYPE[]{'a', 'b', 'c', 'd', 'e', '_', '`', 'f', 'g'}); +#endif + + } + + public Iterable> order(List> insertionOrder) { +#if TYPE_OBJECT + insertionOrder.sort(DERIVED_MAP_GENERATORS.entryObjectComparator((Comparator)Comparator.naturalOrder())); +#else + insertionOrder.sort(DERIVED_MAP_GENERATORS.entryObjectComparator(CLASS_TYPE::compare)); +#endif + return insertionOrder; + } + + public ObjectIterable order(ObjectList insertionOrder) { +#if TYPE_OBJECT + insertionOrder.sort(DERIVED_MAP_GENERATORS.entryComparator((Comparator)Comparator.naturalOrder())); +#else + insertionOrder.sort(DERIVED_MAP_GENERATORS.entryComparator(CLASS_TYPE::compare)); +#endif + return insertionOrder; + } + + @Override + public MAP.Entry KEY_VALUE_GENERIC_TYPE belowSamplesLesser() { return new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[5], values[5]); } + @Override + public MAP.Entry KEY_VALUE_GENERIC_TYPE belowSamplesGreater() { return new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[6], values[6]); } + @Override + public MAP.Entry KEY_VALUE_GENERIC_TYPE aboveSamplesLesser() { return new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[7], values[7]); } + @Override + public MAP.Entry KEY_VALUE_GENERIC_TYPE aboveSamplesGreater() { return new ABSTRACT_MAP.BasicEntryKV_BRACES(keys[8], values[8]); } + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/impl/maps/TestMap.template b/src/builder/resources/speiger/assets/testers/templates/impl/maps/TestMap.template new file mode 100644 index 00000000..573673db --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/impl/maps/TestMap.template @@ -0,0 +1,92 @@ +package speiger.src.testers.PACKAGE.impl.maps; + +import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.PACKAGE.maps.impl.misc.ARRAY_MAP; +import speiger.src.collections.objects.collections.ObjectIterator; +import speiger.src.collections.objects.sets.AbstractObjectSet; +import speiger.src.collections.objects.sets.ObjectSet; + +@SuppressWarnings("javadoc") +public class SIMPLE_TEST_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE +{ + MAP KEY_VALUE_GENERIC_TYPE map; + + public SIMPLE_TEST_MAP(KEY_TYPE[] keys, VALUE_TYPE[] values) { + map = new ARRAY_MAPKV_BRACES(keys, values); + } + + @Override + public ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE setDefaultReturnValue(VALUE_TYPE v) { + map.setDefaultReturnValue(v); + return this; + } + + @Override + public VALUE_TYPE getDefaultReturnValue() { return map.getDefaultReturnValue(); } + + @Override + public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value) { return map.put(key, value); } + @Override + public VALUE_TYPE putIfAbsent(KEY_TYPE key, VALUE_TYPE value) { return map.putIfAbsent(key, value); } +#if VALUE_PRIMITIVES + @Override + public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) { return map.addTo(key, value); } + @Override + public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value) { return map.subFrom(key, value); } +#endif + @Override + public VALUE_TYPE REMOVE_VALUE(KEY_TYPE key) { return map.REMOVE_VALUE(key); } + @Override + public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.REMOVE_VALUEOrDefault(key, defaultValue); } +#if !TYPE_OBJECT || !VALUE_OBJECT + @Override + public boolean remove(KEY_TYPE key, VALUE_TYPE value) { return map.remove(key, value); } +#endif + @Override + public CLASS_VALUE_TYPE remove(Object key) { return map.remove(key); } + @Override + public boolean remove(Object key, Object value) { return map.remove(key, value); } + @Override + public VALUE_TYPE GET_VALUE(KEY_TYPE key) { return map.GET_VALUE(key); } +#if TYPE_OBJECT && !VALUE_OBJECT + @Override + public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.getOrDefault(key, defaultValue); } +#endif + @Override + public ObjectSet ENTRY_SET() { + return new AbstractObjectSet() { + @Override + public ObjectIterator iterator() { + return new ObjectIterator() { + ObjectIterator iter = map.ENTRY_SET().iterator(); + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public MAP.Entry KEY_VALUE_GENERIC_TYPE next() { + MAP.Entry KEY_VALUE_GENERIC_TYPE entry = iter.next(); + return new ABSTRACT_MAP.BasicEntry KEY_VALUE_GENERIC_TYPE(entry.ENTRY_KEY(), entry.ENTRY_VALUE()) { + @Override + public VALUE_TYPE setValue(VALUE_TYPE value) { + return entry.setValue(value); + } + }; + } + + @Override + public void remove() { + iter.remove(); + } + }; + } + + @Override + public int size() { + return map.size(); + } + }; + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractCollectionTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractCollectionTester.template new file mode 100644 index 00000000..c8f7c3c2 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractCollectionTester.template @@ -0,0 +1,28 @@ +package speiger.src.testers.PACKAGE.tests.base; + +import org.junit.Ignore; + +import speiger.src.collections.PACKAGE.collections.COLLECTION; + +@Ignore +@SuppressWarnings("javadoc") +public class ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE extends ABSTRACT_CONTAINER_TESTER KKS_GENERIC_TYPE +{ + protected COLLECTION KEY_GENERIC_TYPE collection; + + @Override + protected COLLECTION KEY_GENERIC_TYPE actualContents() { + return collection; + } + + @Override + protected COLLECTION KEY_GENERIC_TYPE resetContainer(COLLECTION KEY_GENERIC_TYPE newContents) { + collection = super.resetContainer(newContents); + return collection; + } + + protected void resetCollection() { + resetContainer(); + } + +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractContainerTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractContainerTester.template new file mode 100644 index 00000000..010b6b39 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractContainerTester.template @@ -0,0 +1,188 @@ +package speiger.src.testers.PACKAGE.tests.base; + +import com.google.common.collect.testing.AbstractTester; +import com.google.common.collect.testing.OneSizeTestContainerGenerator; +import com.google.common.collect.testing.TestContainerGenerator; +import com.google.common.collect.testing.features.CollectionSize; +import com.google.errorprone.annotations.OverridingMethodsMustInvokeSuper; + +import org.junit.Ignore; + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.utils.LISTS; +import speiger.src.testers.PACKAGE.generators.TEST_COLLECTION_GENERATOR; +import speiger.src.testers.PACKAGE.utils.HELPERS; +import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS; +import speiger.src.testers.PACKAGE.utils.MINIMAL_COLLECTION; + +@Ignore +@SuppressWarnings("javadoc") +public abstract class ABSTRACT_CONTAINER_TESTER KKS_GENERIC_TYPE extends AbstractTester> +{ + protected SAMPLE_ELEMENTS KEY_GENERIC_TYPE samples; + protected E container; + protected TEST_COLLECTION_GENERATOR KEY_GENERIC_TYPE primitiveGenerator; + protected CollectionSize size; + + @Override + @OverridingMethodsMustInvokeSuper + public void setUp() throws Exception { + super.setUp(); + setupGenerator(); + } + + protected void setupGenerator() { + TestContainerGenerator generator = getSubjectGenerator().getInnerGenerator(); + if (!(generator instanceof TEST_COLLECTION_GENERATOR)) throw new IllegalStateException("Test Generator Must extend TEST_COLLECTION_GENERATOR"); + primitiveGenerator = (TEST_COLLECTION_GENERATOR KEY_GENERIC_TYPE) generator; + samples = primitiveGenerator.getSamples(); + size = getSubjectGenerator().getCollectionSize(); + resetContainer(); + } + + protected abstract COLLECTION KEY_GENERIC_TYPE actualContents(); + + protected E resetContainer() { + return resetContainer(createTestSubject()); + } + + protected E resetContainer(E newValue) { + container = newValue; + return container; + } + + protected void expectContents(KEY_TYPE... elements) { + expectContents(ARRAY_LIST.wrap(elements)); + } + + protected void expectContents(COLLECTION KEY_GENERIC_TYPE expected) { + HELPERS.assertEqualIgnoringOrder(expected, actualContents()); + } + + protected void expectUnchanged() { + expectContents(getOrderedElements()); + } + + protected final void expectAdded(KEY_TYPE... elements) { + LIST KEY_GENERIC_TYPE expected = HELPERS.copyToList(getSampleElements()); + expected.addAll(elements); + expectContents(expected); + } + + protected final void expectAddedIndex(int index, KEY_TYPE... elements) { + expectAdded(index, ARRAY_LIST.wrap(elements)); + } + + protected final void expectAdded(int index, COLLECTION KEY_GENERIC_TYPE elements) { + LIST KEY_GENERIC_TYPE expected = HELPERS.copyToList(getSampleElements()); + expected.addAll(index, elements); + expectContents(expected); + } + + protected void expectMissing(KEY_TYPE... elements) { + for (KEY_TYPE element : elements) { + assertFalse("Should not contain " + element, actualContents().contains(element)); + } + } + + protected KEY_TYPE[] createSamplesArray() { + return getSampleElements().TO_ARRAY(NEW_KEY_ARRAY(getNumElements())); + } + + protected KEY_TYPE[] createOrderedArray() { + return getOrderedElements().TO_ARRAY(NEW_KEY_ARRAY(getNumElements())); + } + + public static class ArrayWithDuplicate KEY_GENERIC_TYPE { + public final KEY_TYPE[] elements; + public final KEY_TYPE duplicate; + + private ArrayWithDuplicate(KEY_TYPE[] elements, KEY_TYPE duplicate) { + this.elements = elements; + this.duplicate = duplicate; + } + } + + protected ArrayWithDuplicate KEY_GENERIC_TYPE createArrayWithDuplicateElement() { + KEY_TYPE[] elements = createSamplesArray(); + KEY_TYPE duplicate = elements[(elements.length / 2) - 1]; + elements[(elements.length / 2) + 1] = duplicate; + return new ArrayWithDuplicateBRACES(elements, duplicate); + } + + protected int getNumElements() { + return size.getNumElements(); + } + + protected COLLECTION KEY_GENERIC_TYPE getSampleElements() { + return getSampleElements(getNumElements()); + } + + protected LIST KEY_GENERIC_TYPE getOrderedElements() { + LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); + for (ITERATOR KEY_GENERIC_TYPE iter = primitiveGenerator.order(new ARRAY_LISTBRACES(getSampleElements())).iterator(); iter.hasNext();) { + list.add(iter.NEXT()); + } + return LISTS.unmodifiable(list); + } + +#if TYPE_OBJECT + protected KEY_TYPE[] createDisjointArray() { + KEY_TYPE[] array = NEW_KEY_ARRAY(2); + array[0] = e3(); + array[1] = e4(); + return array; + } +#else + protected KEY_TYPE[] createDisjointArray() { + return new KEY_TYPE[]{e3(), e4()}; + } + +#endif + protected KEY_TYPE[] emptyArray() { + return NEW_KEY_ARRAY(0); + } + + protected MINIMAL_COLLECTION KEY_GENERIC_TYPE createDisjointCollection() { + return MINIMAL_COLLECTION.of(e3(), e4()); + } + + protected MINIMAL_COLLECTION KEY_GENERIC_TYPE emptyCollection() { + return MINIMAL_COLLECTION.of(); + } + + public KEY_TYPE[] createArray(KEY_TYPE...array) { + return array; + } + + protected final KEY_TYPE e0() { + return samples.e0(); + } + + protected final KEY_TYPE e1() { + return samples.e1(); + } + + protected final KEY_TYPE e2() { + return samples.e2(); + } + + protected final KEY_TYPE e3() { + return samples.e3(); + } + + protected final KEY_TYPE e4() { + return samples.e4(); + } + + protected E createTestSubject() { + return (E)primitiveGenerator.create(getSampleElements(size.getNumElements()).TO_ARRAY(NEW_KEY_ARRAY(getNumElements()))); + } + + protected COLLECTION KEY_GENERIC_TYPE getSampleElements(int howMany) { + return new ARRAY_LISTBRACES(samples.asList().subList(0, howMany)); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractListIndexOfTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractListIndexOfTester.template new file mode 100644 index 00000000..083241eb --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractListIndexOfTester.template @@ -0,0 +1,27 @@ +package speiger.src.testers.PACKAGE.tests.base; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +@Ignore +@SuppressWarnings("javadoc") +public abstract class ABSTRACT_LIST_INDEX_OF_TESTER KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ + protected abstract int find(KEY_TYPE o); + + protected abstract String getMethodName(); + + @CollectionSize.Require(absent = ZERO) + public void testFind_yes() { + assertEquals(getMethodName() + "(firstElement) should return 0", 0, find(getOrderedElements().GET_KEY(0))); + } + + public void testFind_no() { + assertEquals(getMethodName() + "(notPresent) should return -1", -1, find(e3())); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractListTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractListTester.template new file mode 100644 index 00000000..0eec85e7 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractListTester.template @@ -0,0 +1,39 @@ +package speiger.src.testers.PACKAGE.tests.base; + +import org.junit.Ignore; + +#if TYPE_OBJECT +import java.util.Objects; +#endif + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.utils.HELPERS; + +@Ignore +@SuppressWarnings("javadoc") +public class ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ + protected final LIST KEY_GENERIC_TYPE getList() { + return (LIST KEY_GENERIC_TYPE) collection; + } + + @Override + protected void expectContents(COLLECTION KEY_GENERIC_TYPE expectedCollection) { + LIST KEY_GENERIC_TYPE expectedList = HELPERS.copyToList(expectedCollection); + if (getList().size() != expectedList.size()) { + fail("size mismatch: " + reportContext(expectedList)); + } + for (int i = 0; i < expectedList.size(); i++) { + KEY_TYPE expected = expectedList.GET_KEY(i); + KEY_TYPE actual = getList().GET_KEY(i); + if (KEY_EQUALS_NOT(expected, actual)) { + fail("mismatch at index " + i + ": " + reportContext(expectedList)); + } + } + } + + private String reportContext(LIST KEY_GENERIC_TYPE expected) { + return String.format("expected collection %s; actual collection %s", expected, collection); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractQueueTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractQueueTester.template new file mode 100644 index 00000000..faee9c36 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/base/AbstractQueueTester.template @@ -0,0 +1,81 @@ +package speiger.src.testers.PACKAGE.tests.base; + +#if TYPE_OBJECT +import java.util.Objects; +#endif + +import org.junit.Ignore; + +import com.google.common.collect.testing.TestContainerGenerator; + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE; +import speiger.src.collections.PACKAGE.utils.LISTS; +import speiger.src.testers.PACKAGE.generators.TEST_QUEUE_GENERATOR; +import speiger.src.testers.PACKAGE.utils.HELPERS; + +@Ignore +@SuppressWarnings("javadoc") +public class ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE extends ABSTRACT_CONTAINER_TESTER KKS_GENERIC_TYPE +{ + protected TEST_QUEUE_GENERATOR KEY_GENERIC_TYPE queueGenerator; + protected PRIORITY_QUEUE KEY_GENERIC_TYPE queue; + + @Override + protected void setupGenerator() { + TestContainerGenerator generator = getSubjectGenerator().getInnerGenerator(); + if (!(generator instanceof TEST_QUEUE_GENERATOR)) throw new IllegalStateException("Test Generator Must extend TestLongCollectionGenerator"); + queueGenerator = (TEST_QUEUE_GENERATOR KEY_GENERIC_TYPE) generator; + samples = queueGenerator.getSamples(); + size = getSubjectGenerator().getCollectionSize(); + resetContainer(); + } + + @Override + protected COLLECTION KEY_GENERIC_TYPE actualContents() { return null; } + + @Override + protected PRIORITY_QUEUE KEY_GENERIC_TYPE resetContainer(PRIORITY_QUEUE KEY_GENERIC_TYPE newValue) { + queue = super.resetContainer(newValue); + return queue; + } + + protected void resetQueue() { + resetContainer(); + } + + protected LIST KEY_GENERIC_TYPE getOrderedElements() { + LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); + for (ITERATOR KEY_GENERIC_TYPE iter = queueGenerator.order(new ARRAY_LISTBRACES(getSampleElements())).iterator(); iter.hasNext();) { + list.add(iter.NEXT()); + } + return LISTS.unmodifiable(list); + } + + @Override + protected PRIORITY_QUEUE KEY_GENERIC_TYPE createTestSubject() { + return queueGenerator.create(getSampleElements(size.getNumElements()).TO_ARRAY(NEW_KEY_ARRAY(getNumElements()))); + } + + @Override + protected void expectContents(COLLECTION KEY_GENERIC_TYPE expected) { + HELPERS.assertContentsAnyOrder(expected, queue.TO_ARRAY()); + } + + @Override + protected void expectMissing(KEY_TYPE... elements) { + for (KEY_TYPE element : elements) { + assertFalse("Should not contain " + element, contains(element)); + } + } + + protected boolean contains(KEY_TYPE element) { + for(int i = 0,m=queue.size();i +{ + protected TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE primitiveMapGenerator; + + protected MAP KEY_VALUE_GENERIC_TYPE getMap() { + return container; + } + + @Override + protected void setupGenerator() { + TestContainerGenerator, ? extends Map.Entry> generator = getSubjectGenerator().getInnerGenerator(); + if (!(generator instanceof TEST_MAP_GENERATOR)) throw new IllegalStateException("Test Generator Must extend TestLong2ByteMapGenerator"); + primitiveMapGenerator = (TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) generator; + samples = primitiveMapGenerator.getSamples(); + size = getSubjectGenerator().getCollectionSize(); + resetContainer(); + } + + @Override + protected MAP KEY_VALUE_GENERIC_TYPE createTestSubject() { + return primitiveMapGenerator.create(getSampleElements(size.getNumElements()).toArray(new MAP.Entry[getNumElements()])); + } + + @Override + protected ObjectList getOrderedElements() { + ObjectList list = new ObjectArrayList<>(); + for (ObjectIterator iter = primitiveMapGenerator.order(new ObjectArrayList(getSampleElements())).iterator(); iter.hasNext();) { + list.add(iter.next()); + } + return ObjectLists.unmodifiable(list); + } + + @Override + protected ObjectCollection actualContents() { + return getMap().ENTRY_SET(); + } + + protected final void resetMap() { + resetContainer(); + } + + protected void resetMap(MAP.Entry KEY_VALUE_GENERIC_TYPE[] entries) { + resetContainer(primitiveMapGenerator.create(entries)); + } + + @Override + protected MAP KEY_VALUE_GENERIC_TYPE resetContainer(MAP KEY_VALUE_GENERIC_TYPE newValue) { + newValue.setDefaultReturnValue(INVALID_VALUE); + return super.resetContainer(newValue); + } + + protected void expectMissingKeys(KEY_TYPE... elements) { + for (KEY_TYPE element : elements) { + assertFalse("Should not contain key " + element, getMap().containsKey(element)); + } + } + + protected void expectMissingValues(VALUE_TYPE... elements) { + for (VALUE_TYPE element : elements) { + assertFalse("Should not contain value " + element, getMap().containsValue(element)); + } + } + + protected int getNumEntries() { + return getNumElements(); + } + + protected ObjectCollection getSampleEntries(int howMany) { + return getSampleElements(howMany); + } + + protected ObjectCollection getSampleEntries() { + return getSampleElements(); + } + + @Override + protected void expectMissing(MAP.Entry KEY_VALUE_GENERIC_TYPE... entries) { + for (MAP.Entry KEY_VALUE_GENERIC_TYPE entry : entries) { + assertFalse("Should not contain entry " + entry, actualContents().contains(entry)); +#if !VALUE_BOOLEAN + assertFalse("Should not contain key " + entry.ENTRY_KEY() + " mapped to value " + entry.ENTRY_VALUE(), valueEquals(getMap().get(entry.ENTRY_KEY()), entry.ENTRY_VALUE())); +#endif + } + } + + @Override + protected void expectContents(ObjectCollection expected) { + super.expectContents(expected); + for (MAP.Entry KEY_VALUE_GENERIC_TYPE entry : expected) { + assertEquals("Wrong value for key " + entry.ENTRY_KEY(), entry.ENTRY_VALUE(), getMap().GET_VALUE(entry.ENTRY_KEY())); + } + } + + protected final void expectReplacement(MAP.Entry KEY_VALUE_GENERIC_TYPE newEntry) { + ObjectList expected = ObjectHelpers.copyToList(getSampleElements()); + replaceValue(expected, newEntry); + expectContents(expected); + } + + private void replaceValue(ObjectList expected, MAP.Entry KEY_VALUE_GENERIC_TYPE newEntry) { + for (ObjectListIterator i = expected.listIterator(); i.hasNext();) { + if (HELPERS.equals(i.next().ENTRY_KEY(), newEntry.ENTRY_KEY())) { + i.set(newEntry); + return; + } + } + throw new IllegalArgumentException(String.format(Locale.ROOT, "key %s not found in entries %s", newEntry.ENTRY_KEY(), expected)); + } + +#if !VALUE_BOOLEAN + private static GENERIC_VALUE_BRACES boolean valueEquals(VALUE_TYPE a, VALUE_TYPE b) { + return VALUE_EQUALS(a, b); + } + +#endif + protected MAP.Entry KEY_VALUE_GENERIC_TYPE entry(KEY_TYPE key, VALUE_TYPE value) { + return new ABSTRACT_MAP.BasicEntryKV_BRACES(key, value); + } + + protected KEY_TYPE[] emptyKeyArray() { + return NEW_KEY_ARRAY(0); + } + + protected KEY_TYPE[] createDisjointedKeyArray() { + KEY_TYPE[] array = NEW_KEY_ARRAY(2); + array[0] = k3(); + array[1] = k4(); + return array; + } + + protected CLASS_TYPE[] emptyKeyObjectArray() { + return NEW_CLASS_ARRAY(0); + } + + protected CLASS_TYPE[] createDisjointedKeyObjectArray() { + CLASS_TYPE[] array = NEW_CLASS_ARRAY(2); + array[0] = k3(); + array[1] = k4(); + return array; + } + + protected VALUE_TYPE[] emptyValueArray() { + return NEW_VALUE_ARRAY(0); + } + + protected VALUE_TYPE[] createDisjointedValueArray() { + VALUE_TYPE[] array = NEW_VALUE_ARRAY(2); + array[0] = v3(); + array[1] = v4(); + return array; + } + + protected CLASS_VALUE_TYPE[] emptyValueObjectArray() { + return NEW_CLASS_VALUE_ARRAY(0); + } + + protected CLASS_VALUE_TYPE[] createDisjointedValueObjectArray() { + CLASS_VALUE_TYPE[] array = NEW_CLASS_VALUE_ARRAY(2); + array[0] = v3(); + array[1] = v4(); + return array; + } + + protected VALUE_TYPE get(KEY_TYPE key) { + return getMap().GET_VALUE(key); + } + +#if !TYPE_OBJECT + @SuppressWarnings("deprecation") + protected CLASS_VALUE_TYPE get(CLASS_TYPE key) { + return getMap().get(key); + } + +#endif + protected final KEY_TYPE k0() { + return e0().ENTRY_KEY(); + } + + protected final VALUE_TYPE v0() { + return e0().ENTRY_VALUE(); + } + + protected final KEY_TYPE k1() { + return e1().ENTRY_KEY(); + } + + protected final VALUE_TYPE v1() { + return e1().ENTRY_VALUE(); + } + + protected final KEY_TYPE k2() { + return e2().ENTRY_KEY(); + } + + protected final VALUE_TYPE v2() { + return e2().ENTRY_VALUE(); + } + + protected final KEY_TYPE k3() { + return e3().ENTRY_KEY(); + } + + protected final VALUE_TYPE v3() { + return e3().ENTRY_VALUE(); + } + + protected final KEY_TYPE k4() { + return e4().ENTRY_KEY(); + } + + protected final VALUE_TYPE v4() { + return e4().ENTRY_VALUE(); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionAddAllArrayTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionAddAllArrayTester.template new file mode 100644 index 00000000..c1d62f97 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionAddAllArrayTester.template @@ -0,0 +1,151 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import java.util.ConcurrentModificationException; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPECollectionAddAllArrayTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + public void testAddAllArray_supportedNothing() { + assertFalse("addAll(nothing[]) should return false", collection.addAll(emptyArray())); + expectUnchanged(); + } + + @CollectionFeature.Require(absent = SUPPORTS_ADD) + public void testAddAllArray_unsupportedNothing() { + try { + assertFalse("addAll(nothing[]) should return false or throw", collection.addAll(emptyArray())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + + @CollectionFeature.Require(SUPPORTS_ADD) + public void testAddAllArray_supportedNonePresent() { + assertTrue("addAll(nonePresent[]) should return true", collection.addAll(createDisjointArray())); + expectAdded(e3(), e4()); + } + + @CollectionFeature.Require(absent = SUPPORTS_ADD) + public void testAddAllArray_unsupportedNonePresent() { + try { + collection.addAll(createDisjointArray()); + fail("addAll(nonePresent[]) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + expectMissing(e3(), e4()); + } +#endignore + +#if !TYPE_BOOLEAN +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) +#endignore + public void testAddAllArray_supportedToLargeOffset() { + try { + collection.addAll(createDisjointArray(), 5, 2); + } catch (IndexOutOfBoundsException e) { + } + expectUnchanged(); + expectMissing(e3(), e4()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) +#endignore + public void testAddAllArray_supportedToLargeArray() { + try { + collection.addAll(createDisjointArray(), 3); + } catch (IndexOutOfBoundsException e) { + } + expectUnchanged(); + expectMissing(e3(), e4()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) +#endignore + public void testAddAllArray_supportedToSmallOffset() { + try { + collection.addAll(createDisjointArray(), -1, 2); + } catch (IndexOutOfBoundsException e) { + } + expectUnchanged(); + expectMissing(e3(), e4()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) +#endignore + public void testAddAllArray_supportedAddSubArray() { + try { + collection.addAll(createDisjointArray(), 1); + } catch (IndexOutOfBoundsException e) { + } + expectAdded(e3()); + expectMissing(e4()); + } +#endif +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) + public void testAddAllArray_supportedSomePresent() { + assertTrue("addAll(somePresent[]) should return true", collection.addAll(e3(), e0())); + assertTrue("should contain " + e3(), collection.contains(e3())); + assertTrue("should contain " + e0(), collection.contains(e0())); + } + + @CollectionFeature.Require(absent = SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) + public void testAddAllArray_unsupportedSomePresent() { + try { + collection.addAll(e3(), e0()); + fail("addAll(somePresent[]) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + + @CollectionFeature.Require({ SUPPORTS_ADD, FAILS_FAST_ON_CONCURRENT_MODIFICATION }) + @CollectionSize.Require(absent = ZERO) + public void testAddAllArrayConcurrentWithIteration() { +#endignore + try { + ITERATOR KEY_GENERIC_TYPE iterator = collection.iterator(); + assertTrue(collection.addAll(e3(), e0())); + iterator.NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) + public void testAddAllArray_unsupportedAllPresent() { + try { + assertFalse("addAll(allPresent[]) should return false or throw", collection.addAll(e0())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } +#endignore +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionAddAllTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionAddAllTester.template new file mode 100644 index 00000000..f41e199f --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionAddAllTester.template @@ -0,0 +1,102 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import java.util.ConcurrentModificationException; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; +import speiger.src.testers.PACKAGE.utils.MINIMAL_COLLECTION; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPECollectionAddAllTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + public void testAddAll_supportedNothing() { + assertFalse("addAll(nothing) should return false", collection.addAll(emptyCollection())); + expectUnchanged(); + } + + @CollectionFeature.Require(absent = SUPPORTS_ADD) + public void testAddAll_unsupportedNothing() { + try { + assertFalse("addAll(nothing) should return false or throw", collection.addAll(emptyCollection())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + + @CollectionFeature.Require(SUPPORTS_ADD) + public void testAddAll_supportedNonePresent() { + assertTrue("addAll(nonePresent) should return true", collection.addAll(createDisjointCollection())); + expectAdded(e3(), e4()); + } + + @CollectionFeature.Require(absent = SUPPORTS_ADD) + public void testAddAll_unsupportedNonePresent() { + try { + collection.addAll(createDisjointCollection()); + fail("addAll(nonePresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + expectMissing(e3(), e4()); + } + + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) + public void testAddAll_supportedSomePresent() { +#endignore + assertTrue("addAll(somePresent) should return true", collection.addAll(MINIMAL_COLLECTION.of(e3(), e0()))); + assertTrue("should contain " + e3(), collection.contains(e3())); + assertTrue("should contain " + e0(), collection.contains(e0())); + } +#ignore + @CollectionFeature.Require(absent = SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) + public void testAddAll_unsupportedSomePresent() { +#endignore + try { + collection.addAll(MINIMAL_COLLECTION.of(e3(), e0())); + fail("addAll(somePresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require({ SUPPORTS_ADD, FAILS_FAST_ON_CONCURRENT_MODIFICATION }) + @CollectionSize.Require(absent = ZERO) + public void testAddAllConcurrentWithIteration() { +#endignore + try { + ITERATOR KEY_GENERIC_TYPE iterator = collection.iterator(); + assertTrue(collection.addAll(MINIMAL_COLLECTION.of(e3(), e0()))); + iterator.NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + + @CollectionFeature.Require(absent = SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) + public void testAddAll_unsupportedAllPresent() { + try { + assertFalse("addAll(allPresent) should return false or throw", collection.addAll(MINIMAL_COLLECTION.of(e0()))); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionAddTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionAddTester.template new file mode 100644 index 00000000..180dc9a9 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionAddTester.template @@ -0,0 +1,64 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import java.util.ConcurrentModificationException; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPECollectionAddTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + public void testAdd_supportedNotPresent() { + assertTrue("add(notPresent) should return true", collection.add(e3())); + expectAdded(e3()); + } + + @CollectionFeature.Require(absent = SUPPORTS_ADD) + public void testAdd_unsupportedNotPresent() { + try { + collection.add(e3()); + fail("add(notPresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + expectMissing(e3()); + } + + @CollectionFeature.Require(absent = SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) + public void testAdd_unsupportedPresent() { + try { + assertFalse("add(present) should return false or throw", collection.add(e0())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + + @CollectionFeature.Require({ SUPPORTS_ADD, FAILS_FAST_ON_CONCURRENT_MODIFICATION }) + @CollectionSize.Require(absent = ZERO) + public void testAddConcurrentWithIteration() { +#endignore + try { + ITERATOR KEY_GENERIC_TYPE iterator = collection.iterator(); + assertTrue(collection.add(e3())); + iterator.NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionClearTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionClearTester.template new file mode 100644 index 00000000..1381bfbb --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionClearTester.template @@ -0,0 +1,68 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import java.util.ConcurrentModificationException; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPECollectionClearTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + public void testClear() { + collection.clear(); + assertTrue("After clear(), a collection should be empty.", collection.isEmpty()); + assertEquals(0, collection.size()); + assertFalse(collection.iterator().hasNext()); + } + + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) + public void testClear_unsupported() { + try { + collection.clear(); + fail("clear() should throw UnsupportedOperation if a collection does " + + "not support it and is not empty."); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) + public void testClear_unsupportedByEmptyCollection() { + try { + collection.clear(); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + + @CollectionFeature.Require({ SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION }) + @CollectionSize.Require(SEVERAL) + public void testClearConcurrentWithIteration() { +#endignore + try { + ITERATOR KEY_GENERIC_TYPE iterator = collection.iterator(); + collection.clear(); + iterator.NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionConstructorTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionConstructorTester.template new file mode 100644 index 00000000..dea1a067 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionConstructorTester.template @@ -0,0 +1,165 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.function.Function; +import java.util.function.IntFunction; +import java.util.function.Supplier; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.Ignore; +import junit.framework.TestCase; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.collections.COLLECTION; +#if !TYPE_OBJECT +import speiger.src.collections.PACKAGE.utils.ARRAYS; +#endif +import speiger.src.collections.utils.ITrimmable; + +@Ignore +@SuppressWarnings("javadoc") +public abstract class FILE_KEY_TYPECollectionConstructorTester KEY_GENERIC_TYPE extends TestCase +{ + protected Supplier simpleConstructor; + protected IntFunction sizeConstructor; + protected Function pArrayConstructor; +#if !TYPE_OBJECT + protected Function arrayConstructor; +#endif + protected Function, COLLECTION KEY_GENERIC_TYPE> collectionConstructor; + protected Function pCollectionConstructor; + protected KEY_TYPE[] keys = createKeyElements(); + + protected void setSimpleConstructor(Supplier simpleConstructor) { + this.simpleConstructor = simpleConstructor; + } + + protected void setSizeConstructor(IntFunction sizeConstructor) { + this.sizeConstructor = sizeConstructor; + } + + protected void setPArrayConstructor(Function pArrayConstructor) { + this.pArrayConstructor = pArrayConstructor; + } + +#if !TYPE_OBJECT + protected void setArrayConstructor(Function arrayConstructor) { + this.arrayConstructor = arrayConstructor; + } + +#endif + protected void setCollectionConstructor(Function, COLLECTION KEY_GENERIC_TYPE> collectionConstructor) { + this.collectionConstructor = collectionConstructor; + } + + protected void setPCollectionConstructor(Function pCollectionConstructor) { + this.pCollectionConstructor = pCollectionConstructor; + } + + @Test + public void testPrimitiveArrayConstructor() { + if(pArrayConstructor == null) return; + Assert.assertTrue(pArrayConstructor.apply(keys) != null); + } + +#if !TYPE_OBJECT + @Test + public void testArrayConstructor() { + if(arrayConstructor == null) return; +#if TYPE_OBJECT + Assert.assertTrue(arrayConstructor.apply(keys) != null); +#else + Assert.assertTrue(arrayConstructor.apply(ARRAYS.wrap(keys)) != null); +#endif + } + +#endif + @Test + public void testPrimitiveMapsConstructor() { + if(pCollectionConstructor == null) return; + Assert.assertTrue(pCollectionConstructor.apply(new ARRAY_LISTBRACES(keys)) != null); + } + + @Test + public void testMapsConstructor() { + if(collectionConstructor == null) return; + Assert.assertTrue(collectionConstructor.apply(new ArrayList<>(new ARRAY_LISTBRACES(keys))) != null); + } + + @Test + public void testSimpleConstructor() { + if(simpleConstructor == null) return; + Assert.assertTrue(simpleConstructor.get() != null); + } + + @Test + public void testSizeConstructor_empty() { + if(sizeConstructor == null) return; + Assert.assertTrue(sizeConstructor.apply(0) != null); + } + + @Test + public void testSizeConstructor_smallSize() { + if(sizeConstructor == null) return; + Assert.assertTrue(sizeConstructor.apply(32) != null); + } + + @Test + public void testSizeConstructor_largeSize() { + if(sizeConstructor == null) return; + Assert.assertTrue(sizeConstructor.apply(25212) != null); + } + + @Test + public void testRehash() { + if(sizeConstructor == null) return; + try + { + COLLECTION KEY_GENERIC_TYPE set = sizeConstructor.apply(0); + if(set instanceof ITrimmable) { + ITrimmable trim = (ITrimmable)set; + set.addAll(keys); + set.clear(); + Assert.assertTrue(trim.trim()); + Assert.assertFalse(trim.trim()); + set.addAll(keys); + trim.clearAndTrim(); + set.addAll(keys); + trim.clearAndTrim(Short.MAX_VALUE); + } + } + catch(UnsupportedOperationException e) { + //Ignore thats fine + } + } + + @Test + public void testSizeConstructor_InvalidSize() { + if(sizeConstructor == null) return; + try { + sizeConstructor.apply(-1); + Assert.fail("When Inputted Size is negative this should crash"); + } + catch(IllegalStateException e) { + } + } + +#if TYPE_OBJECT + protected abstract KEY_TYPE[] createKeyElements(); + +#else + protected KEY_TYPE[] createKeyElements() { + KEY_TYPE[] keys = NEW_KEY_ARRAY(100); + for(int i = 0;i<100;i++) { +#if TYPE_BOOLEAN + keys[i] = i % 2 != 0; +#else + keys[i] = (KEY_TYPE)i; +#endif + } + return keys; + } +#endif +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionContainsAllTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionContainsAllTester.template new file mode 100644 index 00000000..045dd624 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionContainsAllTester.template @@ -0,0 +1,45 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; +import speiger.src.testers.PACKAGE.utils.MINIMAL_COLLECTION; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPECollectionContainsAllTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ + public void testContainsAll_empty() { + assertTrue("containsAll(empty) should return true", collection.containsAll(MINIMAL_COLLECTION.of())); + } + +#ignore + @CollectionSize.Require(absent = ZERO) + public void testContainsAll_subset() { +#endignore + assertTrue("containsAll(subset) should return true", collection.containsAll(MINIMAL_COLLECTION.of(e0()))); + } + + public void testContainsAll_sameElements() { + assertTrue("containsAll(sameElements) should return true", collection.containsAll(MINIMAL_COLLECTION.of(createSamplesArray()))); + } + + public void testContainsAll_self() { + assertTrue("containsAll(this) should return true", collection.containsAll(collection)); + } + + public void testContainsAll_partialOverlap() { + assertFalse("containsAll(partialOverlap) should return false", collection.containsAll(MINIMAL_COLLECTION.of(e0(), e3()))); + } + + public void testContainsAll_disjoint() { + assertFalse("containsAll(disjoint) should return false", collection.containsAll(MINIMAL_COLLECTION.of(e3()))); + } + +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionContainsAnyTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionContainsAnyTester.template new file mode 100644 index 00000000..22dc634b --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionContainsAnyTester.template @@ -0,0 +1,42 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; +import speiger.src.testers.PACKAGE.utils.MINIMAL_COLLECTION; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPECollectionContainsAnyTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ + public void testContainsAny_empty() { + assertFalse("containsAny(empty) should return false", collection.containsAny(MINIMAL_COLLECTION.of())); + } +#ignore + @CollectionSize.Require(absent = ZERO) + public void testContainsAny_subset() { +#endignore + assertTrue("containsAny(subset) should return true", collection.containsAny(MINIMAL_COLLECTION.of(e0()))); + } + +#ignore + @CollectionSize.Require(ONE) + public void testContainsAny_subSetElement() { +#endignore + assertFalse("containsAny(empty) should return false", collection.containsAny(MINIMAL_COLLECTION.of())); + } + +#ignore + @CollectionSize.Require(ONE) + public void testContainsAny_subSetElements() { +#endignore + assertTrue("containsAny(subset) should return true", collection.containsAny(getSampleElements(5))); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionContainsTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionContainsTester.template new file mode 100644 index 00000000..c1e72052 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionContainsTester.template @@ -0,0 +1,27 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPECollectionContainsTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionSize.Require(absent = ZERO) + public void testContains_yes() { + assertTrue("contains(present) should return true", collection.contains(e0())); + } + + public void testContains_no() { + assertFalse("contains(notPresent) should return false", collection.contains(e3())); + } +#endignore +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionCopyTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionCopyTester.template new file mode 100644 index 00000000..b96746c9 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionCopyTester.template @@ -0,0 +1,38 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +import org.junit.Assert; +import org.junit.Ignore; + +import speiger.src.testers.utils.SpecialFeature; +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.utils.COLLECTIONS; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPECollectionCopyTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ +#ignore + @SpecialFeature.Require(SpecialFeature.COPYING) +#endignore + public void testEquals() { + COLLECTION KEY_GENERIC_TYPE copy = collection.copy(); + if(!(collection instanceof COLLECTIONS.EmptyCollection)) { + Assert.assertFalse("Copied Collection shouldn't match", copy == collection); + } + Assert.assertTrue("Copied Collection contents should match", copy.equals(collection)); + } + +#ignore + @SpecialFeature.Require(absent = SpecialFeature.COPYING) +#endignore + public void testEqualsFail() { + try { + assertNull(collection.copy()); + fail("If Copying isn't supported it should throw a UnsupportedOperationException"); + } + catch(UnsupportedOperationException e) { + //Success + } + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionEqualsTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionEqualsTester.template new file mode 100644 index 00000000..b516615d --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionEqualsTester.template @@ -0,0 +1,24 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +import org.junit.Ignore; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPECollectionEqualsTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ + public void testEquals_self() { + assertTrue("An Object should be equal to itself.", collection.equals(collection)); + } + + public void testEquals_null() { + // noinspection ObjectEqualsNull + assertFalse("An object should not be equal to null.", collection.equals(null)); + } + + public void testEquals_notACollection() { + // noinspection EqualsBetweenInconvertibleTypes + assertFalse("A Collection should never equal an object that is not a Collection.", collection.equals("huh?")); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionForEachTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionForEachTester.template new file mode 100644 index 00000000..8a86432a --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionForEachTester.template @@ -0,0 +1,55 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; + +import org.junit.Ignore; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPECollectionForEachTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(absent = KNOWN_ORDER) + public void testForEachUnknownOrder() { +#endignore + LIST KEY_GENERIC_TYPE elements = new ARRAY_LISTBRACES(); + collection.forEach(elements::add); + HELPERS.assertContentsAnyOrder(elements, createSamplesArray()); + } + +#ignore +@CollectionFeature.Require(absent = KNOWN_ORDER) + public void testForEachExtraUnknownOrder() { +#endignore + LIST KEY_GENERIC_TYPE elements = new ARRAY_LISTBRACES(); + collection.forEach(elements, LIST::add); + HELPERS.assertContentsAnyOrder(elements, createSamplesArray()); + } + +#ignore + @CollectionFeature.Require(KNOWN_ORDER) + public void testForEachKnownOrder() { +#endignore + LIST KEY_GENERIC_TYPE elements = new ARRAY_LISTBRACES(); + collection.forEach(elements::add); + assertEquals("Different ordered iteration", HELPERS.copyToList(getOrderedElements()), elements); + } + +#ignore + @CollectionFeature.Require(KNOWN_ORDER) + public void testForEachExtraKnownOrder() { +#endignore + LIST KEY_GENERIC_TYPE elements = new ARRAY_LISTBRACES(); + collection.forEach(elements, LIST::add); + assertEquals("Different ordered iteration", HELPERS.copyToList(getOrderedElements()), elements); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionIteratorTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionIteratorTester.template new file mode 100644 index 00000000..3a643767 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionIteratorTester.template @@ -0,0 +1,161 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +#ignore +import static com.google.common.collect.testing.IteratorFeature.MODIFIABLE; +import static com.google.common.collect.testing.IteratorFeature.UNMODIFIABLE; +import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER; +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ITERATOR_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import java.util.NoSuchElementException; +import java.util.Set; +import java.util.EnumSet; +import java.util.Collections; + +import com.google.common.collect.testing.IteratorFeature; +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import org.junit.Ignore; + +import speiger.src.collections.PACKAGE.collections.ITERABLE; +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; +import speiger.src.collections.PACKAGE.utils.LISTS; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; +import speiger.src.testers.PACKAGE.utils.ITERATOR_TESTER; +import speiger.src.testers.PACKAGE.utils.LIST_ITERATOR_TESTER; +import speiger.src.testers.PACKAGE.utils.BIDIRECTIONAL_ITERATOR_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPECollectionIteratorTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ + public void testIterator() { + LIST KEY_GENERIC_TYPE elements = new ARRAY_LISTBRACES(); + for (ITERATOR KEY_GENERIC_TYPE iter = collection.iterator();iter.hasNext();) { // uses iterator() + elements.add(iter.NEXT()); + } + HELPERS.assertContentsAnyOrder(elements, createSamplesArray()); + } + +#ignore + @CollectionFeature.Require(KNOWN_ORDER) + public void testIterationOrdering() { +#endignore + LIST KEY_GENERIC_TYPE elements = new ARRAY_LISTBRACES(); + for (ITERATOR KEY_GENERIC_TYPE iter = collection.iterator();iter.hasNext();) { // uses iterator() + elements.add(iter.NEXT()); + } + LIST KEY_GENERIC_TYPE expected = HELPERS.copyToList(getOrderedElements()); + assertEquals("Different ordered iteration", expected, elements); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE) + @CollectionSize.Require(absent = ZERO) + public void testIterator_removeAffectsBackingCollection() { +#endignore + int originalSize = collection.size(); + ITERATOR KEY_GENERIC_TYPE iterator = collection.iterator(); + KEY_TYPE element = iterator.NEXT(); + assertTrue(collection.contains(element)); // sanity check + iterator.remove(); + assertFalse(collection.contains(element)); + assertEquals(originalSize - 1, collection.size()); + } + +#ignore + @CollectionFeature.Require({ KNOWN_ORDER, SUPPORTS_ITERATOR_REMOVE }) + public void testIterator_knownOrderRemoveSupported() { +#endignore + runIteratorTest(MODIFIABLE, ITERATOR_TESTER.KnownOrder.KNOWN_ORDER, getOrderedElements()); + } + +#ignore + @CollectionFeature.Require(value = KNOWN_ORDER, absent = SUPPORTS_ITERATOR_REMOVE) + public void testIterator_knownOrderRemoveUnsupported() { +#endignore + runIteratorTest(UNMODIFIABLE, ITERATOR_TESTER.KnownOrder.KNOWN_ORDER, getOrderedElements()); + } + +#ignore + @CollectionFeature.Require(absent = KNOWN_ORDER, value = SUPPORTS_ITERATOR_REMOVE) + public void testIterator_unknownOrderRemoveSupported() { +#endignore + runIteratorTest(MODIFIABLE, ITERATOR_TESTER.KnownOrder.UNKNOWN_ORDER, getSampleElements()); + } + +#ignore + @CollectionFeature.Require(absent = { KNOWN_ORDER, SUPPORTS_ITERATOR_REMOVE }) + public void testIterator_unknownOrderRemoveUnsupported() { +#endignore + runIteratorTest(UNMODIFIABLE, ITERATOR_TESTER.KnownOrder.UNKNOWN_ORDER, getSampleElements()); + } + + private void runIteratorTest(Set features, ITERATOR_TESTER.KnownOrder knownOrder, ITERABLE KEY_GENERIC_TYPE elements) { + if(knownOrder == ITERATOR_TESTER.KnownOrder.KNOWN_ORDER && !(collection instanceof LIST) && collection.iterator() instanceof LIST_ITERATOR) { + Set listFeature = features.isEmpty() ? features : EnumSet.copyOf(features); +#ignore + listFeature.retainAll(EnumSet.of(IteratorFeature.SUPPORTS_REMOVE)); +#endignore + new LIST_ITERATOR_TESTER KEY_GENERIC_TYPE(2, LISTS.singleton(INVALID_VALUE), Collections.unmodifiableSet(listFeature), elements, 0) { + @Override + protected LIST_ITERATOR KEY_GENERIC_TYPE newTargetIterator() { + resetCollection(); + return (LIST_ITERATOR KEY_GENERIC_TYPE)collection.iterator(); + } + + @Override + protected void verify(LIST KEY_GENERIC_TYPE elements) { + expectContents(elements); + } + }.test(); + } + if(collection.iterator() instanceof BI_ITERATOR) { + new BIDIRECTIONAL_ITERATOR_TESTER KEY_GENERIC_TYPE(4, features, elements, knownOrder) { + @Override + protected BI_ITERATOR KEY_GENERIC_TYPE newTargetIterator() { + resetCollection(); + return (BI_ITERATOR KEY_GENERIC_TYPE)collection.iterator(); + } + + @Override + protected void verify(LIST KEY_GENERIC_TYPE elements) { + expectContents(elements); + } + }.test(); + return; + } + new ITERATOR_TESTER KEY_GENERIC_TYPE(5, features, elements, knownOrder) { + @Override + protected ITERATOR KEY_GENERIC_TYPE newTargetIterator() { + resetCollection(); + return collection.iterator(); + } + + @Override + protected void verify(LIST KEY_GENERIC_TYPE elements) { + expectContents(elements); + } + }.test(); + } + + public void testIteratorNoSuchElementException() { + ITERATOR KEY_GENERIC_TYPE iterator = collection.iterator(); + while (iterator.hasNext()) { + iterator.NEXT(); + } + + try { + iterator.NEXT(); + fail("iterator.next() should throw NoSuchElementException"); + } catch (NoSuchElementException expected) { + } + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionRemoveAllTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionRemoveAllTester.template new file mode 100644 index 00000000..7ead2116 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionRemoveAllTester.template @@ -0,0 +1,153 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import java.util.ConcurrentModificationException; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import org.junit.Ignore; + +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; +import speiger.src.testers.PACKAGE.utils.MINIMAL_COLLECTION; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPECollectionRemoveAllTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemoveAll_emptyCollection() { + assertFalse("removeAll(emptyCollection) should return false", collection.removeAll(MINIMAL_COLLECTION.of())); + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemoveAll_nonePresent() { + assertFalse("removeAll(disjointCollection) should return false", collection.removeAll(MINIMAL_COLLECTION.of(e3()))); + expectUnchanged(); + } + + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemoveAll_nonePresentFetchRemoved() { + LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); + assertFalse("removeAll(disjointCollection) should return false", collection.removeAll(MINIMAL_COLLECTION.of(e3()), list::add)); + expectUnchanged(); + assertTrue(list.isEmpty()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemoveAll_emptyCollectionFetching() { + LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); + assertFalse("removeAll(emptyCollection) should return false", collection.removeAll(MINIMAL_COLLECTION.of(), list::add)); + expectUnchanged(); + assertTrue(list.isEmpty()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveAll_allPresent() { + assertTrue("removeAll(intersectingCollection) should return true", collection.removeAll(MINIMAL_COLLECTION.of(e0()))); + expectMissing(e0()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveAll_somePresent() { + assertTrue("removeAll(intersectingCollection) should return true", collection.removeAll(MINIMAL_COLLECTION.of(e0(), e3()))); + expectMissing(e0()); + } + +#ignore + @CollectionFeature.Require({ SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION }) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemoveAllSomePresentConcurrentWithIteration() { + try { + ITERATOR KEY_GENERIC_TYPE iterator = collection.iterator(); + assertTrue(collection.removeAll(MINIMAL_COLLECTION.of(e0(), e3()))); + iterator.NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveAll_somePresentLargeCollectionToRemove() { + assertTrue("removeAll(largeIntersectingCollection) should return true", collection.removeAll(MINIMAL_COLLECTION.of(e0(), e0(), e0(), e3(), e3(), e3()))); + expectMissing(e0()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveAll_someFetchRemovedElements() { + LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); + assertTrue("removeAll(largeIntersectingCollection, RemovedElements) should return true", collection.removeAll(MINIMAL_COLLECTION.of(e0(), e0(), e0(), e3(), e3(), e3()), list::add)); + expectMissing(e0()); + HELPERS.assertContentsAnyOrder(list, e0()); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testRemoveAll_unsupportedEmptyCollection() { + try { + assertFalse("removeAll(emptyCollection) should return false or throw UnsupportedOperationException", collection.removeAll(MINIMAL_COLLECTION.of())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testRemoveAll_unsupportedNonePresent() { + try { + assertFalse("removeAll(disjointCollection) should return false or throw UnsupportedOperationException", collection.removeAll(MINIMAL_COLLECTION.of(e3()))); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveAll_unsupportedPresent() { + try { + collection.removeAll(MINIMAL_COLLECTION.of(e0())); + fail("removeAll(intersectingCollection) should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + assertTrue(collection.contains(e0())); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionRemoveIfTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionRemoveIfTester.template new file mode 100644 index 00000000..a801e60f --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionRemoveIfTester.template @@ -0,0 +1,119 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import java.util.ConcurrentModificationException; +#if TYPE_OBJECT +import java.util.Objects; +#endif + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import org.junit.Ignore; + +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPECollectionRemoveIfTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemoveIf_alwaysFalse() { +#if TYPE_OBJECT + assertFalse("remoIf(x -> false) should return false", collection.removeIf(x -> false)); +#else + assertFalse("remoIf(x -> false) should return false", collection.remIf(x -> false)); +#endif + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveIf_sometimesTrue() { + assertTrue("remIf(isEqual(present)) should return true", +#if TYPE_OBJECT + collection.removeIf(T -> Objects.equals(T, e0()))); +#else + collection.remIf(T -> T == e0())); +#endif + expectMissing(samples.e0()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveIf_allPresent() { +#if TYPE_OBJECT + assertTrue("remIf(x -> true) should return true", collection.removeIf(x -> true)); +#else + assertTrue("remIf(x -> true) should return true", collection.remIf(x -> true)); +#endif + expectContents(); + } + +#ignore + @CollectionFeature.Require({ SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION }) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemoveIfSomeMatchesConcurrentWithIteration() { + try { + ITERATOR KEY_GENERIC_TYPE iterator = collection.iterator(); +#if TYPE_OBJECT + assertTrue(collection.removeIf(T -> Objects.equals(T, e0()))); +#else + assertTrue(collection.remIf(T -> T == e0())); +#endif + iterator.NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) +#endignore + public void testRemoveIf_unsupportedEmptyCollection() { + try { + assertFalse("remIf(Predicate) should return false or throw UnsupportedOperationException", +#if TYPE_OBJECT + collection.removeIf(x -> {throw new AssertionError("predicate should never be called");})); +#else + collection.remIf(x -> {throw new AssertionError("predicate should never be called");})); +#endif + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveIf_alwaysTrueUnsupported() { + try { +#if TYPE_OBJECT + collection.removeIf(x -> true); +#else + collection.remIf(x -> true); + fail("remIf(x -> true) should throw " + "UnsupportedOperationException"); +#endif + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + assertTrue(collection.contains(samples.e0())); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionRetainAllTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionRetainAllTester.template new file mode 100644 index 00000000..184f8fdd --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionRetainAllTester.template @@ -0,0 +1,337 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import org.junit.Ignore; + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; +import speiger.src.testers.PACKAGE.utils.MINIMAL_COLLECTION; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPECollectionRetainAllTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ + + private class Target { + private final COLLECTION KEY_GENERIC_TYPE toRetain; + private final COLLECTION KEY_GENERIC_TYPE inverse = ARRAY_LIST.wrap(createSamplesArray()); + private final String description; + + private Target(COLLECTION KEY_GENERIC_TYPE toRetain, String description) { + this.toRetain = toRetain; + inverse.removeAll(toRetain); + this.description = description; + } + + @Override + public String toString() { + return description; + } + } + + private Target empty; + private Target disjoint; + private Target superset; + private Target nonEmptyProperSubset; + private Target sameElements; + private Target partialOverlap; + private Target containsDuplicates; + + @Override + public void setUp() throws Exception { + super.setUp(); + + empty = new Target(emptyCollection(), "empty"); + disjoint = new Target(ARRAY_LIST.wrap(e3(), e4()), "disjoint"); + superset = new Target(MINIMAL_COLLECTION.of(e0(), e1(), e2(), e3(), e4()), "superset"); + nonEmptyProperSubset = new Target(MINIMAL_COLLECTION.of(e1()), "subset"); + sameElements = new Target(ARRAY_LIST.wrap(createSamplesArray()), "sameElements"); + containsDuplicates = new Target(MINIMAL_COLLECTION.of(e0(), e0(), e3(), e3()), "containsDuplicates"); + partialOverlap = new Target(MINIMAL_COLLECTION.of(e2(), e3()), "partialOverlap"); + } + + // retainAll(empty) +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) + public void testRetainAll_emptyPreviouslyEmpty() { + expectReturnsFalse(empty); + expectUnchanged(); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) + public void testRetainAllExtra_emptyPreviouslyEmpty() { + expectReturnsFalseExtra(empty); + expectUnchanged(); + } + + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) + public void testRetainAll_emptyPreviouslyEmptyUnsupported() { + expectReturnsFalseOrThrows(empty); + expectUnchanged(); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) + public void testRetainAll_emptyPreviouslyNonEmpty() { + expectReturnsTrue(empty); + expectContents(); + expectMissing(e0(), e1(), e2()); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) + public void testRetainAllExtra_emptyPreviouslyNonEmpty() { + expectReturnsTrueExtra(empty); + expectContents(); + expectMissing(e0(), e1(), e2()); + } + + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) + public void testRetainAll_emptyPreviouslyNonEmptyUnsupported() { + expectThrows(empty); + expectUnchanged(); + } + + // retainAll(disjoint) + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) + public void testRetainAll_disjointPreviouslyEmpty() { + expectReturnsFalse(disjoint); + expectUnchanged(); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) + public void testRetainAllExtra_disjointPreviouslyEmpty() { + expectReturnsFalseExtra(disjoint); + expectUnchanged(); + } + + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) + public void testRetainAll_disjointPreviouslyEmptyUnsupported() { + expectReturnsFalseOrThrows(disjoint); + expectUnchanged(); + } +#endignore +#if !TYPE_BOOLEAN +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRetainAll_disjointPreviouslyNonEmpty() { + expectReturnsTrue(disjoint); + expectContents(); + expectMissing(e0(), e1(), e2()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRetainAllExtra_disjointPreviouslyNonEmpty() { + expectReturnsTrueExtra(disjoint); + expectContents(); + expectMissing(e0(), e1(), e2()); + } + +#endif +#ignore + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) + public void testRetainAll_disjointPreviouslyNonEmptyUnsupported() { + expectThrows(disjoint); + expectUnchanged(); + } + + // retainAll(superset) + + @CollectionFeature.Require(SUPPORTS_REMOVE) + public void testRetainAll_superset() { + expectReturnsFalse(superset); + expectUnchanged(); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + public void testRetainAllExtra_superset() { + expectReturnsFalseExtra(superset); + expectUnchanged(); + } + + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) + public void testRetainAll_supersetUnsupported() { + expectReturnsFalseOrThrows(superset); + expectUnchanged(); + } + + // retainAll(subset) + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = { ZERO, ONE }) + public void testRetainAll_subset() { + expectReturnsTrue(nonEmptyProperSubset); + expectContents(nonEmptyProperSubset.toRetain); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = { ZERO, ONE }) + public void testRetainAllExtra_subset() { + expectReturnsTrueExtra(nonEmptyProperSubset); + expectContents(nonEmptyProperSubset.toRetain); + } + + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(absent = { ZERO, ONE }) + public void testRetainAll_subsetUnsupported() { + expectThrows(nonEmptyProperSubset); + expectUnchanged(); + } + + // retainAll(sameElements) + + @CollectionFeature.Require(SUPPORTS_REMOVE) + public void testRetainAll_sameElements() { + expectReturnsFalse(sameElements); + expectUnchanged(); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + public void testRetainAllExtra_sameElements() { + expectReturnsFalseExtra(sameElements); + expectUnchanged(); + } + + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) + public void testRetainAll_sameElementsUnsupported() { + expectReturnsFalseOrThrows(sameElements); + expectUnchanged(); + } + + // retainAll(partialOverlap) + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = { ZERO, ONE }) + public void testRetainAll_partialOverlap() { + expectReturnsTrue(partialOverlap); + expectContents(e2()); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = { ZERO, ONE }) + public void testRetainAllExtra_partialOverlap() { + expectReturnsTrueExtra(partialOverlap); + expectContents(e2()); + } + + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(absent = { ZERO, ONE }) + public void testRetainAll_partialOverlapUnsupported() { + expectThrows(partialOverlap); + expectUnchanged(); + } + + // retainAll(containsDuplicates) + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ONE) + public void testRetainAll_containsDuplicatesSizeOne() { + expectReturnsFalse(containsDuplicates); + expectContents(e0()); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ONE) + public void testRetainAllExtra_containsDuplicatesSizeOne() { + expectReturnsFalseExtra(containsDuplicates); + expectContents(e0()); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = { ZERO, ONE }) + public void testRetainAll_containsDuplicatesSizeSeveral() { + expectReturnsTrue(containsDuplicates); + expectContents(e0()); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = { ZERO, ONE }) + public void testRetainAllExtra_containsDuplicatesSizeSeveral() { + expectReturnsTrueExtra(containsDuplicates); + expectContents(e0()); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) + public void testRetainAll_nullCollectionReferenceEmptySubject() { + try { + collection.retainAll(null); + // Returning successfully is not ideal, but tolerated. + } catch (NullPointerException tolerated) { + } + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) + public void testRetainAll_nullCollectionReferenceNonEmptySubject() { + try { + collection.retainAll(null); + fail("retainAll(null) should throw NullPointerException"); + } catch (NullPointerException expected) { + } + } + +#endignore + private void expectReturnsTrue(Target target) { + String message = String.format("retainAll(%s) should return true", target); + assertTrue(message, collection.retainAll(target.toRetain)); + } + + private void expectReturnsTrueExtra(Target target) { + String message = String.format("retainAll(%s, Removed) should return true", target); + LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); + assertTrue(message, collection.retainAll(target.toRetain, list::add)); + HELPERS.assertEqualIgnoringOrder(target.inverse, list); + } + + private void expectReturnsFalse(Target target) { + String message = String.format("retainAll(%s) should return false", target); + assertFalse(message, collection.retainAll(target.toRetain)); + } + + private void expectReturnsFalseExtra(Target target) { + String message = String.format("retainAll(%s, Removed) should return false", target); + assertFalse(message, collection.retainAll(target.toRetain, T -> {})); + } + + private void expectThrows(Target target) { + try { + collection.retainAll(target.toRetain); + fail(String.format("retainAll(%s) should throw", target)); + } catch (UnsupportedOperationException expected) { + } + } + + private void expectReturnsFalseOrThrows(Target target) { + String message = String.format("retainAll(%s) should return false or throw", target); + try { + assertFalse(message, collection.retainAll(target.toRetain)); + } catch (UnsupportedOperationException tolerated) { + } + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionStreamTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionStreamTester.template new file mode 100644 index 00000000..a5508d6c --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/collection/CollectionStreamTester.template @@ -0,0 +1,59 @@ +package speiger.src.testers.PACKAGE.tests.collection; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; + +import org.junit.Ignore; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +#if !JDK_TYPE +import speiger.src.collections.utils.SanityChecks; +#endif +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPECollectionStreamTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(absent = KNOWN_ORDER) + public void testStreamToArrayUnknownOrder() { +#endignore + synchronized (collection) { + HELPERS.assertContentsAnyOrder(getSampleElements(), unwrap(collection.primitiveStream().toArray())); + } + } + +#ignore + @CollectionFeature.Require(KNOWN_ORDER) + public void testStreamToArrayKnownOrder() { +#endignore + synchronized (collection) { + assertEquals(getOrderedElements(), ARRAY_LIST.wrap(unwrap(collection.primitiveStream().toArray()))); + } + } + + public void testStreamCount() { + synchronized (collection) { + assertEquals(getNumElements(), collection.primitiveStream().count()); + } + } + +#if JDK_TYPE + public KEY_TYPE[] unwrap(KEY_TYPE[] input) { + return input; + } +#else + public KEY_TYPE[] unwrap(KEY_JAVA_TYPE[] input) { + KEY_TYPE[] other = NEW_KEY_ARRAY(input.length); + for(int i = 0,m=input.length;i false)); + } + + public void testIterableCount_AllFound() { + assertEquals("Expected All to be found", getNumElements(), collection.count(T -> true)); + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testIterableCount_FindFirst() + { + assertEquals("First element should be found", 1, collection.count(T -> KEY_EQUALS(T, e0()))); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testIterableCount_FindLast() { + assertEquals("Last element should be found", 1, collection.count(T -> KEY_EQUALS(T, e2()))); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableDistinctTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableDistinctTester.template new file mode 100644 index 00000000..8e7c0b59 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableDistinctTester.template @@ -0,0 +1,24 @@ +package speiger.src.testers.PACKAGE.tests.iterable; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEIterableDistinctTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testDistinct() + { + ArrayWithDuplicate KEY_GENERIC_TYPE duplicate = createArrayWithDuplicateElement(); + resetContainer(primitiveGenerator.create(duplicate.elements)); + LIST KEY_GENERIC_TYPE list = collection.distinct().pourAsList(); + assertEquals("Distinct should remove duplicate elements", list.indexOf(duplicate.duplicate), list.lastIndexOf(duplicate.duplicate)); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableFilterTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableFilterTester.template new file mode 100644 index 00000000..cb2efdb1 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableFilterTester.template @@ -0,0 +1,52 @@ +package speiger.src.testers.PACKAGE.tests.iterable; + +#if TYPE_OBJECT +import java.util.Objects; + +#endif +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.sets.SET; +import speiger.src.collections.PACKAGE.utils.SETS; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEIterableFilterTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ + public void testIterableFilter_missingElement() { + assertTrue(expectMissing(collection.filter(T -> KEY_EQUALS_NOT(T, e0())).pourAsSet(), e0())); + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testIterableFilter_filterElement() { + assertFalse(expectMissing(SETS.singleton(e0()), collection.filter(T -> KEY_EQUALS(T, e0())).pourAsSet().TO_ARRAY())); + } + +#ignore + @CollectionSize.Require(CollectionSize.ONE) +#endignore + public void testIterableFilter_filterMissing() { + assertTrue(collection.filter(T -> KEY_EQUALS(T, e1())).pourAsList().isEmpty()); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testIterableFilter_filterSeveral() { + assertTrue(expectMissing(SETS.singleton(e1()), collection.filter(T -> KEY_EQUALS_NOT(T, e1())).pourAsSet().TO_ARRAY())); + } + + protected boolean expectMissing(SET KEY_GENERIC_TYPE set, KEY_OBJECT_TYPE...elements) + { + for(KEY_OBJECT_TYPE element : elements) + { + if(set.contains(element)) return false; + } + return true; + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableFindFirstTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableFindFirstTester.template new file mode 100644 index 00000000..a096c13a --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableFindFirstTester.template @@ -0,0 +1,43 @@ +package speiger.src.testers.PACKAGE.tests.iterable; + +#if TYPE_OBJECT +import java.util.Objects; + +#endif +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEIterableFindFirstTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ + public void testIterableFindFirst_null() { + try { + container.findFirst(null); + fail("This should throw a NullPointerException"); + } + catch (NullPointerException e) { + } + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testIterableFindFirst_FindFirstElements() { + assertEquals("First Element should be found", e0(), container.findFirst(T -> KEY_EQUALS(T, e0()))); + } + + public void testIterableFindFirst_FindNothing() { + assertEquals("No element should be found", EMPTY_KEY_VALUE, container.findFirst(T -> KEY_EQUALS(T, e4()))); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testIterableFindFirst_FindLastElement() { + assertEquals("Last Element should be found", e2(), container.findFirst(T -> KEY_EQUALS(T, e2()))); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableLimitTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableLimitTester.template new file mode 100644 index 00000000..7e189a61 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableLimitTester.template @@ -0,0 +1,25 @@ +package speiger.src.testers.PACKAGE.tests.iterable; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEIterableLimitTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testIterableLimit() { + LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(collection); + list.REMOVE(list.size()-1); + LIST KEY_GENERIC_TYPE result = collection.limit(getNumElements()-1).pourAsList(); + assertEquals(list.size(), result.size()); + assertEquals("Limit does not retain the iteration order", list, result); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableMapTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableMapTester.template new file mode 100644 index 00000000..de3ac300 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableMapTester.template @@ -0,0 +1,132 @@ +package speiger.src.testers.PACKAGE.tests.iterable; + +#if TYPE_OBJECT +import java.util.Objects; +#endif + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionFeature; + +#if TYPE_OBJECT +import speiger.src.collections.chars.utils.CharArrays; +#endif +import speiger.src.collections.objects.lists.ObjectArrayList; +import speiger.src.collections.objects.lists.ObjectList; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; +#if !TYPE_OBJECT +import speiger.src.testers.objects.utils.ObjectHelpers; +#endif + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEIterableMapTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ + public void testIterableMap_ToString() { + assertEquals(HELPERS.copyToList(collection).toString(), collection.map(CLASS_OBJECT_TYPE::toString).pourAsList().toString()); + } +#if !TYPE_OBJECT + +#ignore + @CollectionFeature.Require(CollectionFeature.KNOWN_ORDER) +#endignore + public void testIterableMap_Collection() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange((int)entry)); + } + assertEquals(result, collection.flatMap(T -> ObjectArrayList.wrap(toRange((int)T))).pourAsList()); + } + +#ignore + @CollectionFeature.Require(CollectionFeature.KNOWN_ORDER) +#endignore + public void testIterableMap_Array() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange((int)entry)); + } + assertEquals(result, collection.arrayflatMap(T -> toRange((int)T)).pourAsList()); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.KNOWN_ORDER) +#endignore + public void testIterableMap_CollectionUnordered() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange((int)entry)); + } + ObjectHelpers.assertEqualIgnoringOrder(result, collection.flatMap(T -> ObjectArrayList.wrap(toRange((int)T))).pourAsList()); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.KNOWN_ORDER) +#endignore + public void testIterableMap_ArrayUnordered() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange((int)entry)); + } + ObjectHelpers.assertEqualIgnoringOrder(result, collection.arrayflatMap(T -> toRange((int)T)).pourAsList()); + } + + private Integer[] toRange(int range) { + Integer[] result = new Integer[range]; + for(int i = 0;i result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange(entry)); + } + assertEquals(result, collection.flatMap(T -> ObjectArrayList.wrap(toRange(T))).pourAsList()); + } + +#ignore + @CollectionFeature.Require(CollectionFeature.KNOWN_ORDER) +#endignore + public void testIterableMap_Array() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange(entry)); + } + assertEquals(result, collection.arrayflatMap(this::toRange).pourAsList()); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.KNOWN_ORDER) +#endignore + public void testIterableMap_CollectionUnordered() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange(entry)); + } + ObjectHelpers.assertEqualIgnoringOrder(result, collection.flatMap(T -> ObjectArrayList.wrap(toRange(T))).pourAsList()); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.KNOWN_ORDER) +#endignore + public void testIterableMap_ArrayUnordered() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange(entry)); + } + ObjectHelpers.assertEqualIgnoringOrder(result, collection.arrayflatMap(this::toRange).pourAsList()); + } + + private Character[] toRange(T obj) { + return CharArrays.wrap(Objects.toString(obj).toCharArray()); + } +#endif +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableMatchesTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableMatchesTester.template new file mode 100644 index 00000000..8c188e11 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableMatchesTester.template @@ -0,0 +1,107 @@ +package speiger.src.testers.PACKAGE.tests.iterable; + +#if TYPE_OBJECT +import java.util.Objects; + +#endif +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.sets.HASH_SET; +import speiger.src.collections.PACKAGE.sets.SET; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEIterableMatchesTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ + public void testIterableMatch_AnyNull() { + try { + collection.matchesAny(null); + fail("MatchesAny should throw a NullPointException"); + } + catch (NullPointerException e) { + } + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testIterableMatch_AnyFoundFirstElement() { + assertTrue("Element ["+e0()+"] should be found", collection.matchesAny(T -> KEY_EQUALS(T, e0()))); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testIterableMatch_AnyFoundLastElement() { + assertTrue("Element ["+e2()+"] should be found", collection.matchesAny(T -> KEY_EQUALS(T, e2()))); + } + + public void testIterableMatch_AnyFoundNoElement() { + assertFalse("Element ["+e4()+"] should not be found", collection.matchesAny(T -> KEY_EQUALS(T, e4()))); + } + + public void testIterableMatch_NoneNull() { + try { + collection.matchesNone(null); + fail("MatchesNone should throw a NullPointException"); + } + catch (NullPointerException e) { + } + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testIterableMatch_NoneFoundFirstElement() { + assertFalse("Element ["+e0()+"] should not be found", collection.matchesNone(T -> KEY_EQUALS(T, e0()))); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testIterableMatch_NoneFoundLastElement() { + assertFalse("Element ["+e2()+"] should not be found", collection.matchesNone(T -> KEY_EQUALS(T, e2()))); + } + + public void testIterableMatch_NoneFoundNoElement() { + assertTrue("Element ["+e4()+"] should not be found", collection.matchesNone(T -> KEY_EQUALS(T, e4()))); + } + + public void testIterableMatch_AllNull() { + try { + collection.matchesAll(null); + fail("MatchesAny should throw a NullPointException"); + } + catch (NullPointerException e) { + } + } + + public void testIterableMatch_AllFoundAllElements() { + SET KEY_GENERIC_TYPE set = new HASH_SETBRACES(collection); + assertTrue("All elements should be found", collection.matchesAll(set::contains)); + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testIterableMatch_AllFoundNone() { + assertFalse("It should not find anything", collection.matchesAll(T -> false)); + } + +#ignore + @CollectionSize.Require(CollectionSize.ZERO) +#endignore + public void testIterableMatch_AllFoundNoneEmpty() { + assertTrue("Empty Collections should return true even if all have to be found", collection.matchesAll(T -> false)); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testIterableMatches_AllPartical() { + assertFalse("Even if some elements were found, it should return false", collection.matchesAll(T -> KEY_EQUALS(T, e0()))); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterablePeekTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterablePeekTester.template new file mode 100644 index 00000000..fcd76961 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterablePeekTester.template @@ -0,0 +1,19 @@ +package speiger.src.testers.PACKAGE.tests.iterable; + +import org.junit.Ignore; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEIterablePeekTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ + public void testIterablePeek() { + LIST KEY_GENERIC_TYPE peeked = new ARRAY_LISTBRACES(); + LIST KEY_GENERIC_TYPE result = new ARRAY_LISTBRACES(); + collection.peek(peeked::add).forEach(result::add); + assertEquals("Collections should match since peek is just a preview of foreach", result, peeked); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableReduceTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableReduceTester.template new file mode 100644 index 00000000..ffc5a7b1 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableReduceTester.template @@ -0,0 +1,78 @@ +package speiger.src.testers.PACKAGE.tests.iterable; + +#if TYPE_OBJECT +import java.util.Objects; + +#endif +import org.junit.Ignore; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEIterableReduceTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ + public void testIterableReduce_Null() { + try { + collection.reduce(null); + fail("This should crash"); + } catch (NullPointerException e) { + } + } + + public void testIterableReduce_extraNull() { + try { + collection.reduce(EMPTY_KEY_VALUE, null); + fail("This should crash"); + } catch (NullPointerException e) { + } + } + + public void testIterableReduce() { + assertEquals("The sum of the collection should match", getSum(), collection.reduce(this::sum)); + } + + public void testIterableExtraReduce() { +#if TYPE_OBJECT + assertEquals("The sum of the collection should match", getObjectSum(), collection.reduce(new StringBuilder(), this::sum).toString()); +#else + assertEquals("The sum of the collection should match", getSum(), collection.reduce(EMPTY_KEY_VALUE, this::sum)); +#endif + } + + public KEY_TYPE getSum() + { + KEY_TYPE result = EMPTY_KEY_VALUE; + for(KEY_TYPE key : collection) + { + result = sum(result, key); + } + return result; + } + + public KEY_TYPE sum(KEY_TYPE key, KEY_TYPE value) + { +#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR + return (KEY_TYPE)(key + value); +#else if TYPE_OBJECT + return value; +#else + return key + value; +#endif + } + +#if TYPE_OBJECT + public StringBuilder sum(StringBuilder builder, T value) { + return builder.append(Objects.toString(value)); + } + + public String getObjectSum() { + StringBuilder builder = new StringBuilder(); + for(T key : collection) + { + builder = sum(builder, key); + } + return builder.toString(); + } +#endif +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableSortedTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableSortedTester.template new file mode 100644 index 00000000..fc20fa50 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/iterable/IterableSortedTester.template @@ -0,0 +1,43 @@ +package speiger.src.testers.PACKAGE.tests.iterable; + +import org.junit.Ignore; + +#if TYPE_OBJECT +import java.util.Comparator; +import java.util.Map; +#endif + +import com.google.common.collect.testing.features.CollectionFeature; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_COLLECTION_TESTER; +import speiger.src.testers.utils.SpecialFeature; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEIterableSortedTester KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(absent = CollectionFeature.KNOWN_ORDER) + @SpecialFeature.Require(absent = SpecialFeature.MAP_ENTRY) +#endignore + public void testIterableSorted() { + LIST KEY_GENERIC_TYPE expected = new ARRAY_LISTBRACES(collection); + expected.sort(null); + assertEquals("Elements were expected to be sorted", expected, collection.sorted(null).pourAsList()); + } + +#if TYPE_OBJECT +#ignore + @CollectionFeature.Require(absent = CollectionFeature.KNOWN_ORDER) + @SpecialFeature.Require(SpecialFeature.MAP_ENTRY) +#endignore + public void testIterableSortedEntry() { + ObjectList expected = new ObjectArrayList<>(collection); + Comparator comparator = Comparator.comparing(T -> (Comparable)((Map.Entry)T).getKey()); + expected.sort(comparator); + assertEquals("Elements were expected to be sorted", expected, collection.sorted(comparator).pourAsList()); + } +#endif +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAbsentTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAbsentTester.template new file mode 100644 index 00000000..a52f19eb --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAbsentTester.template @@ -0,0 +1,60 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListAbsentTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(ONE) +#endignore + public void testIfAbsent() { + assertTrue("addIfAbsent(absent) should return true", getList().addIfAbsent(e1())); + expectAdded(e1()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(ONE) +#endignore + public void testIfPresent() { + assertFalse("addIfAbsent(present) should return false", getList().addIfAbsent(e0())); + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_ADD) + @CollectionSize.Require(ONE) +#endignore + public void test_IfAbsentUnsupported() { + try { + assertFalse("addIfAbsent(absent) should return false", getList().addIfAbsent(e1())); + } catch (UnsupportedOperationException e) { + //Success + } + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_ADD) + @CollectionSize.Require(ONE) +#endignore + public void test_IfPresentUnsupported() { + try { + assertFalse("addIfAbsent(present) should return false", getList().addIfAbsent(e0())); + } catch (UnsupportedOperationException e) { + //Success + } + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllArrayAtIndexTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllArrayAtIndexTester.template new file mode 100644 index 00000000..1c86ab2f --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllArrayAtIndexTester.template @@ -0,0 +1,194 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#if !TYPE_BOOLEAN +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; +#endignore +#endif +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_ADD_WITH_INDEX; +#endignore + +#if !TYPE_BOOLEAN +import com.google.common.collect.testing.features.CollectionFeature; +#endif +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.ListFeature; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListAddAllArrayAtIndexTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllArrayAtIndex_supportedAllPresent() { + getList().addElements(0, createArray(e0())); + expectAddedIndex(0, e0()); + } + +#ignore + @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllArrayAtIndex_unsupportedAllPresent() { + try { + getList().addElements(0, createArray(e0())); + fail("addAll(n, allPresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllArrayAtIndex_supportedSomePresent() { + getList().addElements(0, createArray(e0(), e3())); + expectAddedIndex(0, e0(), e3()); + } + +#ignore + @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllArrayAtIndex_unsupportedSomePresent() { + try { + getList().addElements(0, createArray(e0(), e3())); + fail("addAll(n, allPresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + expectMissing(e3()); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllArrayAtIndex_supportedNothing() { + getList().addElements(0, emptyArray()); + expectUnchanged(); + } + +#ignore + @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllArrayAtIndex_unsupportedNothing() { + try { + getList().addElements(0, emptyArray()); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllArrayAtIndex_withDuplicates() { + getList().addElements(0, createArray(e0(), e1(), e0(), e1())); + expectAddedIndex(0, e0(), e1(), e0(), e1()); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testAddAllArrayAtIndex_middle() { + getList().addElements(getNumElements() / 2, createDisjointArray()); + expectAdded(getNumElements() / 2, createDisjointCollection()); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllArrayAtIndex_end() { + getList().addElements(getNumElements(), createDisjointArray()); + expectAdded(getNumElements(), createDisjointCollection()); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllArrayAtIndex_nullCollectionReference() { + try { +#if TYPE_OBJECT + getList().addElements(0, (T[])null); +#else + getList().addElements(0, null); +#endif + fail("addElements(n, null) should throw"); + } catch (NullPointerException expected) { + } + expectUnchanged(); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllArrayAtIndex_negative() { + try { + getList().addElements(-1, createArray(e3())); + fail("addElements(-1, e) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + expectUnchanged(); + expectMissing(e3()); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllArrayAtIndex_tooLarge() { + try { + getList().addElements(getNumElements() + 1, createArray(e3())); + fail("addElements(size + 1, e) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + expectUnchanged(); + expectMissing(e3()); + } + +#if !TYPE_BOOLEAN +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) +#endignore + public void testAddAllArray_supportedToLargeOffset() { + try { + getList().addElements(0, createDisjointArray(), 5, 2); + } catch (IndexOutOfBoundsException e) { + } + expectUnchanged(); + expectMissing(e3(), e4()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) +#endignore + public void testAddAllArray_supportedToSmallOffset() { + try { + getList().addElements(0, createDisjointArray(), -1, 2); + } catch (IndexOutOfBoundsException e) { + } + expectUnchanged(); + expectMissing(e3(), e4()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) +#endignore + public void testAddAllArray_supportedAddSubArray() { + getList().addElements(0, createDisjointArray(), 0, 1); + expectAddedIndex(0, e3()); + expectMissing(e4()); + } +#endif +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllAtIndexTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllAtIndexTester.template new file mode 100644 index 00000000..b737861a --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllAtIndexTester.template @@ -0,0 +1,167 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_ADD_WITH_INDEX; +#endignore + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.ListFeature; + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; +import speiger.src.testers.PACKAGE.utils.MINIMAL_COLLECTION; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListAddAllAtIndexTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllAtIndex_supportedAllPresent() { + assertTrue("addAll(n, allPresent) should return true", getList().addAll(0, MINIMAL_COLLECTION.of(e0()))); + expectAddedIndex(0, e0()); + } + +#ignore + @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllAtIndex_unsupportedAllPresent() { + try { + getList().addAll(0, MINIMAL_COLLECTION.of(e0())); + fail("addAll(n, allPresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllAtIndex_supportedSomePresent() { + assertTrue("addAll(n, allPresent) should return true", getList().addAll(0, MINIMAL_COLLECTION.of(e0(), e3()))); + expectAddedIndex(0, e0(), e3()); + } + +#ignore + @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllAtIndex_unsupportedSomePresent() { + try { + getList().addAll(0, MINIMAL_COLLECTION.of(e0(), e3())); + fail("addAll(n, allPresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + expectMissing(e3()); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllAtIndex_supportedNothing() { + assertFalse("addAll(n, nothing) should return false", getList().addAll(0, emptyCollection())); + expectUnchanged(); + } + +#ignore + @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllAtIndex_unsupportedNothing() { + try { + assertFalse("addAll(n, nothing) should return false or throw", getList().addAll(0, emptyCollection())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllAtIndex_withDuplicates() { + MINIMAL_COLLECTION KEY_GENERIC_TYPE elementsToAdd = MINIMAL_COLLECTION.of(e0(), e1(), e0(), e1()); + assertTrue("addAll(n, hasDuplicates) should return true", getList().addAll(0, elementsToAdd)); + expectAddedIndex(0, e0(), e1(), e0(), e1()); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testAddAllAtIndex_middle() { + assertTrue("addAll(middle, disjoint) should return true", getList().addAll(getNumElements() / 2, createDisjointCollection())); + expectAdded(getNumElements() / 2, createDisjointCollection()); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllAtIndex_end() { + assertTrue("addAll(end, disjoint) should return true", getList().addAll(getNumElements(), createDisjointCollection())); + expectAdded(getNumElements(), createDisjointCollection()); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllAtIndex_nullCollectionReference() { + try { + getList().addAll(0, (COLLECTION KEY_GENERIC_TYPE)null); + fail("addAll(n, null) should throw"); + } catch (NullPointerException expected) { + } + expectUnchanged(); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllAtIndex_nullListReference() { + try { + getList().addAll(0, (LIST KEY_GENERIC_TYPE)null); + fail("addAll(n, null) should throw"); + } catch (NullPointerException expected) { + } + expectUnchanged(); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllAtIndex_negative() { + try { + getList().addAll(-1, MINIMAL_COLLECTION.of(e3())); + fail("addAll(-1, e) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + expectUnchanged(); +#if !TYPE_BOOLEAN + expectMissing(e3()); +#endif + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllAtIndex_tooLarge() { + try { + getList().addAll(getNumElements() + 1, MINIMAL_COLLECTION.of(e3())); + fail("addAll(size + 1, e) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + expectUnchanged(); +#if !TYPE_BOOLEAN + expectMissing(e3()); +#endif + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllListAtIndexTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllListAtIndexTester.template new file mode 100644 index 00000000..b2807762 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllListAtIndexTester.template @@ -0,0 +1,155 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_ADD_WITH_INDEX; +#endignore + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.ListFeature; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListAddAllListAtIndexTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllListAtIndex_supportedAllPresent() { + assertTrue("addAll(n, allPresent) should return true", getList().addAll(0, ARRAY_LIST.wrap(e0()))); + expectAddedIndex(0, e0()); + } + +#ignore + @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllListAtIndex_unsupportedAllPresent() { + try { + getList().addAll(0, ARRAY_LIST.wrap(e0())); + fail("addAll(n, allPresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllListAtIndex_supportedSomePresent() { + assertTrue("addAll(n, allPresent) should return true", getList().addAll(0, ARRAY_LIST.wrap(e0(), e3()))); + expectAddedIndex(0, e0(), e3()); + } + +#ignore + @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllListAtIndex_unsupportedSomePresent() { + try { + getList().addAll(0, ARRAY_LIST.wrap(e0(), e3())); + fail("addAll(n, allPresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); +#if !TYPE_BOOLEAN + expectMissing(e3()); +#endif + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllListAtIndex_supportedNothing() { + assertFalse("addAll(n, nothing) should return false", getList().addAll(0, new ARRAY_LISTBRACES())); + expectUnchanged(); + } + +#ignore + @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllListAtIndex_unsupportedNothing() { + try { + assertFalse("addAll(n, nothing) should return false or throw", getList().addAll(0, new ARRAY_LISTBRACES())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllListAtIndex_withDuplicates() { + assertTrue("addAll(n, hasDuplicates) should return true", getList().addAll(0, ARRAY_LIST.wrap(e0(), e1(), e0(), e1()))); + expectAddedIndex(0, e0(), e1(), e0(), e1()); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testAddAllListAtIndex_middle() { + assertTrue("addAll(middle, disjoint) should return true", getList().addAll(getNumElements() / 2, new ARRAY_LISTBRACES(createDisjointCollection()))); + expectAdded(getNumElements() / 2, createDisjointCollection()); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllListAtIndex_end() { + assertTrue("addAll(end, disjoint) should return true", getList().addAll(getNumElements(), new ARRAY_LISTBRACES(createDisjointCollection()))); + expectAdded(getNumElements(), createDisjointCollection()); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllListAtIndex_nullListReference() { + try { + getList().addAll(0, (LIST KEY_GENERIC_TYPE)null); + fail("addAll(n, null) should throw"); + } catch (NullPointerException expected) { + } + expectUnchanged(); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllListAtIndex_negative() { + try { + getList().addAll(-1, ARRAY_LIST.wrap(e3())); + fail("addAll(-1, e) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + expectUnchanged(); +#if !TYPE_BOOLEAN + expectMissing(e3()); +#endif + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAllListAtIndex_tooLarge() { + try { + getList().addAll(getNumElements() + 1, ARRAY_LIST.wrap(e3())); + fail("addAll(size + 1, e) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + expectUnchanged(); +#if !TYPE_BOOLEAN + expectMissing(e3()); +#endif + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllTester.template new file mode 100644 index 00000000..9fc394fd --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAllTester.template @@ -0,0 +1,115 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; +import speiger.src.testers.PACKAGE.utils.MINIMAL_COLLECTION; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListAddAllTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAll_supportedAllPresent() { + assertTrue("addAll(allPresent) should return true", getList().addAll(MINIMAL_COLLECTION.of(e0()))); + expectAdded(e0()); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAll_unsupportedAllPresent() { + try { + getList().addAll(MINIMAL_COLLECTION.of(e0())); + fail("addAll(allPresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) +#endignore + public void testAddAll_withDuplicates() { + MINIMAL_COLLECTION KEY_GENERIC_TYPE elementsToAdd = MINIMAL_COLLECTION.of(e0(), e1(), e0(), e1()); + assertTrue("addAll(hasDuplicates) should return true", getList().addAll(elementsToAdd)); + expectAdded(e0(), e1(), e0(), e1()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllListCollection_supportedAllPresent() { + assertTrue("addAll(allPresent) should return true", getList().addAll((COLLECTION KEY_GENERIC_TYPE)ARRAY_LIST.wrap(e0()))); + expectAdded(e0()); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllListCollection_unsupportedAllPresent() { + try { + getList().addAll((COLLECTION KEY_GENERIC_TYPE)ARRAY_LIST.wrap(e0())); + fail("addAll(allPresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) +#endignore + public void testAddAllListCollection_withDuplicates() { + COLLECTION KEY_GENERIC_TYPE elementsToAdd = ARRAY_LIST.wrap(e0(), e1(), e0(), e1()); + assertTrue("addAll(hasDuplicates) should return true", getList().addAll(elementsToAdd)); + expectAdded(e0(), e1(), e0(), e1()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllList_supportedAllPresent() { + assertTrue("addAll(allPresent) should return true", getList().addAll(ARRAY_LIST.wrap(e0()))); + expectAdded(e0()); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAllList_unsupportedAllPresent() { + try { + getList().addAll(ARRAY_LIST.wrap(e0())); + fail("addAll(allPresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) +#endignore + public void testAddAllList_withDuplicates() { + LIST KEY_GENERIC_TYPE elementsToAdd = ARRAY_LIST.wrap(e0(), e1(), e0(), e1()); + assertTrue("addAll(hasDuplicates) should return true", getList().addAll(elementsToAdd)); + expectAdded(e0(), e1(), e0(), e1()); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAtIndexTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAtIndexTester.template new file mode 100644 index 00000000..1076151e --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddAtIndexTester.template @@ -0,0 +1,112 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_ADD_WITH_INDEX; +#endignore + +import java.util.ConcurrentModificationException; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.ListFeature; + +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListAddAtIndexTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) + public void testAddAtIndex_supportedPresent() { + getList().add(0, e0()); + expectAddedIndex(0, e0()); + } + + @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) + public void testAddAtIndex_unsupportedPresent() { + try { + getList().add(0, e0()); + fail("add(n, present) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + public void testAddAtIndex_supportedNotPresent() { + getList().add(0, e3()); + expectAddedIndex(0, e3()); + } + + @CollectionFeature.Require(FAILS_FAST_ON_CONCURRENT_MODIFICATION) + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testAddAtIndexConcurrentWithIteration() { + try { + ITERATOR KEY_GENERIC_TYPE iterator = collection.iterator(); + getList().add(0, e3()); + iterator.NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) + public void testAddAtIndex_unsupportedNotPresent() { + try { + getList().add(0, e3()); + fail("add(n, notPresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + expectMissing(e3()); + } + + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = { ZERO, ONE }) + public void testAddAtIndex_middle() { + getList().add(getNumElements() / 2, e3()); + expectAddedIndex(getNumElements() / 2, e3()); + } + + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) + public void testAddAtIndex_end() { + getList().add(getNumElements(), e3()); + expectAddedIndex(getNumElements(), e3()); + } + + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + public void testAddAtIndex_negative() { + try { + getList().add(-1, e3()); + fail("add(-1, e) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + expectUnchanged(); + expectMissing(e3()); + } + + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + public void testAddAtIndex_tooLarge() { + try { + getList().add(getNumElements() + 1, e3()); + fail("add(size + 1, e) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + expectUnchanged(); + expectMissing(e3()); + } +#endignore +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddTester.template new file mode 100644 index 00000000..8b45ca8b --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListAddTester.template @@ -0,0 +1,37 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListAddTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) + public void testAdd_supportedPresent() { + assertTrue("add(present) should return true", getList().add(e0())); + expectAdded(e0()); + } + + @CollectionFeature.Require(absent = SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) + public void testAdd_unsupportedPresent() { + try { + getList().add(e0()); + fail("add(present) should throw"); + } catch (UnsupportedOperationException expected) { + } + } +#endignore +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListCreationTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListCreationTester.template new file mode 100644 index 00000000..42210009 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListCreationTester.template @@ -0,0 +1,30 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.REJECTS_DUPLICATES_AT_CREATION; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListCreationTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testCreateWithDuplicates() { + KEY_TYPE[] array = createSamplesArray(); + array[1] = e0(); + collection = primitiveGenerator.create(array); + expectContents(array); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListEqualsTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListEqualsTester.template new file mode 100644 index 00000000..7fbb35e7 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListEqualsTester.template @@ -0,0 +1,45 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; +import speiger.src.testers.PACKAGE.utils.MINIMAL_SET; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListEqualsTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ + public void testEquals_otherListWithSameElements() { + assertTrue("A List should equal any other List containing the same elements.", getList().equals(new ARRAY_LISTBRACES(getOrderedElements()))); + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testEquals_otherListWithDifferentElements() { + ARRAY_LIST KEY_GENERIC_TYPE other = new ARRAY_LISTBRACES(getSampleElements()); + other.set(other.size() / 2, e3()); + assertFalse("A List should not equal another List containing different elements.", getList().equals(other)); + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testEquals_shorterList() { + COLLECTION KEY_GENERIC_TYPE fewerElements = getSampleElements(getNumElements() - 1); + assertFalse("Lists of different sizes should not be equal.", getList().equals(new ARRAY_LISTBRACES(fewerElements))); + } + + public void testEquals_longerList() { + COLLECTION KEY_GENERIC_TYPE moreElements = getSampleElements(getNumElements() + 1); + assertFalse("Lists of different sizes should not be equal.", getList().equals(new ARRAY_LISTBRACES(moreElements))); + } + + public void testEquals_set() { + assertFalse("A List should never equal a Set.", getList().equals(MINIMAL_SET.of(getList()))); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListExtractElementsTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListExtractElementsTester.template new file mode 100644 index 00000000..9029ef03 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListExtractElementsTester.template @@ -0,0 +1,86 @@ +package speiger.src.testers.PACKAGE.tests.list; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import org.junit.Ignore; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListExtractElementsTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = {ZERO}) +#endignore + public void testRemoveElements() { +#if TYPE_OBJECT + assertArrayEquals("The Extracted Elements should be present", getSampleElements(1).TO_ARRAY(), getList().extractElements(0, 1, Object.class)); +#else + assertArrayEquals("The Extracted Elements should be present", getSampleElements(1).TO_ARRAY(), getList().extractElements(0, 1)); +#endif + expectMissing(e0()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = {ZERO}) +#endignore + public void testRemove_FromToLow() { + try { +#if TYPE_OBJECT + getList().extractElements(-1, 1, Object.class); +#else + getList().extractElements(-1, 1); +#endif + fail("extractElements(toLow, high) should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = {ZERO}) +#endignore + public void testRemove_toToHigh() { + try { +#if TYPE_OBJECT + getList().extractElements(0, getNumElements()+1, Object.class); +#else + getList().extractElements(0, getNumElements()+1); +#endif + fail("extractElements(low, toHigh) should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = {ZERO}) +#endignore + public void testRemove_mixedUp() { + try { +#if TYPE_OBJECT + getList().extractElements(1, 0, Object.class); +#else + getList().extractElements(1, 0); +#endif + } catch (IndexOutOfBoundsException e) { + } + expectUnchanged(); + } + + private static void assertArrayEquals(String message, KEY_OBJECT_TYPE[] expected, KEY_OBJECT_TYPE[] actual) { + assertEquals(message, ARRAY_LIST.wrap(expected), ARRAY_LIST.wrap(actual)); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListFillBufferTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListFillBufferTester.template new file mode 100644 index 00000000..34bc94c0 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListFillBufferTester.template @@ -0,0 +1,23 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +import java.nio.JAVA_BUFFER; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListFillBufferTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ + public void testFillBuffer() { + JAVA_BUFFER buffer = JAVA_BUFFER.allocate(getNumElements()); + getList().fillBuffer(buffer); + assertArrayEquals("Fill Buffer elements should equal", getSampleElements().TO_ARRAY(), buffer.array()); + } + + private static void assertArrayEquals(String message, KEY_TYPE[] expected, KEY_TYPE[] actual) { + assertEquals(message, ARRAY_LIST.wrap(expected), ARRAY_LIST.wrap(actual)); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListGetElementsTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListGetElementsTester.template new file mode 100644 index 00000000..ace29a14 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListGetElementsTester.template @@ -0,0 +1,90 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListGetElementsTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testGetElements_valid() { + KEY_OBJECT_TYPE[] samples = getSampleElements(2).TO_ARRAY(); + assertArrayEquals("getElements(from, result) should match", samples, getList().getElements(0, NEW_KEY_ARRAY(2))); + } + +#ignore + @CollectionSize.Require(absent = ZERO) +#endignore + public void testGetElements_validSmallerArray() { + KEY_OBJECT_TYPE[] samples = getSampleElements(2).TO_ARRAY(); + samples[1] = EMPTY_KEY_VALUE; + assertArrayEquals("getElements(from, result) should match", samples, getList().getElements(0, NEW_KEY_ARRAY(2), 0, 1)); + } + + public void testGetElements_outputToLarge() { + try { + getList().getElements(0, NEW_KEY_ARRAY(10)); + fail("getElements(from, output) should have thrown a IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + } + } + + public void testGetElements_offsetToSmall() { + try { + getList().getElements(0, NEW_KEY_ARRAY(2), -1, 2); + fail("getElements(from, output, offset, length) should have thrown a IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + //success + } + } + + public void testGetElements_offsetToLarge() { + try { + getList().getElements(0, NEW_KEY_ARRAY(2), 10, 2); + fail("getElements(from, output, offset, length) should have thrown a IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + //success + } + } + + public void testGetElements_lengthExceedingArray() { + try { + getList().getElements(0, NEW_KEY_ARRAY(2), 0, 10); + fail("getElements(from, output, offset, length) should have thrown a IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + //success + } + } + + public void testGet_negative() { + try { + getList().getElements(-1, NEW_KEY_ARRAY(2)); + fail("getElements(-1) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + } + + public void testGet_tooLarge() { + try { + getList().getElements(getNumElements(), NEW_KEY_ARRAY(2)); + fail("get(size) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + } + + private static void assertArrayEquals(String message, KEY_OBJECT_TYPE[] expected, KEY_OBJECT_TYPE[] actual) { + assertEquals(message, ARRAY_LIST.wrap(expected), ARRAY_LIST.wrap(actual)); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListGetTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListGetTester.template new file mode 100644 index 00000000..764ff5b4 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListGetTester.template @@ -0,0 +1,35 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListGetTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ + public void testGet_valid() { + expectContents(createOrderedArray()); + } + + public void testGet_validList() { + expectContents(getOrderedElements()); + } + + public void testGet_negative() { + try { + getList().GET_KEY(-1); + fail("get(-1) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + } + + public void testGet_tooLarge() { + try { + getList().GET_KEY(getNumElements()); + fail("get(size) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + } + +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListIndexOfTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListIndexOfTester.template new file mode 100644 index 00000000..83d3db25 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListIndexOfTester.template @@ -0,0 +1,40 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.REJECTS_DUPLICATES_AT_CREATION; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_INDEX_OF_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListIndexOfTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_INDEX_OF_TESTER KEY_GENERIC_TYPE +{ + @Override + protected int find(KEY_TYPE o) { + return getList().indexOf(o); + } + + @Override + protected String getMethodName() { + return "indexOf"; + } + +#ignore + @CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testIndexOf_duplicate() { + KEY_TYPE[] array = createSamplesArray(); + array[getNumElements() / 2] = e0(); + collection = primitiveGenerator.create(array); + assertEquals("indexOf(duplicate) should return index of first occurrence", 0, getList().indexOf(e0())); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListLastIndexOfTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListLastIndexOfTester.template new file mode 100644 index 00000000..53a2a03f --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListLastIndexOfTester.template @@ -0,0 +1,40 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.REJECTS_DUPLICATES_AT_CREATION; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_INDEX_OF_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListLastIndexOfTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_INDEX_OF_TESTER KEY_GENERIC_TYPE +{ + @Override + protected int find(KEY_TYPE o) { + return getList().lastIndexOf(o); + } + + @Override + protected String getMethodName() { + return "lastIndexOf"; + } + +#ignore + @CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testLastIndexOf_duplicate() { + KEY_TYPE[] array = createSamplesArray(); + array[getNumElements() / 2] = e0(); + collection = primitiveGenerator.create(array); + assertEquals("lastIndexOf(duplicate) should return index of last occurrence", getNumElements() / 2, getList().lastIndexOf(e0())); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListListIteratorTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListListIteratorTester.template new file mode 100644 index 00000000..f84fe29e --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListListIteratorTester.template @@ -0,0 +1,73 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.IteratorFeature.MODIFIABLE; +import static com.google.common.collect.testing.IteratorFeature.UNMODIFIABLE; +#endignore + +import java.util.Set; + +import com.google.common.collect.testing.IteratorFeature; + +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; +import speiger.src.collections.PACKAGE.utils.LISTS; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; +import speiger.src.testers.PACKAGE.utils.LIST_ITERATOR_TESTER; + +import speiger.src.testers.utils.SpecialFeature; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListListIteratorTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @SpecialFeature.Require(absent = SpecialFeature.ITERATOR_MODIFIABLE) + public void testListIterator_unmodifiable() { + runListIteratorTest(UNMODIFIABLE); + } + + @SpecialFeature.Require(SpecialFeature.ITERATOR_MODIFIABLE) + public void testListIterator_fullyModifiable() { + runListIteratorTest(MODIFIABLE); + } +#endignore + + private void runListIteratorTest(Set features) { + new LIST_ITERATOR_TESTER KEY_GENERIC_TYPE(4, LISTS.singleton(e4()), features, HELPERS.copyToList(getOrderedElements()), 0) { + @Override + protected LIST_ITERATOR KEY_GENERIC_TYPE newTargetIterator() { + resetCollection(); + return getList().listIterator(); + } + + @Override + protected void verify(LIST KEY_GENERIC_TYPE elements) { + expectContents(elements); + } + }.test(); + } + + public void testListIterator_tooLow() { + try { + getList().listIterator(-1); + fail(); + } catch (IndexOutOfBoundsException expected) { + } + } + + public void testListIterator_tooHigh() { + try { + getList().listIterator(getNumElements() + 1); + fail(); + } catch (IndexOutOfBoundsException expected) { + } + } + + public void testListIterator_atSize() { + getList().listIterator(getNumElements()); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListPresentTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListPresentTester.template new file mode 100644 index 00000000..ca0edf7a --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListPresentTester.template @@ -0,0 +1,54 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListPresentTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(ONE) + public void testIfAbsent() { + assertFalse("addIfPresent(absent) should return false", getList().addIfPresent(e1())); + expectUnchanged(); + } + + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(ONE) + public void testIfPresent() { + assertTrue("addIfPresent(present) should return true", getList().addIfPresent(e0())); + expectAdded(e0()); + } + + @CollectionFeature.Require(absent = SUPPORTS_ADD) + @CollectionSize.Require(ONE) + public void test_IfAbsentUnsupported() { + try { + assertFalse("addIfPresent(absent) should return false", getList().addIfPresent(e1())); + } catch (UnsupportedOperationException e) { + //Success + } + } + + @CollectionFeature.Require(absent = SUPPORTS_ADD) + @CollectionSize.Require(ONE) + public void test_IfPresentUnsupported() { + try { + assertFalse("addIfPresent(present) should return false", getList().addIfPresent(e0())); + } catch (UnsupportedOperationException e) { + //Success + } + } +#endignore +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveAllTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveAllTester.template new file mode 100644 index 00000000..2d7c3b89 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveAllTester.template @@ -0,0 +1,32 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; +import speiger.src.testers.PACKAGE.utils.MINIMAL_COLLECTION; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListRemoveAllTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testRemoveAll_duplicate() { + ArrayWithDuplicate KEY_GENERIC_TYPE arrayAndDuplicate = createArrayWithDuplicateElement(); + collection = primitiveGenerator.create(arrayAndDuplicate.elements); + KEY_TYPE duplicate = arrayAndDuplicate.duplicate; + assertTrue("removeAll(intersectingCollection) should return true", getList().removeAll(MINIMAL_COLLECTION.of(duplicate))); + assertFalse("after removeAll(e), a collection should not contain e even if it initially contained e more than once.", getList().contains(duplicate)); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveAtIndexTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveAtIndexTester.template new file mode 100644 index 00000000..e3bd4236 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveAtIndexTester.template @@ -0,0 +1,106 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_REMOVE_WITH_INDEX; +#endignore + +import java.util.ConcurrentModificationException; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.ListFeature; + +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListRemoveAtIndexTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @ListFeature.Require(absent = SUPPORTS_REMOVE_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveAtIndex_unsupported() { + try { + getList().REMOVE(0); + fail("remove(i) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) +#endignore + public void testRemoveAtIndex_negative() { + try { + getList().REMOVE(-1); + fail("remove(-1) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + expectUnchanged(); + } + +#ignore + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) +#endignore + public void testRemoveAtIndex_tooLarge() { + try { + getList().REMOVE(getNumElements()); + fail("remove(size) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + expectUnchanged(); + } + +#ignore + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) + public void testRemoveAtIndex_first() { + runRemoveTest(0); + } + + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) + @CollectionSize.Require(absent = { ZERO, ONE }) + public void testRemoveAtIndex_middle() { + runRemoveTest(getNumElements() / 2); + } + + @CollectionFeature.Require(FAILS_FAST_ON_CONCURRENT_MODIFICATION) + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveAtIndexConcurrentWithIteration() { + try { + ITERATOR KEY_GENERIC_TYPE iterator = collection.iterator(); + getList().REMOVE(getNumElements() / 2); + iterator.NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveAtIndex_last() { + runRemoveTest(getNumElements() - 1); + } + + private void runRemoveTest(int index) { + assertEquals(String.format("remove(%d) should return the element at index %d", index, index), getList().GET_KEY(index), getList().REMOVE(index)); + LIST KEY_GENERIC_TYPE expected = HELPERS.copyToList(createSamplesArray()); + expected.REMOVE(index); + expectContents(expected); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveElementsTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveElementsTester.template new file mode 100644 index 00000000..765879ff --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveElementsTester.template @@ -0,0 +1,59 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListRemoveElementsTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = {ZERO}) + public void testRemoveElements() { + getList().removeElements(0, 1); + expectMissing(e0()); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = {ZERO}) + public void testRemove_FromToLow() { + try { + getList().removeElements(-1, 1); + fail("removeElements(toLow, high) should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + } + expectUnchanged(); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = {ZERO}) + public void testRemove_toToHigh() { + try { + getList().removeElements(0, getNumElements()+1); + fail("removeElements(low, toHigh) should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + } + expectUnchanged(); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = {ZERO}) + public void testRemove_mixedUp() { + try { + getList().removeElements(1, 0); + } catch (IndexOutOfBoundsException e) { + } + expectUnchanged(); + } +#endignore +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveTester.template new file mode 100644 index 00000000..8a4afdb6 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListRemoveTester.template @@ -0,0 +1,40 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListRemoveTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = {ZERO, ONE}) +#endignore + public void testRemove_duplicate() { + ArrayWithDuplicate KEY_GENERIC_TYPE arrayAndDuplicate = createArrayWithDuplicateElement(); + collection = primitiveGenerator.create(arrayAndDuplicate.elements); + KEY_TYPE duplicate = arrayAndDuplicate.duplicate; + + int firstIndex = getList().indexOf(duplicate); + int initialSize = getList().size(); +#if TYPE_OBJECT + assertTrue("remove(present) should return true", getList().remove(duplicate)); +#else + assertTrue("remove(present) should return true", getList().REMOVE_KEY(duplicate)); +#endif + assertTrue("After remove(duplicate), a list should still contain the duplicate element", getList().contains(duplicate)); + assertFalse("remove(duplicate) should remove the first instance of the " + "duplicate element in the list", firstIndex == getList().indexOf(duplicate)); + assertEquals("remove(present) should decrease the size of a list by one.", initialSize - 1, getList().size()); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListReplaceAllTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListReplaceAllTester.template new file mode 100644 index 00000000..6c56c703 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListReplaceAllTester.template @@ -0,0 +1,72 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_SET; +#endignore + +import java.util.Arrays; +#if TYPE_OBJECT +import java.util.Objects; +#endif + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.ListFeature; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListReplaceAllTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @ListFeature.Require(SUPPORTS_SET) +#endignore + public void testReplaceAll() { +#if TYPE_OBJECT + getList().replaceAll(e -> samples.e3()); +#else + getList().REPLACE(e -> samples.e3()); +#endif + KEY_TYPE[] array = NEW_KEY_ARRAY(getNumElements()); + Arrays.fill(array, samples.e3()); + expectContents(array); + } + +#ignore + @ListFeature.Require(SUPPORTS_SET) +#endignore + public void testReplaceAll_changesSome() { +#if TYPE_OBJECT + getList().replaceAll(e -> Objects.equals(e, samples.e0()) ? samples.e3() : e); +#else + getList().REPLACE(e -> e == samples.e0() ? samples.e3() : e); +#endif + KEY_TYPE[] expected = createSamplesArray(); + for (int i = 0; i < expected.length; i++) { + if (KEY_EQUALS(expected[i], samples.e0())) { + expected[i] = samples.e3(); + } + } + expectContents(expected); + } + +#ignore + @CollectionSize.Require(absent = ZERO) + @ListFeature.Require(absent = SUPPORTS_SET) +#endignore + public void testReplaceAll_unsupported() { + try { +#if TYPE_OBJECT + getList().replaceAll(e -> e); +#else + getList().REPLACE(e -> e); +#endif + fail("replaceAll() should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListRetainAllTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListRetainAllTester.template new file mode 100644 index 00000000..9b209b71 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListRetainAllTester.template @@ -0,0 +1,59 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; +import speiger.src.testers.PACKAGE.utils.MINIMAL_COLLECTION; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListRetainAllTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testRetainAll_duplicatesKept() { + KEY_TYPE[] array = createSamplesArray(); + array[1] = e0(); + collection = primitiveGenerator.create(array); + assertFalse("containsDuplicates.retainAll(superset) should return false", collection.retainAll(MINIMAL_COLLECTION.of(createSamplesArray()))); + expectContents(array); + } + +#ignore + @SuppressWarnings("unchecked") + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRetainAll_duplicatesRemoved() { + KEY_TYPE[] array = createSamplesArray(); + array[1] = e0(); + collection = primitiveGenerator.create(array); + assertTrue("containsDuplicates.retainAll(subset) should return true", collection.retainAll(MINIMAL_COLLECTION.of(e2()))); + expectContents(e2()); + } + +#ignore + @SuppressWarnings("unchecked") + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRetainAll_countIgnored() { + resetContainer(primitiveGenerator.create(createArray(e0(), e2(), e1(), e0()))); + assertTrue(getList().retainAll(ARRAY_LIST.wrap(e0(), e1()))); + HELPERS.assertContentsInOrder(getList(), e0(), e1(), e0()); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListSetTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListSetTester.template new file mode 100644 index 00000000..78b3e70c --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListSetTester.template @@ -0,0 +1,83 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_SET; +#endignore + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.ListFeature; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListSetTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @ListFeature.Require(SUPPORTS_SET) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSet() { + doTestSet(e3()); + } + + private void doTestSet(KEY_TYPE newValue) { + int index = aValidIndex(); + KEY_TYPE initialValue = getList().GET_KEY(index); + assertEquals("set(i, x) should return the old element at position i.", initialValue, getList().set(index, newValue)); + assertEquals("After set(i, x), get(i) should return x", newValue, getList().GET_KEY(index)); + assertEquals("set() should not change the size of a list.", getNumElements(), getList().size()); + } + +#ignore + @ListFeature.Require(SUPPORTS_SET) + public void testSet_indexTooLow() { + try { + getList().set(-1, e3()); + fail("set(-1) should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException expected) { + } + expectUnchanged(); + } + + @ListFeature.Require(SUPPORTS_SET) + public void testSet_indexTooHigh() { + int index = getNumElements(); + try { + getList().set(index, e3()); + fail("set(size) should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException expected) { + } + expectUnchanged(); + } + + @CollectionSize.Require(absent = ZERO) + @ListFeature.Require(absent = SUPPORTS_SET) + public void testSet_unsupported() { + try { + getList().set(aValidIndex(), e3()); + fail("set() should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + + @CollectionSize.Require(ZERO) + @ListFeature.Require(absent = SUPPORTS_SET) + public void testSet_unsupportedByEmptyList() { + try { + getList().set(0, e3()); + fail("set() should throw UnsupportedOperationException or IndexOutOfBoundsException"); + } catch (UnsupportedOperationException | IndexOutOfBoundsException tolerated) { + } + expectUnchanged(); + } +#endignore + + private int aValidIndex() { + return getList().size() / 2; + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListSortTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListSortTester.template new file mode 100644 index 00000000..21225570 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListSortTester.template @@ -0,0 +1,102 @@ +package speiger.src.testers.PACKAGE.tests.list; + +#if TYPE_OBJECT +import java.util.Comparator; +#endif + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.ListFeature; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.utils.LISTS; +import speiger.src.collections.utils.SanityChecks; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListSortTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @ListFeature.Require(ListFeature.SUPPORTS_SET) + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testStableSort() { + KEY_TYPE[] keys = collection.TO_ARRAY(NEW_KEY_ARRAY(collection.size())); + SanityChecks.getRandom().setSeed(212121212L); + LISTS.shuffle(getList()); + assertFalse(getList().equals(ARRAY_LIST.wrap(keys))); + getList().sort(null); + assertEquals(ARRAY_LIST.wrap(keys), getList()); + } + +#ignore + @ListFeature.Require(ListFeature.SUPPORTS_SET) + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testStableSort_Comparator() { + KEY_TYPE[] keys = collection.TO_ARRAY(NEW_KEY_ARRAY(collection.size())); + SanityChecks.getRandom().setSeed(212121212L); + LISTS.shuffle(getList()); + assertFalse(getList().equals(ARRAY_LIST.wrap(keys))); +#if TYPE_OBJECT + getList().sort((Comparator)Comparator.naturalOrder()); +#else + getList().sort(CLASS_TYPE::compare); +#endif + assertEquals(ARRAY_LIST.wrap(keys), getList()); + } + +#ignore + @ListFeature.Require(absent = ListFeature.SUPPORTS_SET) +#endignore + public void testStableSort_Null() { + try { + getList().sort(null); + } + catch(UnsupportedOperationException e) { + } + } + +#ignore + @ListFeature.Require(ListFeature.SUPPORTS_SET) + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testUnstableSort() { + KEY_TYPE[] keys = collection.TO_ARRAY(NEW_KEY_ARRAY(collection.size())); + SanityChecks.getRandom().setSeed(212121212L); + LISTS.shuffle(getList()); + assertFalse(getList().equals(ARRAY_LIST.wrap(keys))); + getList().unstableSort(null); + assertEquals(ARRAY_LIST.wrap(keys), getList()); + } + +#ignore + @ListFeature.Require(ListFeature.SUPPORTS_SET) + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testUnstableSort_Comparator() { + KEY_TYPE[] keys = collection.TO_ARRAY(NEW_KEY_ARRAY(collection.size())); + SanityChecks.getRandom().setSeed(212121212L); + LISTS.shuffle(getList()); + assertFalse(getList().equals(ARRAY_LIST.wrap(keys))); +#if TYPE_OBJECT + getList().unstableSort((Comparator)Comparator.naturalOrder()); +#else + getList().unstableSort(CLASS_TYPE::compare); +#endif + assertEquals(ARRAY_LIST.wrap(keys), getList()); + } + +#ignore + @ListFeature.Require(absent = ListFeature.SUPPORTS_SET) +#endignore + public void testUnstableSort_Null() { + try { + getList().unstableSort(null); + } + catch(UnsupportedOperationException e) { + } + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListSubListTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListSubListTester.template new file mode 100644 index 00000000..fb9502fb --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListSubListTester.template @@ -0,0 +1,309 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_ADD_WITH_INDEX; +import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_REMOVE_WITH_INDEX; +import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_SET; +#endignore + +import java.util.Arrays; +import java.util.Collections; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.ListFeature; +import com.google.common.testing.SerializableTester; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.utils.LISTS; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListSubListTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ + public void testSubList_startNegative() { + try { + getList().subList(-1, 0); + fail("subList(-1, 0) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + } + + public void testSubList_endTooLarge() { + try { + getList().subList(0, getNumElements() + 1); + fail("subList(0, size + 1) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + } + + public void testSubList_startGreaterThanEnd() { + try { + getList().subList(1, 0); + fail("subList(1, 0) should throw"); + } catch (IndexOutOfBoundsException expected) { + } catch (IllegalArgumentException expected) { + } + } + + public void testSubList_empty() { + assertEquals("subList(0, 0) should be empty", LISTS.empty(), getList().subList(0, 0)); + } + + public void testSubList_entireList() { + assertEquals("subList(0, size) should be equal to the original list", getList(), getList().subList(0, getNumElements())); + } + +#ignore + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSubList_subListRemoveAffectsOriginal() { + LIST KEY_GENERIC_TYPE subList = getList().subList(0, 1); + subList.REMOVE(0); + expectContents(ARRAY_LIST.wrap(createSamplesArray()).subList(1, getNumElements())); + } + +#ignore + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSubList_subListClearAffectsOriginal() { + LIST KEY_GENERIC_TYPE subList = getList().subList(0, 1); + subList.clear(); + expectContents(ARRAY_LIST.wrap(createSamplesArray()).subList(1, getNumElements())); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) +#endignore + public void testSubList_subListAddAffectsOriginal() { + LIST KEY_GENERIC_TYPE subList = getList().subList(0, 0); + subList.add(e3()); + expectAddedIndex(0, e3()); + } + +#ignore + @ListFeature.Require(SUPPORTS_SET) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSubList_subListSetAffectsOriginal() { + LIST KEY_GENERIC_TYPE subList = getList().subList(0, 1); + subList.set(0, e3()); + LIST KEY_GENERIC_TYPE expected = HELPERS.copyToList(createSamplesArray()); + expected.set(0, e3()); + expectContents(expected); + } + +#ignore + @ListFeature.Require(SUPPORTS_SET) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSubList_originalListSetAffectsSubList() { + LIST KEY_GENERIC_TYPE subList = getList().subList(0, 1); + getList().set(0, e3()); + assertEquals("A set() call to a list after a sublist has been created should be reflected in the sublist", LISTS.singleton(e3()), subList); + } + +#ignore + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testSubList_subListRemoveAffectsOriginalLargeList() { + LIST KEY_GENERIC_TYPE subList = getList().subList(1, 3); +#if TYPE_OBJECT + subList.remove(e2()); +#else + subList.REMOVE_KEY(e2()); +#endif + LIST KEY_GENERIC_TYPE expected = HELPERS.copyToList(createSamplesArray()); + expected.REMOVE(2); + expectContents(expected); + } + +#ignore + @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testSubList_subListAddAtIndexAffectsOriginalLargeList() { + LIST KEY_GENERIC_TYPE subList = getList().subList(2, 3); + subList.add(0, e3()); + expectAddedIndex(2, e3()); + } + +#ignore + @ListFeature.Require(SUPPORTS_SET) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testSubList_subListSetAffectsOriginalLargeList() { + LIST KEY_GENERIC_TYPE subList = getList().subList(1, 2); + subList.set(0, e3()); + LIST KEY_GENERIC_TYPE expected = HELPERS.copyToList(createSamplesArray()); + expected.set(1, e3()); + expectContents(expected); + } + +#ignore + @ListFeature.Require(SUPPORTS_SET) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testSubList_originalListSetAffectsSubListLargeList() { + LIST KEY_GENERIC_TYPE subList = getList().subList(1, 3); + getList().set(1, e3()); + assertEquals("A set() call to a list after a sublist has been created " + "should be reflected in the sublist", + Arrays.asList(e3(), e2()), subList); + } + + public void testSubList_ofSubListEmpty() { + LIST KEY_GENERIC_TYPE subList = getList().subList(0, 0).subList(0, 0); + assertEquals("subList(0, 0).subList(0, 0) should be an empty list", LISTS.empty(), subList); + } + + @CollectionSize.Require(absent = { ZERO, ONE }) + public void testSubList_ofSubListNonEmpty() { + LIST KEY_GENERIC_TYPE subList = getList().subList(0, 2).subList(1, 2); + assertEquals("subList(0, 2).subList(1, 2) " + "should be a single-element list of the element at index 1", + Collections.singletonList(getOrderedElements().GET_KEY(1)), subList); + } + +#ignore + @CollectionSize.Require(absent = { ZERO }) +#endignore + public void testSubList_size() { + LIST KEY_GENERIC_TYPE list = getList(); + int size = getNumElements(); + assertEquals(size, list.subList(0, size).size()); + assertEquals(size - 1, list.subList(0, size - 1).size()); + assertEquals(size - 1, list.subList(1, size).size()); + assertEquals(0, list.subList(size, size).size()); + assertEquals(0, list.subList(0, 0).size()); + } + +#ignore + @CollectionSize.Require(absent = { ZERO }) +#endignore + public void testSubList_isEmpty() { + LIST KEY_GENERIC_TYPE list = getList(); + int size = getNumElements(); + for (LIST KEY_GENERIC_TYPE subList : Arrays.asList(list.subList(0, size), list.subList(0, size - 1), list.subList(1, size), + list.subList(0, 0), list.subList(size, size))) { + assertEquals(subList.size() == 0, subList.isEmpty()); + } + } + +#ignore + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testSubList_get() { + LIST KEY_GENERIC_TYPE list = getList(); + int size = getNumElements(); + LIST KEY_GENERIC_TYPE copy = list.subList(0, size); + LIST KEY_GENERIC_TYPE head = list.subList(0, size - 1); + LIST KEY_GENERIC_TYPE tail = list.subList(1, size); + assertEquals(list.GET_KEY(0), copy.GET_KEY(0)); + assertEquals(list.GET_KEY(size - 1), copy.GET_KEY(size - 1)); + assertEquals(list.GET_KEY(1), tail.GET_KEY(0)); + assertEquals(list.GET_KEY(size - 1), tail.GET_KEY(size - 2)); + assertEquals(list.GET_KEY(0), head.GET_KEY(0)); + assertEquals(list.GET_KEY(size - 2), head.GET_KEY(size - 2)); + for (LIST KEY_GENERIC_TYPE subList : Arrays.asList(copy, head, tail)) { + for (int index : Arrays.asList(-1, subList.size())) { + try { + subList.GET_KEY(index); + fail("expected IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException expected) { + } + } + } + } + +#ignore + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testSubList_contains() { + LIST KEY_GENERIC_TYPE list = getList(); + int size = getNumElements(); + LIST KEY_GENERIC_TYPE copy = list.subList(0, size); + LIST KEY_GENERIC_TYPE head = list.subList(0, size - 1); + LIST KEY_GENERIC_TYPE tail = list.subList(1, size); + assertTrue(copy.contains(list.GET_KEY(0))); + assertTrue(head.contains(list.GET_KEY(0))); + assertTrue(tail.contains(list.GET_KEY(1))); + // The following assumes all elements are distinct. + assertTrue(copy.contains(list.GET_KEY(size - 1))); + assertTrue(head.contains(list.GET_KEY(size - 2))); + assertTrue(tail.contains(list.GET_KEY(size - 1))); + assertFalse(head.contains(list.GET_KEY(size - 1))); + assertFalse(tail.contains(list.GET_KEY(0))); + } + +#ignore + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testSubList_indexOf() { + LIST KEY_GENERIC_TYPE list = getList(); + int size = getNumElements(); + LIST KEY_GENERIC_TYPE copy = list.subList(0, size); + LIST KEY_GENERIC_TYPE head = list.subList(0, size - 1); + LIST KEY_GENERIC_TYPE tail = list.subList(1, size); + assertEquals(0, copy.indexOf(list.GET_KEY(0))); + assertEquals(0, head.indexOf(list.GET_KEY(0))); + assertEquals(0, tail.indexOf(list.GET_KEY(1))); + // The following assumes all elements are distinct. + assertEquals(size - 1, copy.indexOf(list.GET_KEY(size - 1))); + assertEquals(size - 2, head.indexOf(list.GET_KEY(size - 2))); + assertEquals(size - 2, tail.indexOf(list.GET_KEY(size - 1))); + assertEquals(-1, head.indexOf(list.GET_KEY(size - 1))); + assertEquals(-1, tail.indexOf(list.GET_KEY(0))); + } + +#ignore + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testSubList_lastIndexOf() { + LIST KEY_GENERIC_TYPE list = getList(); + int size = list.size(); + LIST KEY_GENERIC_TYPE copy = list.subList(0, size); + LIST KEY_GENERIC_TYPE head = list.subList(0, size - 1); + LIST KEY_GENERIC_TYPE tail = list.subList(1, size); + assertEquals(size - 1, copy.lastIndexOf(list.GET_KEY(size - 1))); + assertEquals(size - 2, head.lastIndexOf(list.GET_KEY(size - 2))); + assertEquals(size - 2, tail.lastIndexOf(list.GET_KEY(size - 1))); + // The following assumes all elements are distinct. + assertEquals(0, copy.lastIndexOf(list.GET_KEY(0))); + assertEquals(0, head.lastIndexOf(list.GET_KEY(0))); + assertEquals(0, tail.lastIndexOf(list.GET_KEY(1))); + assertEquals(-1, head.lastIndexOf(list.GET_KEY(size - 1))); + assertEquals(-1, tail.lastIndexOf(list.GET_KEY(0))); + } + +#ignore + @CollectionFeature.Require(SERIALIZABLE_INCLUDING_VIEWS) +#endignore + public void testReserializeWholeSubList() { + SerializableTester.reserializeAndAssert(getList().subList(0, getNumElements())); + } + +#ignore + @CollectionFeature.Require(SERIALIZABLE_INCLUDING_VIEWS) +#endignore + public void testReserializeEmptySubList() { + SerializableTester.reserializeAndAssert(getList().subList(0, 0)); + } + +#ignore + @CollectionFeature.Require(SERIALIZABLE_INCLUDING_VIEWS) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testReserializeSubList() { + SerializableTester.reserializeAndAssert(getList().subList(0, 2)); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListSwapRemoveAtIndexTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListSwapRemoveAtIndexTester.template new file mode 100644 index 00000000..713e490e --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListSwapRemoveAtIndexTester.template @@ -0,0 +1,115 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_REMOVE_WITH_INDEX; +#endignore + +import java.util.ConcurrentModificationException; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.ListFeature; + +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListSwapRemoveAtIndexTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @ListFeature.Require(absent = SUPPORTS_REMOVE_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) + public void testRemoveAtIndex_unsupported() { + try { + getList().swapRemove(0); + fail("remove(i) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) + public void testRemoveAtIndex_negative() { + try { + getList().swapRemove(-1); + fail("remove(-1) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + expectUnchanged(); + } + + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) + public void testRemoveAtIndex_tooLarge() { + try { + getList().swapRemove(getNumElements()); + fail("remove(size) should throw"); + } catch (IndexOutOfBoundsException expected) { + } + expectUnchanged(); + } + + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) + public void testRemoveAtIndex_first() { + runRemoveTest(0); + } + + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testRemoveAtSecondOfFour() { + COLLECTION KEY_GENERIC_TYPE samples = getSampleElements(4); + KEY_TYPE[] data = samples.TO_ARRAY(NEW_KEY_ARRAY(4)); + collection = primitiveGenerator.create(data); + assertEquals(data[1], getList().GET_KEY(1)); + assertEquals(data[1], getList().swapRemove(1)); + assertEquals(data[3], getList().GET_KEY(1)); + } + +#ignore + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) + @CollectionSize.Require(absent = { ZERO, ONE }) + public void testRemoveAtIndex_middle() { + runRemoveTest(getNumElements() / 2); + } + + @CollectionFeature.Require(FAILS_FAST_ON_CONCURRENT_MODIFICATION) + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveAtIndexConcurrentWithIteration() { + try { + ITERATOR KEY_GENERIC_TYPE iterator = collection.iterator(); + getList().swapRemove(getNumElements() / 2); + iterator.NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveAtIndex_last() { + runRemoveTest(getNumElements() - 1); + } + + private void runRemoveTest(int index) { + assertEquals(String.format("remove(%d) should return the element at index %d", index, index), getList().GET_KEY(index), getList().swapRemove(index)); + LIST KEY_GENERIC_TYPE expected = HELPERS.copyToList(createSamplesArray()); + expected.set(index, expected.GET_KEY(expected.size()-1)); + expected.REMOVE(expected.size()-1); + expectContents(expected); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListSwapRemoveTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListSwapRemoveTester.template new file mode 100644 index 00000000..c4c8061a --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListSwapRemoveTester.template @@ -0,0 +1,81 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +#if !TYPE_BOOLEAN +import speiger.src.collections.PACKAGE.collections.COLLECTION; +#endif +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListSwapRemoveTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = {ZERO, ONE}) +#endignore + public void testRemove_duplicate() { + ArrayWithDuplicate KEY_GENERIC_TYPE arrayAndDuplicate = createArrayWithDuplicateElement(); + collection = primitiveGenerator.create(arrayAndDuplicate.elements); + KEY_TYPE duplicate = arrayAndDuplicate.duplicate; + KEY_TYPE lastElement = arrayAndDuplicate.elements[arrayAndDuplicate.elements.length-1]; + + int firstIndex = getList().indexOf(duplicate); + int initialSize = getList().size(); + assertTrue("swapRemove(present) should return true", getList().REMOVE_SWAP(duplicate)); + assertTrue("removed element should have moved the last element in its place", getList().GET_KEY(firstIndex) == lastElement); + assertTrue("After remove(duplicate), a list should still contain the duplicate element", getList().contains(duplicate)); + assertEquals("remove(present) should decrease the size of a list by one.", initialSize - 1, getList().size()); + } +#if !TYPE_BOOLEAN + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = {ZERO, ONE}) +#endignore + public void testSwapRemove_First() { + assertTrue(getList().REMOVE_SWAP(e0())); + assertFalse(getList().contains(e0())); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testRemoveAtSecondOfFour() { + COLLECTION KEY_GENERIC_TYPE samples = getSampleElements(4); + KEY_TYPE[] data = samples.TO_ARRAY(NEW_KEY_ARRAY(4)); + collection = primitiveGenerator.create(data); + assertTrue(getList().REMOVE_SWAP(data[2])); + assertFalse(getList().contains(data[2])); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = {ZERO, ONE}) +#endignore + public void testSwapRemove_Middle() { + assertTrue(getList().REMOVE_SWAP(e1())); + assertFalse(getList().contains(e1())); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = {ZERO, ONE}) +#endignore + public void testSwapRemove_Missing() { + assertFalse(getList().REMOVE_SWAP(e3())); + assertFalse(getList().contains(e3())); + } +#endif +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/list/ListToArrayTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListToArrayTester.template new file mode 100644 index 00000000..a7163d7e --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/list/ListToArrayTester.template @@ -0,0 +1,37 @@ +package speiger.src.testers.PACKAGE.tests.list; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_LIST_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEListToArrayTester KEY_GENERIC_TYPE extends ABSTRACT_LIST_TESTER KEY_GENERIC_TYPE +{ + public void testToArray_noArg() { + KEY_OBJECT_TYPE[] actual = getList().TO_ARRAY(); + assertArrayEquals("toArray() order should match list", createOrderedArray(), actual); + } + + @CollectionSize.Require(absent = ZERO) + public void testToArray_tooSmall() { + KEY_TYPE[] actual = getList().TO_ARRAY(NEW_KEY_ARRAY(0)); + assertArrayEquals("toArray(tooSmall) order should match list", createOrderedArray(), actual); + } + + public void testToArray_largeEnough() { + KEY_TYPE[] actual = getList().TO_ARRAY(NEW_KEY_ARRAY(getNumElements())); + assertArrayEquals("toArray(largeEnough) order should match list", createOrderedArray(), actual); + } + + private static void assertArrayEquals(String message, KEY_OBJECT_TYPE[] expected, KEY_OBJECT_TYPE[] actual) { + assertEquals(message, ARRAY_LIST.wrap(expected), ARRAY_LIST.wrap(actual)); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapAddToTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapAddToTester.template new file mode 100644 index 00000000..33208e3c --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapAddToTester.template @@ -0,0 +1,150 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +import org.junit.Ignore; + +#if VALUE_PRIMITIVES +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore + +import java.util.ConcurrentModificationException; +import java.util.Iterator; + + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR; +#if !SAME_TYPE +import speiger.src.collections.PACKAGE.collections.ITERATOR; +#endif +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +#endif +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapAddToTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#if VALUE_PRIMITIVES +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddTo_supportedPresent() { + assertEquals("addTo(present, value) should return the old value", v0(), getMap().addTo(k0(), v3())); +#if VALUE_CHAR + expectReplacement(entry(k0(), (char)(v0()+v3()))); +#else + expectReplacement(entry(k0(), v3())); +#endif + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testAddTo_supportedNotPresent() { + assertEquals("addTo(notPresent, value) should return INVALID_VALUE", INVALID_VALUE, addTo(e3())); + expectAdded(e3()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testAddToSum_supportedNotPresent() { + assertEquals("addTo(notPresent, value) should return INVALID_VALUE", INVALID_VALUE, addTo(e3())); + assertEquals("addTo(notPresent, value) should return "+v3(), v3(), addTo(e3())); + expectAdded(entry(k3(), (VALUE_TYPE)(v3()+v3()))); + } + + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_PUT }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddToAbsentConcurrentWithEntrySetIteration() { + try { + Iterator iterator = getMap().ENTRY_SET().iterator(); + addTo(e3()); + iterator.next(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_PUT }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddToAbsentConcurrentWithKeySetIteration() { + try { + ITERATOR KEY_GENERIC_TYPE iterator = getMap().keySet().iterator(); + addTo(e3()); + iterator.NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_PUT }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddToAbsentConcurrentWithValueIteration() { + try { + VALUE_ITERATOR VALUE_GENERIC_TYPE iterator = getMap().values().iterator(); + addTo(e3()); + iterator.VALUE_NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testAddTo_unsupportedNotPresent() { + try { + addTo(e3()); + fail("addTo(notPresent, value) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + expectMissing(e3()); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddTo_unsupportedPresentExistingValue() { + try { + assertEquals("addTo(present, existingValue) should return present or throw", v0(), addTo(e0())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddTo_unsupportedPresentDifferentValue() { + try { + getMap().addTo(k0(), v3()); + fail("addTo(present, differentValue) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + + private VALUE_TYPE addTo(MAP.Entry KEY_VALUE_GENERIC_TYPE entry) { + return getMap().addTo(entry.ENTRY_KEY(), entry.ENTRY_VALUE()); + } +#endif +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapClearTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapClearTester.template new file mode 100644 index 00000000..7490f3d0 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapClearTester.template @@ -0,0 +1,110 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; +#endignore + +import java.util.ConcurrentModificationException; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +#if !VALUE_OBJECT +import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR; +#endif +#if !TYPE_OBJECT && !SAME_TYPE +import speiger.src.collections.PACKAGE.collections.ITERATOR; +#endif +import speiger.src.collections.PACKAGE.maps.interfaces.MAP.Entry; +import speiger.src.collections.objects.collections.ObjectIterator; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapClearTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testClear() { + getMap().clear(); + assertTrue("After clear(), a map should be empty.", getMap().isEmpty()); + assertEquals(0, getMap().size()); + assertFalse(getMap().ENTRY_SET().iterator().hasNext()); + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE }) + @CollectionSize.Require(SEVERAL) +#endignore + public void testClearConcurrentWithEntrySetIteration() { + try { + ObjectIterator iterator = getMap().ENTRY_SET().iterator(); + getMap().clear(); + iterator.next(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE }) + @CollectionSize.Require(SEVERAL) +#endignore + public void testClearConcurrentWithKeySetIteration() { + try { + ITERATOR KEY_GENERIC_TYPE iterator = getMap().keySet().iterator(); + getMap().clear(); + iterator.NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE }) + @CollectionSize.Require(SEVERAL) +#endignore + public void testClearConcurrentWithValuesIteration() { + try { + VALUE_ITERATOR VALUE_GENERIC_TYPE iterator = getMap().values().iterator(); + getMap().clear(); + iterator.VALUE_NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testClear_unsupported() { + try { + getMap().clear(); + fail("clear() should throw UnsupportedOperation if a map does not support it and is not empty."); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) +#endignore + public void testClear_unsupportedByEmptyCollection() { + try { + getMap().clear(); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfAbsentTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfAbsentTester.template new file mode 100644 index 00000000..b151a09c --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfAbsentTester.template @@ -0,0 +1,157 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore +#if !VALUE_BOOLEAN +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ONE; +#endignore +#endif + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import junit.framework.AssertionFailedError; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testComputeIfAbsent_supportedAbsent() { + assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), + getMap().COMPUTE_IF_ABSENT(k3(), k -> { + assertEquals(k3(), k); + return v3(); + })); + expectAdded(e3()); + } + +#if !VALUE_BOOLEAN +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(ONE) +#endignore + public void testComputeIfAbsent_supportedAbsentFirst() { + getMap().setDefaultReturnValue(v0()); + assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), + getMap().COMPUTE_IF_ABSENT(k0(), k -> { + assertEquals(k0(), k); + return v3(); + })); + expectContents(entry(k0(), v3())); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(ONE) +#endignore + public void testComputeIfAbsent_supportedAbsentSameResult() { + getMap().setDefaultReturnValue(v0()); + assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v0(), + getMap().COMPUTE_IF_ABSENT(k0(), k -> { + assertEquals(k0(), k); + return v0(); + })); + expectUnchanged(); + } + +#endif +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testComputeIfAbsent_supportedPresent() { + assertEquals("COMPUTE_IF_ABSENT(present, function) should return existing value", v0(), + getMap().COMPUTE_IF_ABSENT(k0(), k -> { + throw new AssertionFailedError(); + })); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testComputeIfAbsent_functionReturnsNullNotInserted() { + assertEquals("COMPUTE_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", + INVALID_VALUE, getMap().COMPUTE_IF_ABSENT(k3(), k -> { + assertEquals(k3(), k); + return INVALID_VALUE; + })); + expectUnchanged(); + } + + static class ExpectedException extends RuntimeException { + private static final long serialVersionUID = 1L; + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testComputeIfAbsent_functionThrows() { + try { + getMap().COMPUTE_IF_ABSENT(k3(), k -> { + assertEquals(k3(), k); + throw new ExpectedException(); + }); + fail("Expected ExpectedException"); + } catch (ExpectedException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testComputeIfAbsent_unsupportedAbsent() { + try { + getMap().COMPUTE_IF_ABSENT(k3(), k -> { + // allowed to be called + assertEquals(k3(), k); + return v3(); + }); + fail("COMPUTE_IF_ABSENT(notPresent, function) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testComputeIfAbsent_unsupportedPresentExistingValue() { + try { + assertEquals("COMPUTE_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), + getMap().COMPUTE_IF_ABSENT(k0(), k -> { + assertEquals(k0(), k); + return v0(); + })); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testComputeIfAbsent_unsupportedPresentDifferentValue() { + try { + assertEquals("COMPUTE_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), + getMap().COMPUTE_IF_ABSENT(k0(), k -> { + assertEquals(k0(), k); + return v3(); + })); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfPresentTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfPresentTester.template new file mode 100644 index 00000000..95115979 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeIfPresentTester.template @@ -0,0 +1,105 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import junit.framework.AssertionFailedError; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testComputeIfPresent_supportedAbsent() { + assertEquals("COMPUTE_IF_PRESENT(notPresent, function) should return INVALID_VALUE", INVALID_VALUE, + getMap().COMPUTE_IF_PRESENT(k3(), (k, v) -> { + throw new AssertionFailedError(); + })); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testComputeIfPresent_supportedPresent() { + assertEquals("COMPUTE_IF_PRESENT(present, function) should return new value", v3(), + getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> { + assertEquals(k0(), k); + assertEquals(v0(), v); + return v3(); + })); + expectReplacement(entry(k0(), v3())); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testComputeIfPresent_functionReturnsNull() { + assertEquals("COMPUTE_IF_PRESENT(present, returnsNull) should return INVALID_VALUE", INVALID_VALUE, + getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> { + assertEquals(k0(), k); + assertEquals(v0(), v); + return INVALID_VALUE; + })); + expectMissing(e0()); + } + + static class ExpectedException extends RuntimeException { + private static final long serialVersionUID = 1L; + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testComputeIfPresent_functionThrows() { + try { + getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> { + assertEquals(k0(), k); + assertEquals(v0(), v); + throw new ExpectedException(); + }); + fail("Expected ExpectedException"); + } catch (ExpectedException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testComputeIfPresent_unsupportedAbsent() { + try { + getMap().COMPUTE_IF_PRESENT(k3(), (k, v) -> { + throw new AssertionFailedError(); + }); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testComputeIfPresent_unsupportedPresent() { + try { + getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> v3()); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeTester.template new file mode 100644 index 00000000..97051803 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapComputeTester.template @@ -0,0 +1,145 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE }) +#endignore + public void testCompute_absentToPresent() { + assertEquals("Map.COMPUTE(absent, functionReturningValue) should return value", v3(), + getMap().COMPUTE(k3(), (k, v) -> { + assertEquals(k3(), k); + assertEquals(INVALID_VALUE, v); + return v3(); + })); + expectAdded(e3()); + assertEquals(getNumElements() + 1, getMap().size()); + } + +#ignore + @MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE }) +#endignore + public void testCompute_absentToAbsent() { + assertEquals("Map.COMPUTE(absent, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE(k3(), (k, v) -> { + assertEquals(k3(), k); + assertEquals(INVALID_VALUE, v); + return INVALID_VALUE; + })); + expectUnchanged(); + assertEquals(getNumElements(), getMap().size()); + } + +#ignore + @MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testCompute_presentToPresent() { + assertEquals("Map.COMPUTE(present, functionReturningValue) should return new value", v3(), + getMap().COMPUTE(k0(), (k, v) -> { + assertEquals(k0(), k); + assertEquals(v0(), v); + return v3(); + })); + expectReplacement(entry(k0(), v3())); + assertEquals(getNumElements(), getMap().size()); + } + +#ignore + @MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testCompute_presentToAbsent() { + assertEquals("Map.COMPUTE(present, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE(k0(), (k, v) -> { + assertEquals(k0(), k); + assertEquals(v0(), v); + return INVALID_VALUE; + })); + expectMissing(e0()); + expectMissingKeys(k0()); + assertEquals(getNumElements() - 1, getMap().size()); + } + + static class ExpectedException extends RuntimeException { + private static final long serialVersionUID = 1L; + } + +#ignore + @MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testCompute_presentFunctionThrows() { + try { + getMap().COMPUTE(k0(), (k, v) -> { + assertEquals(k0(), k); + assertEquals(v0(), v); + throw new ExpectedException(); + }); + fail("Expected ExpectedException"); + } catch (ExpectedException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE }) +#endignore + public void testCompute_absentFunctionThrows() { + try { + getMap().COMPUTE(k3(), (k, v) -> { + assertEquals(k3(), k); + assertEquals(INVALID_VALUE, v); + throw new ExpectedException(); + }); + fail("Expected ExpectedException"); + } catch (ExpectedException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testCompute_removeAbsent() { + try { + getMap().COMPUTE(k3(), (k, v) -> { + assertEquals(k3(), k); + assertEquals(INVALID_VALUE, v); + return INVALID_VALUE; + }); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testCompute_putAbsent() { + try { + getMap().COMPUTE(k3(), (k, v) -> { + assertEquals(k3(), k); + assertEquals(INVALID_VALUE, v); + return INVALID_VALUE; + }); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapConstructorTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapConstructorTester.template new file mode 100644 index 00000000..14d04615 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapConstructorTester.template @@ -0,0 +1,249 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +#if VALUE_OBJECT && !TYPE_OBJECT +import java.util.Objects; +#endif +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.IntFunction; +import java.util.function.Supplier; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.Ignore; +import junit.framework.TestCase; + +#if !VALUE_OBJECT +import speiger.src.collections.VALUE_PACKAGE.utils.VALUE_ARRAYS; +#endif +import speiger.src.collections.PACKAGE.maps.impl.hash.LINKED_HASH_MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +#if !SAME_TYPE && !TYPE_OBJECT +import speiger.src.collections.PACKAGE.utils.ARRAYS; +#endif +import speiger.src.collections.utils.ITrimmable; + +@Ignore +@SuppressWarnings("javadoc") +public abstract class FILE_KEY_TYPE2FILE_VALUE_TYPEMapConstructorTester KEY_VALUE_GENERIC_TYPE extends TestCase +{ + protected Supplier simpleConstructor; + protected IntFunction sizeConstructor; + protected BiFunction pArrayConstructor; +#if !TYPE_OBJECT || !VALUE_OBJECT + protected BiFunction arrayConstructor; +#endif + protected Function, MAP KEY_VALUE_GENERIC_TYPE> mapConstructor; + protected Function pMapConstructor; + protected KEY_TYPE[] keys = createKeyElements(); + protected VALUE_TYPE[] values = createValueElements(); + + protected void setSimpleConstructor(Supplier simpleConstructor) { + this.simpleConstructor = simpleConstructor; + } + + protected void setSizeConstructor(IntFunction sizeConstructor) { + this.sizeConstructor = sizeConstructor; + } + + protected void setPArrayConstructor(BiFunction pArrayConstructor) { + this.pArrayConstructor = pArrayConstructor; + } + +#if !TYPE_OBJECT || !VALUE_OBJECT + protected void setArrayConstructor(BiFunction arrayConstructor) { + this.arrayConstructor = arrayConstructor; + } + +#endif + protected void setMapConstructor(Function, MAP KEY_VALUE_GENERIC_TYPE> mapConstructor) { + this.mapConstructor = mapConstructor; + } + + protected void setPMapConstructor(Function pMapConstructor) { + this.pMapConstructor = pMapConstructor; + } + + @Test + public void testPrimitiveArrayConstructor() { + if(pArrayConstructor == null) return; + Assert.assertTrue(pArrayConstructor.apply(keys, values) != null); + } + + @Test + public void testPrimitiveArrayConstructorBadlySized() { + if(pArrayConstructor == null) return; + try { + pArrayConstructor.apply(Arrays.copyOf(keys, 50), values); + Assert.fail("This should throw IllegalStateException"); + } + catch(IllegalStateException | IllegalArgumentException e) { + } + } + +#if !TYPE_OBJECT || !VALUE_OBJECT + @Test + public void testArrayConstructor() { + if(arrayConstructor == null) return; +#if TYPE_OBJECT + Assert.assertTrue(arrayConstructor.apply(keys, VALUE_ARRAYS.wrap(values)) != null); +#else if VALUE_OBJECT + Assert.assertTrue(arrayConstructor.apply(ARRAYS.wrap(keys), values) != null); +#else + Assert.assertTrue(arrayConstructor.apply(ARRAYS.wrap(keys), VALUE_ARRAYS.wrap(values)) != null); +#endif + } + + @Test + public void testArrayConstructorBadlySized() { + if(arrayConstructor == null) return; + try { +#if TYPE_OBJECT + arrayConstructor.apply(Arrays.copyOf(keys, 50), VALUE_ARRAYS.wrap(values)); +#else if VALUE_OBJECT + arrayConstructor.apply(ARRAYS.wrap(Arrays.copyOf(keys, 50)), values); +#else + arrayConstructor.apply(ARRAYS.wrap(Arrays.copyOf(keys, 50)), VALUE_ARRAYS.wrap(values)); +#endif + Assert.fail("This should throw IllegalStateException"); + } + catch(IllegalStateException | IllegalArgumentException e) { + } + } + +#endif + @Test + public void testPrimitiveMapsConstructor() { + if(pMapConstructor == null) return; + Assert.assertTrue(pMapConstructor.apply(new LINKED_HASH_MAPKV_BRACES(keys, values)) != null); + } + + @Test + public void testMapsConstructor() { + if(mapConstructor == null) return; + Assert.assertTrue(mapConstructor.apply(new LinkedHashMap<>(new LINKED_HASH_MAPKV_BRACES(keys, values))) != null); + } + + @Test + public void testSimpleConstructor() { + if(simpleConstructor == null) return; + Assert.assertTrue(simpleConstructor.get() != null); + } + + @Test + public void testSizeConstructor_empty() { + if(sizeConstructor == null) return; + Assert.assertTrue(sizeConstructor.apply(0) != null); + } + + @Test + public void testSizeConstructor_smallSize() { + if(sizeConstructor == null) return; + Assert.assertTrue(sizeConstructor.apply(32) != null); + } + + @Test + public void testSizeConstructor_largeSize() { + if(sizeConstructor == null) return; + Assert.assertTrue(sizeConstructor.apply(25212) != null); + } + + @Test + public void testRehash() { + if(sizeConstructor == null) return; + try + { + MAP KEY_VALUE_GENERIC_TYPE map = sizeConstructor.apply(0); + if(map instanceof ITrimmable) { + ITrimmable trim = (ITrimmable)map; + map.putAll(keys, values); + map.clear(); + Assert.assertTrue(trim.trim()); + Assert.assertFalse(trim.trim()); + map.putAll(keys, values); + trim.clearAndTrim(); + map.putAll(keys, values); + trim.clearAndTrim(Short.MAX_VALUE); + } + } + catch(UnsupportedOperationException e) { + //Ignore thats fine + } + } + +#if !TYPE_OBJECT + public void testHashCollisions() { + if(simpleConstructor == null) return; + MAP KEY_VALUE_GENERIC_TYPE map = simpleConstructor.get(); + int value = fillMap(map); + for(int i = value;i>=0;i-=16) { + Assert.assertTrue(VALUE_EQUALS(values[i], map.remove(keys[i]))); + } + value = fillMap(map); + for(int i = value;i>=0;i-=16) { + Assert.assertTrue(map.remove(keys[i], values[i])); + } + value = fillMap(map); + for(int i = value;i>=0;i-=16) { + Assert.assertTrue(map.remove(KEY_TO_OBJ(keys[i]), VALUE_TO_OBJ(values[i]))); + } + } + + private int fillMap(MAP KEY_VALUE_GENERIC_TYPE map) { + int result = 0; + for(int i = 2;i<100;i+=16) { + map.put(keys[i], values[i]); + result = i; + } + return result; + } + +#endif + @Test + public void testSizeConstructor_InvalidSize() { + if(sizeConstructor == null) return; + try { + sizeConstructor.apply(-1); + Assert.fail("When Inputted Size is negative this should crash"); + } + catch(IllegalStateException e) { + } + } + +#if TYPE_OBJECT + protected abstract KEY_TYPE[] createKeyElements(); + +#else + protected KEY_TYPE[] createKeyElements() { + KEY_TYPE[] keys = NEW_KEY_ARRAY(100); + for(int i = 0;i<100;i++) { + keys[i] = (KEY_TYPE)i; + } + return keys; + } +#endif + +#if VALUE_OBJECT + protected abstract VALUE_TYPE[] createValueElements(); + +#else + protected VALUE_TYPE[] createValueElements() { + VALUE_TYPE[] values = NEW_VALUE_ARRAY(getSize()); + for(int i = 0,m=getSize();i(e0()))); + } + + public void testContains_no() { + assertFalse("contains(notPresent) should return false", getMap().ENTRY_SET().contains(e3())); + } + + public void testContainsObject_no() { + assertFalse("contains(notPresent) should return false", getMap().ENTRY_SET().contains(new AbstractMap.SimpleEntry<>(e3()))); + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testContainsEntry_yes() { + MAP.Entry KEY_VALUE_GENERIC_TYPE value = getMap().ENTRY_SET().iterator().next(); + assertTrue("MAP.Entry.equals() should return true", value.equals(e0())); + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testContainsEntryObject_yes() { + MAP.Entry KEY_VALUE_GENERIC_TYPE value = getMap().ENTRY_SET().iterator().next(); + assertTrue("MAP.Entry.equals() should return true", value.equals(new AbstractMap.SimpleEntry<>(e0()))); + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testContainsEntry_no() { + MAP.Entry KEY_VALUE_GENERIC_TYPE value = getMap().ENTRY_SET().iterator().next(); + assertFalse("MAP.Entry.equals() should return false", value.equals(e3())); + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testContainsEntryObject_no() { + MAP.Entry KEY_VALUE_GENERIC_TYPE value = getMap().ENTRY_SET().iterator().next(); + assertFalse("MAP.Entry.equals() should return false", value.equals(new AbstractMap.SimpleEntry<>(e3()))); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapContainsValueTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapContainsValueTester.template new file mode 100644 index 00000000..e3113798 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapContainsValueTester.template @@ -0,0 +1,49 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsValueTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @CollectionSize.Require(absent = ZERO) +#endignore + public void testContains_yes() { + assertTrue("containsValue(present) should return true", getMap().containsValue(v0())); + } + + public void testContains_no() { + assertFalse("containsValue(notPresent) should return false", getMap().containsValue(v3())); + } + +#ignore + @CollectionSize.Require(absent = ZERO) +#endignore + public void testContainsObject_yes() { + assertTrue("containsValue(present) should return true", getMap().containsValue(VALUE_TO_OBJ(v0()))); + } + +#if !VALUE_BOOLEAN + public void testContainsObject_no() { + assertFalse("containsValue(notPresent) should return false", getMap().containsValue(VALUE_TO_OBJ(v3()))); + } + +#if !VALUE_OBJECT +#ignore + @CollectionSize.Require(absent = ZERO) +#endignore + public void testContains_null() { + assertFalse("containsValue(present) should return false", getMap().containsValue(null)); + } +#endif +#endif +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapCopyTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapCopyTester.template new file mode 100644 index 00000000..c45957c2 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapCopyTester.template @@ -0,0 +1,38 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +import org.junit.Assert; +import org.junit.Ignore; + +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.PACKAGE.utils.maps.MAPS; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; +import speiger.src.testers.utils.SpecialFeature; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapCopyTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @SpecialFeature.Require(SpecialFeature.COPYING) +#endignore + public void testEquals() { + MAP KEY_VALUE_GENERIC_TYPE copy = container.copy(); + if(!(copy instanceof MAPS.EmptyMap)) { + Assert.assertFalse("Copied Map shouldn't match", copy == container); + } + Assert.assertTrue("Copied Map contents should match", copy.equals(container)); + } + +#ignore + @SpecialFeature.Require(absent = SpecialFeature.COPYING) +#endignore + public void testEqualsFail() { + try { + assertNull(container.copy()); + fail("If Copying isn't supported it should throw a UnsupportedOperationException"); + } + catch(UnsupportedOperationException e) { + //Success + } + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapCreatorTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapCreatorTester.template new file mode 100644 index 00000000..752668e1 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapCreatorTester.template @@ -0,0 +1,40 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.REJECTS_DUPLICATES_AT_CREATION; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.objects.lists.ObjectArrayList; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapCreatorTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testCreateWithDuplicates_nonNullDuplicatesNotRejected() { + expectFirstRemoved(getEntriesMultipleNonNullKeys()); + } + + private MAP.Entry KEY_VALUE_GENERIC_TYPE[] getEntriesMultipleNonNullKeys() { + MAP.Entry KEY_VALUE_GENERIC_TYPE[] entries = createSamplesArray(); + entries[0] = entry(k1(), v0()); + return entries; + } + + private void expectFirstRemoved(MAP.Entry KEY_VALUE_GENERIC_TYPE[] entries) { + resetMap(entries); + expectContents(ObjectArrayList.wrap(entries).subList(1, getNumElements())); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapEntrySetTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapEntrySetTester.template new file mode 100644 index 00000000..c08d602b --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapEntrySetTester.template @@ -0,0 +1,56 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ITERATOR_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore + +import java.util.Iterator; +import java.util.Set; +#if TYPE_OBJECT +import java.util.Objects; +#endif + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapEntrySetTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @CollectionSize.Require(ONE) + @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE) +#endignore + public void testEntrySetIteratorRemove() { + Set entrySet = getMap().ENTRY_SET(); + Iterator entryItr = entrySet.iterator(); + assertEquals(e0(), entryItr.next()); + entryItr.remove(); + assertTrue(getMap().isEmpty()); + assertFalse(entrySet.contains(e0())); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSetValue() { + for (MAP.Entry KEY_VALUE_GENERIC_TYPE entry : getMap().ENTRY_SET()) { + if (KEY_EQUALS(entry.ENTRY_KEY(), k0())) { + assertEquals("entry.setValue() should return the old value", v0(), entry.setValue(v3())); + break; + } + } + expectReplacement(entry(k0(), v3())); + } + +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapEqualsTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapEqualsTester.template new file mode 100644 index 00000000..4d0df87c --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapEqualsTester.template @@ -0,0 +1,95 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +import java.util.AbstractMap; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.maps.impl.hash.HASH_MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.objects.collections.ObjectCollection; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; +import speiger.src.testers.objects.utils.ObjectHelpers; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapEqualsTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ + public void testEquals_otherMapWithSameEntries() { + assertTrue("A Map should equal any other Map containing the same entries.", getMap().equals(newHashMap(getSampleEntries()))); + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testEquals_otherMapWithDifferentEntries() { + MAP KEY_VALUE_GENERIC_TYPE other = newHashMap(getSampleEntries(getNumEntries() - 1)); + other.put(k3(), v3()); + assertFalse("A Map should not equal another Map containing different entries.", getMap().equals(other)); + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testEquals_smallerMap() { + ObjectCollection fewerEntries = getSampleEntries(getNumEntries() - 1); + assertFalse("Maps of different sizes should not be equal.", getMap().equals(newHashMap(fewerEntries))); + } + + public void testEquals_largerMap() { + ObjectCollection moreEntries = getSampleEntries(getNumEntries() + 1); + assertFalse("Maps of different sizes should not be equal.", getMap().equals(newHashMap(moreEntries))); + } + + public void testEquals_list() { + assertFalse("A List should never equal a Map.", getMap().equals(ObjectHelpers.copyToList(getMap().ENTRY_SET()))); + } + +#ignore + @CollectionSize.Require(CollectionSize.ONE) +#endignore + public void testEquals_EntryMatches() { + MAP.Entry KEY_VALUE_GENERIC_TYPE entry = e0(); + assertEquals("The Entries should match", entry, getMap().ENTRY_SET().iterator().next()); + } + +#ignore + @CollectionSize.Require(CollectionSize.ONE) +#endignore + public void testEquals_EntryMatchesObject() { + MAP.Entry KEY_VALUE_GENERIC_TYPE entry = e0(); + assertEquals("The Entries should match", new AbstractMap.SimpleEntry<>(entry), getMap().ENTRY_SET().iterator().next()); + } + +#ignore + @CollectionSize.Require(CollectionSize.ONE) +#endignore + public void testEquals_EntryNotMatches() { + MAP.Entry KEY_VALUE_GENERIC_TYPE entry = e3(); + assertFalse("The Entries should match", getMap().ENTRY_SET().iterator().next().equals(entry)); + } + +#ignore + @CollectionSize.Require(CollectionSize.ONE) +#endignore + public void testEquals_EntryNotMatchesObject() { + MAP.Entry KEY_VALUE_GENERIC_TYPE entry = e3(); + assertFalse("The Entries should match", getMap().ENTRY_SET().iterator().next().equals(new AbstractMap.SimpleEntry<>(entry))); + } + +#ignore + @CollectionSize.Require(CollectionSize.ONE) +#endignore + public void testEquals_EntryNotMatchingNull() { + assertFalse("The Entries should match", getMap().ENTRY_SET().iterator().next().equals(null)); + } + + private static GENERIC_KEY_VALUE_BRACES MAP KEY_VALUE_GENERIC_TYPE newHashMap(ObjectCollection entries) { + MAP KEY_VALUE_GENERIC_TYPE map = new HASH_MAPKV_BRACES(); + for (MAP.Entry KEY_VALUE_GENERIC_TYPE entry : entries) { + map.put(entry.ENTRY_KEY(), entry.ENTRY_VALUE()); + } + return map; + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapForEachTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapForEachTester.template new file mode 100644 index 00000000..73b771ae --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapForEachTester.template @@ -0,0 +1,59 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER; +#endignore + +import java.util.List; + +import org.junit.Ignore; + +import com.google.common.collect.testing.Helpers; +import com.google.common.collect.testing.features.CollectionFeature; + +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.PACKAGE.utils.maps.MAPS; +import speiger.src.collections.objects.lists.ObjectArrayList; +import speiger.src.collections.objects.lists.ObjectList; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapForEachTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(KNOWN_ORDER) +#endignore + public void testForEachKnownOrder() { + ObjectList entries = new ObjectArrayList<>(); + getMap().forEach((k, v) -> entries.add(entry(k, v))); + assertEquals(getOrderedElements(), entries); + } + +#ignore + @CollectionFeature.Require(absent = KNOWN_ORDER) +#endignore + public void testForEachUnknownOrder() { + List entries = new ObjectArrayList<>(); + getMap().forEach((k, v) -> entries.add(entry(k, v))); + Helpers.assertEqualIgnoringOrder(getSampleEntries(), entries); + } + +#ignore + @CollectionFeature.Require(KNOWN_ORDER) +#endignore + public void testFastForEachKnownOrder() { + ObjectList entries = new ObjectArrayList<>(); + MAPS.fastForEach(getMap(), T -> entries.add(entry(T.ENTRY_KEY(), T.ENTRY_VALUE()))); + assertEquals(getOrderedElements(), entries); + } + +#ignore + @CollectionFeature.Require(absent = KNOWN_ORDER) +#endignore + public void testFastForEachUnknownOrder() { + List entries = new ObjectArrayList<>(); + MAPS.fastForEach(getMap(), T -> entries.add(entry(T.ENTRY_KEY(), T.ENTRY_VALUE()))); + Helpers.assertEqualIgnoringOrder(getSampleEntries(), entries); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapGetOrDefaultTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapGetOrDefaultTester.template new file mode 100644 index 00000000..0601f2a3 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapGetOrDefaultTester.template @@ -0,0 +1,27 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapGetOrDefaultTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @CollectionSize.Require(absent = ZERO) +#endignore + public void testGetOrDefault_present() { + assertEquals("getOrDefault(present, def) should return the associated value", v0(), getMap().getOrDefault(k0(), v3())); + } + + public void testGetOrDefault_absent() { + assertEquals("getOrDefault(absent, def) should return the default value", v3(), getMap().getOrDefault(k3(), v3())); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapGetTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapGetTester.template new file mode 100644 index 00000000..68d26cf7 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapGetTester.template @@ -0,0 +1,40 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapGetTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @CollectionSize.Require(absent = ZERO) +#endignore + public void testGet_yes() { + assertEquals("get(present) should return the associated value", v0(), get(k0())); + } + + public void testGet_no() { + assertEquals("get(notPresent) should return INVALID_VALUE", INVALID_VALUE, get(k3())); + } + +#if !TYPE_OBJECT +#ignore + @CollectionSize.Require(absent = ZERO) +#endignore + public void testGetObject_yes() { + assertEquals("get(present) should return the associated value", VALUE_TO_OBJ(v0()), get(KEY_TO_OBJ(k0()))); + } + + public void testGetObject_no() { + assertEquals("get(notPresent) should return INVALID_VALUE", VALUE_TO_OBJ(INVALID_VALUE), get(KEY_TO_OBJ(k3()))); + } +#endif +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapHashCodeTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapHashCodeTester.template new file mode 100644 index 00000000..6cb5fabf --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapHashCodeTester.template @@ -0,0 +1,27 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#if TYPE_OBJECT || VALUE_OBJECT +import java.util.Objects; +#endif + +import org.junit.Ignore; + +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapHashCodeTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ + public void testHashCode() { + int expectedHashCode = 0; + for (MAP.Entry KEY_VALUE_GENERIC_TYPE entry : getSampleEntries()) { + expectedHashCode += hash(entry); + } + assertEquals("A Map's hashCode() should be the sum of those of its entries.", expectedHashCode, getMap().hashCode()); + } + + private static GENERIC_KEY_VALUE_BRACES int hash(MAP.Entry KEY_VALUE_GENERIC_TYPE e) { + return KEY_TO_HASH(e.ENTRY_KEY()) ^ VALUE_TO_HASH(e.ENTRY_VALUE()); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapIsEmptyTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapIsEmptyTester.template new file mode 100644 index 00000000..320920d3 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapIsEmptyTester.template @@ -0,0 +1,30 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapIsEmptyTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testIsEmpty_yes() { + assertTrue("isEmpty() should return true", getMap().isEmpty()); + } + +#ignore + @CollectionSize.Require(absent = ZERO) +#endignore + public void testIsEmpty_no() { + assertFalse("isEmpty() should return false", getMap().isEmpty()); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapMergeBulkTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapMergeBulkTester.template new file mode 100644 index 00000000..e060435a --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapMergeBulkTester.template @@ -0,0 +1,93 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import junit.framework.AssertionFailedError; +import speiger.src.collections.PACKAGE.utils.maps.MAPS; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapMergeBulkTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#if !VALUE_BOOLEAN +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testAbsent() { + getMap().BULK_MERGE(MAPS.singleton(k3(), v3()), (oldV, newV) -> { + throw new AssertionFailedError("Should not call BULK_MERGE function if key was absent"); + }); + expectAdded(e3()); + } + +#endif +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testBulkMergePresent() { + getMap().BULK_MERGE(MAPS.singleton(k0(), v3()), (oldV, newV) -> { + assertEquals(v0(), oldV); + assertEquals(v3(), newV); + return v4(); + }); + expectReplacement(entry(k0(), v4())); + } + + private static class ExpectedException extends RuntimeException { + private static final long serialVersionUID = 1L; + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testBulkMergeFunctionThrows() { + try { + getMap().BULK_MERGE(MAPS.singleton(k0(), v3()), (oldV, newV) -> { + assertEquals(v0(), oldV); + assertEquals(v3(), newV); + throw new ExpectedException(); + }); + fail("Expected ExpectedException"); + } catch (ExpectedException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testBulkMergePresentToNull() { + getMap().BULK_MERGE(MAPS.singleton(k0(), v3()), (oldV, newV) -> { + assertEquals(v0(), oldV); + assertEquals(v3(), newV); + return INVALID_VALUE; + }); + expectMissing(e0()); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testBulkMergeUnsupported() { + try { + getMap().BULK_MERGE(MAPS.singleton(k3(), v3()), (oldV, newV) -> { + throw new AssertionFailedError(); + }); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapMergeTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapMergeTester.template new file mode 100644 index 00000000..7de2a273 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapMergeTester.template @@ -0,0 +1,93 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import junit.framework.AssertionFailedError; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapMergeTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testAbsent() { + assertEquals("Map.MERGE(absent, value, function) should return value", v3(), + getMap().MERGE(k3(), v3(), (oldV, newV) -> { + throw new AssertionFailedError("Should not call MERGE function if key was absent"); + })); + expectAdded(e3()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testMergePresent() { + assertEquals("Map.MERGE(present, value, function) should return function result", v4(), + getMap().MERGE(k0(), v3(), (oldV, newV) -> { + assertEquals(v0(), oldV); + assertEquals(v3(), newV); + return v4(); + })); + expectReplacement(entry(k0(), v4())); + } + + private static class ExpectedException extends RuntimeException { + private static final long serialVersionUID = 1L; + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testMergeFunctionThrows() { + try { + getMap().MERGE(k0(), v3(), (oldV, newV) -> { + assertEquals(v0(), oldV); + assertEquals(v3(), newV); + throw new ExpectedException(); + }); + fail("Expected ExpectedException"); + } catch (ExpectedException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testMergePresentToNull() { + assertEquals("Map.MERGE(present, value, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, + getMap().MERGE(k0(), v3(), (oldV, newV) -> { + assertEquals(v0(), oldV); + assertEquals(v3(), newV); + return INVALID_VALUE; + })); + expectMissing(e0()); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testMergeUnsupported() { + try { + getMap().MERGE(k3(), v3(), (oldV, newV) -> { + throw new AssertionFailedError(); + }); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutAllArrayTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutAllArrayTester.template new file mode 100644 index 00000000..cfe2aa7a --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutAllArrayTester.template @@ -0,0 +1,243 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore + +import java.util.ConcurrentModificationException; +import java.util.Map; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.collections.PACKAGE.maps.impl.hash.LINKED_HASH_MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.objects.collections.ObjectIterable; +import speiger.src.collections.objects.collections.ObjectIterator; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; +import speiger.src.testers.objects.utils.MinimalObjectCollection; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutAllArrayTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testPutAllArray_supportedNothing() { + getMap().putAll(emptyKeyArray(), emptyValueArray()); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testPutAllObjectArray_supportedNothing() { + getMap().putAll(emptyKeyObjectArray(), emptyValueObjectArray()); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testPutAllArray_unsupportedNothing() { + try { + getMap().putAll(emptyKeyArray(), emptyValueArray()); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testPutAllObjectArray_unsupportedNothing() { + try { + getMap().putAll(emptyKeyObjectArray(), emptyValueObjectArray()); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testPutAllArray_supportedNonePresent() { + putAll(createDisjointCollection()); + expectAdded(e3(), e4()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testPutAllObjectArray_supportedNonePresent() { + putAllObjects(createDisjointCollection()); + expectAdded(e3(), e4()); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testPutAllArray_unsupportedNonePresent() { + try { + putAll(createDisjointCollection()); + fail("putAll(nonePresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + expectMissing(e3(), e4()); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testPutAllObjectArray_unsupportedNonePresent() { + try { + putAllObjects(createDisjointCollection()); + fail("putAll(nonePresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + expectMissing(e3(), e4()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutAllArray_supportedSomePresent() { + putAll(MinimalObjectCollection.of(e3(), e0())); + expectAdded(e3()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutAllObjectArray_supportedSomePresent() { + putAllObjects(MinimalObjectCollection.of(e3(), e0())); + expectAdded(e3()); + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_PUT }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutAllArraySomePresentConcurrentWithEntrySetIteration() { + try { + ObjectIterator iterator = getMap().ENTRY_SET().iterator(); + putAll(MinimalObjectCollection.of(e3(), e0())); + iterator.next(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_PUT }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutAllObjectArraySomePresentConcurrentWithEntrySetIteration() { + try { + ObjectIterator iterator = getMap().ENTRY_SET().iterator(); + putAllObjects(MinimalObjectCollection.of(e3(), e0())); + iterator.next(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutAllArray_unsupportedSomePresent() { + try { + putAll(MinimalObjectCollection.of(e3(), e0())); + fail("putAll(somePresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutAllObjectArray_unsupportedSomePresent() { + try { + putAllObjects(MinimalObjectCollection.of(e3(), e0())); + fail("putAll(somePresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutAllArray_unsupportedAllPresent() { + try { + putAll(MinimalObjectCollection.of(e0())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutAllObjectArray_unsupportedAllPresent() { + try { + putAllObjects(MinimalObjectCollection.of(e0())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testPutAllArray_nullCollectionReference() { + try { + getMap().putAll((KEY_TYPE[])null, (VALUE_TYPE[])null); + fail("putAll(null) should throw NullPointerException"); + } catch (NullPointerException expected) { + } + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testPutAllObjectArray_nullCollectionReference() { + try { + getMap().putAll((CLASS_TYPE[])null, (CLASS_VALUE_TYPE[])null); + fail("putAll(null) should throw NullPointerException"); + } catch (NullPointerException expected) { + } + } + + private void putAll(ObjectIterable entries) { + MAP KEY_VALUE_GENERIC_TYPE map = new LINKED_HASH_MAPKV_BRACES(); + for (MAP.Entry KEY_VALUE_GENERIC_TYPE entry : entries) { + map.put(entry.ENTRY_KEY(), entry.ENTRY_VALUE()); + } + getMap().putAll(map.keySet().TO_ARRAY(NEW_KEY_ARRAY(map.size())), map.values().VALUE_TO_ARRAY(NEW_VALUE_ARRAY(map.size()))); + } + + private void putAllObjects(ObjectIterable entries) { + Map map = new LINKED_HASH_MAPKV_BRACES(); + for (MAP.Entry KEY_VALUE_GENERIC_TYPE entry : entries) { + map.put(entry.ENTRY_KEY(), entry.ENTRY_VALUE()); + } + getMap().putAll(map.keySet().toArray(NEW_CLASS_ARRAY(map.size())), map.values().toArray(NEW_CLASS_VALUE_ARRAY(map.size()))); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutAllTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutAllTester.template new file mode 100644 index 00000000..c085a9fd --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutAllTester.template @@ -0,0 +1,139 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore + +import java.util.ConcurrentModificationException; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.collections.PACKAGE.maps.impl.hash.LINKED_HASH_MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.PACKAGE.utils.maps.MAPS; +import speiger.src.collections.objects.collections.ObjectIterable; +import speiger.src.collections.objects.collections.ObjectIterator; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; +import speiger.src.testers.objects.utils.MinimalObjectCollection; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutAllTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testPutAll_supportedNothing() { + getMap().putAll(emptyMap()); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testPutAll_unsupportedNothing() { + try { + getMap().putAll(emptyMap()); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testPutAll_supportedNonePresent() { + putAll(createDisjointCollection()); + expectAdded(e3(), e4()); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testPutAll_unsupportedNonePresent() { + try { + putAll(createDisjointCollection()); + fail("putAll(nonePresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + expectMissing(e3(), e4()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutAll_supportedSomePresent() { + putAll(MinimalObjectCollection.of(e3(), e0())); + expectAdded(e3()); + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_PUT }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutAllSomePresentConcurrentWithEntrySetIteration() { + try { + ObjectIterator iterator = getMap().ENTRY_SET().iterator(); + putAll(MinimalObjectCollection.of(e3(), e0())); + iterator.next(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutAll_unsupportedSomePresent() { + try { + putAll(MinimalObjectCollection.of(e3(), e0())); + fail("putAll(somePresent) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutAll_unsupportedAllPresent() { + try { + putAll(MinimalObjectCollection.of(e0())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testPutAll_nullCollectionReference() { + try { + getMap().putAll(null); + fail("putAll(null) should throw NullPointerException"); + } catch (NullPointerException expected) { + } + } + + private MAP KEY_VALUE_GENERIC_TYPE emptyMap() { + return MAPS.empty(); + } + + private void putAll(ObjectIterable entries) { + MAP KEY_VALUE_GENERIC_TYPE map = new LINKED_HASH_MAPKV_BRACES(); + for (MAP.Entry KEY_VALUE_GENERIC_TYPE entry : entries) { + map.put(entry.ENTRY_KEY(), entry.ENTRY_VALUE()); + } + getMap().putAll(map); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutIfAbsentTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutIfAbsentTester.template new file mode 100644 index 00000000..aa8b4d6d --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutIfAbsentTester.template @@ -0,0 +1,72 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutIfAbsentTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testPutIfAbsent_supportedAbsent() { + assertEquals("putIfAbsent(notPresent, value) should return INVALID_VALUE", INVALID_VALUE, getMap().putIfAbsent(k3(), v3())); + expectAdded(e3()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutIfAbsent_supportedPresent() { + assertEquals("putIfAbsent(present, value) should return existing value", v0(), getMap().putIfAbsent(k0(), v3())); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testPutIfAbsent_unsupportedAbsent() { + try { + getMap().putIfAbsent(k3(), v3()); + fail("putIfAbsent(notPresent, value) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + expectMissing(e3()); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutIfAbsent_unsupportedPresentExistingValue() { + try { + assertEquals("putIfAbsent(present, existingValue) should return present or throw", v0(), getMap().putIfAbsent(k0(), v0())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutIfAbsent_unsupportedPresentDifferentValue() { + try { + getMap().putIfAbsent(k0(), v3()); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutTester.template new file mode 100644 index 00000000..b82bbb5a --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapPutTester.template @@ -0,0 +1,131 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore + +import java.util.ConcurrentModificationException; +import java.util.Iterator; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR; +#if !SAME_TYPE +import speiger.src.collections.PACKAGE.collections.ITERATOR; +#endif +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPut_supportedPresent() { + assertEquals("put(present, value) should return the old value", v0(), getMap().put(k0(), v3())); + expectReplacement(entry(k0(), v3())); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testPut_supportedNotPresent() { + assertEquals("put(notPresent, value) should return INVALID_VALUE", INVALID_VALUE, put(e3())); + expectAdded(e3()); + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_PUT }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutAbsentConcurrentWithEntrySetIteration() { + try { + Iterator iterator = getMap().ENTRY_SET().iterator(); + put(e3()); + iterator.next(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_PUT }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutAbsentConcurrentWithKeySetIteration() { + try { + ITERATOR KEY_GENERIC_TYPE iterator = getMap().keySet().iterator(); + put(e3()); + iterator.NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_PUT }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPutAbsentConcurrentWithValueIteration() { + try { + VALUE_ITERATOR VALUE_GENERIC_TYPE iterator = getMap().values().iterator(); + put(e3()); + iterator.VALUE_NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testPut_unsupportedNotPresent() { + try { + put(e3()); + fail("put(notPresent, value) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + expectMissing(e3()); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPut_unsupportedPresentExistingValue() { + try { + assertEquals("put(present, existingValue) should return present or throw", v0(), put(e0())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testPut_unsupportedPresentDifferentValue() { + try { + getMap().put(k0(), v3()); + fail("put(present, differentValue) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + + private VALUE_TYPE put(MAP.Entry KEY_VALUE_GENERIC_TYPE entry) { + return getMap().put(entry.ENTRY_KEY(), entry.ENTRY_VALUE()); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapRemoveEntryTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapRemoveEntryTester.template new file mode 100644 index 00000000..5a94660c --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapRemoveEntryTester.template @@ -0,0 +1,186 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; +#endignore + +import java.util.AbstractMap; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveEntryTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemove_supportedPresent() { + assertTrue(getMap().remove(k0(), v0())); + expectMissing(e0()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemove_supportedPresentLast() { + assertTrue(getMap().remove(k2(), v2())); + expectMissing(e2()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemove_supportedPresentLastWrongValue() { + assertFalse(getMap().remove(k1(), v2())); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemove_supportedPresentKeyWrongValue() { + assertFalse(getMap().remove(k0(), v3())); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemove_supportedWrongKeyPresentValue() { + assertFalse(getMap().remove(k3(), v0())); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemove_supportedAbsentKeyAbsentValue() { + assertFalse(getMap().remove(k3(), v3())); + expectUnchanged(); + } + +#if !TYPE_OBJECT +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveObject_supportedPresent() { + assertTrue(getMap().remove(KEY_TO_OBJ(k0()), VALUE_TO_OBJ(v0()))); + expectMissing(e0()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemoveObject_supportedPresentLast() { + assertTrue(getMap().remove(KEY_TO_OBJ(k2()), VALUE_TO_OBJ(v2()))); + expectMissing(e2()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemoveObject_supportedPresentLastWrongValue() { + assertFalse(getMap().remove(KEY_TO_OBJ(k1()), VALUE_TO_OBJ(v2()))); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemoveObject_supportedPresentKeyWrongValue() { + assertFalse(getMap().remove(KEY_TO_OBJ(k0()), VALUE_TO_OBJ(v3()))); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemoveObject_supportedWrongKeyPresentValue() { + assertFalse(getMap().remove(KEY_TO_OBJ(k3()), VALUE_TO_OBJ(v0()))); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemoveObject_supportedAbsentKeyAbsentValue() { + assertFalse(getMap().remove(KEY_TO_OBJ(k3()), VALUE_TO_OBJ(v3()))); + expectUnchanged(); + } + +#endif +#ignore + @CollectionSize.Require(ONE) + @MapFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemove_supportedEntryPresent() { + assertTrue(getMap().ENTRY_SET().remove(e0())); + expectMissing(e0()); + } + +#ignore + @CollectionSize.Require(ONE) + @MapFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemove_supportedObjectEntryPresent() { + assertTrue(getMap().ENTRY_SET().remove(new AbstractMap.SimpleEntry<>(e0()))); + expectMissing(e0()); + } + +#ignore + @CollectionSize.Require(ONE) + @MapFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemove_supportedEntryMissing() { + assertFalse(getMap().ENTRY_SET().remove(e3())); + expectUnchanged(); + } + +#ignore + @CollectionSize.Require(ONE) + @MapFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemove_supportedObjectEntryMissing() { + assertFalse(getMap().ENTRY_SET().remove(new AbstractMap.SimpleEntry<>(e3()))); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemove_unsupportedPresent() { + try { + getMap().remove(k0(), v0()); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testRemove_unsupportedAbsent() { + try { + assertFalse(getMap().remove(k0(), v3())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapRemoveOrDefaultTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapRemoveOrDefaultTester.template new file mode 100644 index 00000000..d4cdb25a --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapRemoveOrDefaultTester.template @@ -0,0 +1,121 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; +#endignore + +import java.util.ConcurrentModificationException; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +#if !VALUE_OBJECT +import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR; +#endif +#if !TYPE_OBJECT && !SAME_TYPE +import speiger.src.collections.PACKAGE.collections.ITERATOR; +#endif +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.objects.collections.ObjectIterator; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveOrDefaultTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemove_present() { + int initialSize = getMap().size(); + assertEquals("remove(present) should return the associated value", v0(), getMap().REMOVE_VALUEOrDefault(k0(), v1())); + assertEquals("remove(present) should decrease a map's size by one.", initialSize - 1, getMap().size()); + expectMissing(e0()); + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE }) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemovePresentConcurrentWithEntrySetIteration() { + try { + ObjectIterator iterator = getMap().ENTRY_SET().iterator(); + getMap().REMOVE_VALUEOrDefault(k0(), v0()); + iterator.next(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE }) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemovePresentConcurrentWithKeySetIteration() { + try { + ITERATOR KEY_GENERIC_TYPE iterator = getMap().keySet().iterator(); + getMap().REMOVE_VALUEOrDefault(k0(), v0()); + iterator.NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE }) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemovePresentConcurrentWithValuesIteration() { + try { + VALUE_ITERATOR VALUE_GENERIC_TYPE iterator = getMap().values().iterator(); + getMap().REMOVE_VALUEOrDefault(k0(), v0()); + iterator.VALUE_NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemove_notPresent() { + assertEquals("remove(notPresent) should return "+v3(), v3(), getMap().REMOVE_VALUEOrDefault(k3(), v3())); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemove_unsupported() { + try { + getMap().REMOVE_VALUEOrDefault(k0(), v0()); + fail("remove(present) should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + assertEquals("remove(present) should not remove the element", v0(), get(k0())); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testRemove_unsupportedNotPresent() { + try { + assertNull("remove(notPresent) should return null or throw UnsupportedOperationException", getMap().REMOVE_VALUEOrDefault(k3(), v3())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + expectMissing(e3()); + } + +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapRemoveTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapRemoveTester.template new file mode 100644 index 00000000..c97c8b27 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapRemoveTester.template @@ -0,0 +1,225 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; +#endignore + +import java.util.ConcurrentModificationException; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +#if !VALUE_OBJECT +import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR; +#endif +#if !TYPE_OBJECT && !SAME_TYPE +import speiger.src.collections.PACKAGE.collections.ITERATOR; +#endif +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.objects.collections.ObjectIterator; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemove_present() { + int initialSize = getMap().size(); + assertEquals("remove(present) should return the associated value", v0(), getMap().REMOVE_VALUE(k0())); + assertEquals("remove(present) should decrease a map's size by one.", initialSize - 1, getMap().size()); + expectMissing(e0()); + } + +#if !TYPE_OBJECT + enum WrongType { + INSTANCE; + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemove_WrongType() { + assertFalse("Should return false if the wrong type is going to be removed", getMap().remove(WrongType.INSTANCE, v0())); + } + +#endif +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemove_lastPresent() { + int initialSize = getMap().size(); + assertEquals("remove(present) should return the associated value", v2(), getMap().REMOVE_VALUE(k2())); + assertEquals("remove(present) should decrease a map's size by one.", initialSize - 1, getMap().size()); + expectMissing(e2()); + } + +#if !TYPE_OBJECT +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveObject_present() { + int initialSize = getMap().size(); + assertEquals("remove(present) should return the associated value", VALUE_TO_OBJ(v0()), getMap().remove(KEY_TO_OBJ(k0()))); + assertEquals("remove(present) should decrease a map's size by one.", initialSize - 1, getMap().size()); + expectMissing(e0()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemoveObject_presentLast() { + int initialSize = getMap().size(); + assertEquals("remove(present) should return the associated value", VALUE_TO_OBJ(v2()), getMap().remove(KEY_TO_OBJ(k2()))); + assertEquals("remove(present) should decrease a map's size by one.", initialSize - 1, getMap().size()); + expectMissing(e2()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveObject_missing() { + int initialSize = getMap().size(); + assertEquals("remove(missing) should return the associated value", VALUE_TO_OBJ(INVALID_VALUE), getMap().remove(KEY_TO_OBJ(k3()))); + assertEquals("remove(missing) should not have changed in size.", initialSize, getMap().size()); + expectUnchanged(); + } + +#endif +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE }) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemovePresentConcurrentWithEntrySetIteration() { + try { + ObjectIterator iterator = getMap().ENTRY_SET().iterator(); + getMap().REMOVE_VALUE(k0()); + iterator.next(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#if !TYPE_OBJECT +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE }) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemoveObjectPresentConcurrentWithEntrySetIteration() { + try { + ObjectIterator iterator = getMap().ENTRY_SET().iterator(); + getMap().remove(KEY_TO_OBJ(k0())); + iterator.next(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#endif +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE }) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemovePresentConcurrentWithKeySetIteration() { + try { + ITERATOR KEY_GENERIC_TYPE iterator = getMap().keySet().iterator(); + getMap().REMOVE_VALUE(k0()); + iterator.NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE }) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemovePresentConcurrentWithValuesIteration() { + try { + VALUE_ITERATOR VALUE_GENERIC_TYPE iterator = getMap().values().iterator(); + getMap().REMOVE_VALUE(k0()); + iterator.VALUE_NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemove_notPresent() { + assertEquals("remove(notPresent) should return INVALID_VALUE", INVALID_VALUE, getMap().REMOVE_VALUE(k3())); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemove_unsupported() { + try { + getMap().REMOVE_VALUE(k0()); + fail("remove(present) should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + assertEquals("remove(present) should not remove the element", v0(), get(k0())); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testRemove_unsupportedNotPresent() { + try { + assertEquals("remove(notPresent) should return INVALID_VALUE or throw UnsupportedOperationException", INVALID_VALUE, getMap().REMOVE_VALUE(k3())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + expectMissing(e3()); + } + +#if !TYPE_OBJECT +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemoveObject_unsupported() { + try { + getMap().remove(KEY_TO_OBJ(k0())); + fail("remove(present) should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + assertEquals("remove(present) should not remove the element", VALUE_TO_OBJ(v0()), get(KEY_TO_OBJ(k0()))); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testRemoveObject_unsupportedNotPresent() { + try { + assertEquals("remove(notPresent) should return INVALID_VALUE or throw UnsupportedOperationException", VALUE_TO_OBJ(INVALID_VALUE), getMap().remove(KEY_TO_OBJ(k3()))); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + expectMissing(e3()); + } +#endif +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapReplaceAllTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapReplaceAllTester.template new file mode 100644 index 00000000..79ceaa2f --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapReplaceAllTester.template @@ -0,0 +1,110 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.objects.lists.ObjectArrayList; +import speiger.src.collections.objects.lists.ObjectList; +import speiger.src.testers.VALUE_PACKAGE.utils.VALUE_SAMPLE_ELEMENTS; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; +#if !SAME_TYPE +import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS; +#endif + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceAllTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ + private SAMPLE_ELEMENTS KEY_GENERIC_TYPE keys() { + return new SAMPLE_ELEMENTSBRACES(k0(), k1(), k2(), k3(), k4()); + } + + private VALUE_SAMPLE_ELEMENTS VALUE_GENERIC_TYPE values() { + return new VALUE_SAMPLE_ELEMENTSVALUE_BRACES(v0(), v1(), v2(), v3(), v4()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testReplaceAllRotate() { + getMap().REPLACE_VALUES((k, v) -> { + int index = keys().asList().indexOf(k); + return values().asList().VALUE_GET_KEY(index + 1); + }); + ObjectList expectedEntries = new ObjectArrayList<>(); + for (MAP.Entry KEY_VALUE_GENERIC_TYPE entry : getSampleEntries()) { + int index = keys().asList().indexOf(entry.ENTRY_KEY()); + expectedEntries.add(entry(entry.ENTRY_KEY(), values().asList().VALUE_GET_KEY(index + 1))); + } + expectContents(expectedEntries); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionFeature.Require(KNOWN_ORDER) +#endignore + public void testReplaceAllPreservesOrder() { + getMap().REPLACE_VALUES((k, v) -> { + int index = keys().asList().indexOf(k); + return values().asList().VALUE_GET_KEY(index + 1); + }); + ObjectList orderedEntries = getOrderedElements(); + int index = 0; + for (KEY_TYPE key : getMap().keySet()) { + assertEquals(orderedEntries.get(index).ENTRY_KEY(), key); + index++; + } + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testReplaceAll_unsupported() { + try { + getMap().REPLACE_VALUES((k, v) -> { + int index = keys().asList().indexOf(k); + return values().asList().VALUE_GET_KEY(index + 1); + }); + fail("REPLACE_VALUES() should throw UnsupportedOperation if a map does " + "not support it and is not empty."); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(ZERO) +#endignore + public void testReplaceAll_unsupportedByEmptyCollection() { + try { + getMap().REPLACE_VALUES((k, v) -> { + int index = keys().asList().indexOf(k); + return values().asList().VALUE_GET_KEY(index + 1); + }); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testReplaceAll_unsupportedNoOpFunction() { + try { + getMap().REPLACE_VALUES((k, v) -> v); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapReplaceEntryTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapReplaceEntryTester.template new file mode 100644 index 00000000..a1d097e5 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapReplaceEntryTester.template @@ -0,0 +1,93 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceEntryTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testReplaceEntry_supportedPresent() { + try { + assertTrue(getMap().replace(k0(), v0(), v3())); + expectReplacement(entry(k0(), v3())); + } catch (ClassCastException tolerated) { // for ClassToInstanceMap + expectUnchanged(); + } + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testReplaceEntry_supportedPresentUnchanged() { + assertTrue(getMap().replace(k0(), v0(), v0())); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testReplaceEntry_supportedWrongValue() { + assertFalse(getMap().replace(k0(), v3(), v4())); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testReplaceEntry_supportedAbsentKey() { + assertFalse(getMap().replace(k3(), v3(), v4())); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testReplaceEntry_unsupportedPresent() { + try { + getMap().replace(k0(), v0(), v3()); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testReplaceEntry_unsupportedWrongValue() { + try { + getMap().replace(k0(), v3(), v4()); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testReplaceEntry_unsupportedAbsentKey() { + try { + getMap().replace(k3(), v3(), v4()); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapReplaceTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapReplaceTester.template new file mode 100644 index 00000000..ed3694c5 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapReplaceTester.template @@ -0,0 +1,63 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testReplace_supportedPresent() { + try { + assertEquals(v0(), getMap().replace(k0(), v3())); + expectReplacement(entry(k0(), v3())); + } catch (ClassCastException tolerated) { // for ClassToInstanceMap + expectUnchanged(); + } + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testReplace_supportedPresentNoChange() { + assertEquals(v0(), getMap().replace(k0(), v0())); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testReplace_supportedAbsent() { + assertEquals(INVALID_VALUE, getMap().replace(k3(), v3())); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testReplace_unsupportedPresent() { + try { + getMap().replace(k0(), v3()); + fail("Expected UnsupportedOperationException"); + } catch (UnsupportedOperationException expected) { + } catch (ClassCastException tolerated) { + // for ClassToInstanceMap + } + expectUnchanged(); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSizeTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSizeTester.template new file mode 100644 index 00000000..bd08454c --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSizeTester.template @@ -0,0 +1,14 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +import org.junit.Ignore; + +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSizeTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE { + + public void testSize() { + assertEquals("size():", getNumElements(), getMap().size()); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSubFromTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSubFromTester.template new file mode 100644 index 00000000..4f988356 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSubFromTester.template @@ -0,0 +1,148 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +import org.junit.Ignore; + +#if VALUE_PRIMITIVES +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; +#endignore + +import java.util.ConcurrentModificationException; +import java.util.Iterator; + + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR; +#if !SAME_TYPE +import speiger.src.collections.PACKAGE.collections.ITERATOR; +#endif +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +#endif +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSubFromTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#if VALUE_PRIMITIVES +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testSubFrom_supportedPresent() { + assertEquals("subFrom(present, value) should return the old value", v1(), getMap().subFrom(k1(), v3())); + expectMissing(e1()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testSubFrom_supportedNotPresent() { + assertEquals("subFrom(notPresent, value) should return INVALID_VALUE", INVALID_VALUE, subFrom(e3())); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testSubFromSum_supportedNotPresent() { + assertEquals("subFrom(notPresent, value) should return "+v2(), v2(), getMap().subFrom(k2(), v3())); + assertEquals("subFrom(notPresent, value) should return INVALID_VALUE", INVALID_VALUE, subFrom(e2())); + expectMissing(e2()); + } + + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSubFromAbsentConcurrentWithEntrySetIteration() { + try { + Iterator iterator = getMap().ENTRY_SET().iterator(); + subFrom(e3()); + iterator.next(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSubFromAbsentConcurrentWithKeySetIteration() { + try { + ITERATOR KEY_GENERIC_TYPE iterator = getMap().keySet().iterator(); + subFrom(e3()); + iterator.NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE }) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSubFromAbsentConcurrentWithValueIteration() { + try { + VALUE_ITERATOR VALUE_GENERIC_TYPE iterator = getMap().values().iterator(); + subFrom(e3()); + iterator.VALUE_NEXT(); + fail("Expected ConcurrentModificationException"); + } catch (ConcurrentModificationException expected) { + // success + } + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testSubFrom_unsupportedNotPresent() { + try { + subFrom(e3()); + fail("subFrom(notPresent, value) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + expectMissing(e3()); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSubFrom_unsupportedPresentExistingValue() { + try { + assertEquals("subFrom(present, existingValue) should return present or throw", v0(), subFrom(e0())); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSubFrom_unsupportedPresentDifferentValue() { + try { + getMap().subFrom(k0(), v3()); + fail("subFrom(present, differentValue) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + + private VALUE_TYPE subFrom(MAP.Entry KEY_VALUE_GENERIC_TYPE entry) { + return getMap().subFrom(entry.ENTRY_KEY(), entry.ENTRY_VALUE()); + } +#endif +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSupplyIfAbsentTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSupplyIfAbsentTester.template new file mode 100644 index 00000000..868edfbb --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapSupplyIfAbsentTester.template @@ -0,0 +1,131 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore +#if !VALUE_BOOLEAN +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ONE; +#endignore +#endif + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import junit.framework.AssertionFailedError; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testSupplyIfAbsent_supportedAbsent() { + assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), + getMap().SUPPLY_IF_ABSENT(k3(), this::v3)); + expectAdded(e3()); + } + +#if !VALUE_BOOLEAN +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(ONE) +#endignore + public void testSupplyIfAbsent_supportedAbsentFirst() { + getMap().setDefaultReturnValue(v0()); + assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), + getMap().SUPPLY_IF_ABSENT(k0(), this::v3)); + expectContents(entry(k0(), v3())); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(ONE) +#endignore + public void testSupplyIfAbsent_supportedAbsentSameResult() { + getMap().setDefaultReturnValue(v0()); + assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v0(), + getMap().SUPPLY_IF_ABSENT(k0(), this::v0)); + expectUnchanged(); + } + +#endif +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSupplyIfAbsent_supportedPresent() { + assertEquals("SUPPLY_IF_ABSENT(present, function) should return existing value", v0(), + getMap().SUPPLY_IF_ABSENT(k0(), () -> { + throw new AssertionFailedError(); + })); + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testSupplyIfAbsent_functionReturnsNullNotInserted() { + assertEquals("SUPPLY_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().SUPPLY_IF_ABSENT(k3(), () -> INVALID_VALUE)); + expectUnchanged(); + } + + static class ExpectedException extends RuntimeException { + private static final long serialVersionUID = 1L; + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) +#endignore + public void testSupplyIfAbsent_functionThrows() { + try { + getMap().SUPPLY_IF_ABSENT(k3(), () -> { + throw new ExpectedException(); + }); + fail("Expected ExpectedException"); + } catch (ExpectedException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testSupplyIfAbsent_unsupportedAbsent() { + try { + getMap().SUPPLY_IF_ABSENT(k3(), this::v3); + fail("SUPPLY_IF_ABSENT(notPresent, function) should throw"); + } catch (UnsupportedOperationException expected) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSupplyIfAbsent_unsupportedPresentExistingValue() { + try { + assertEquals("SUPPLY_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENT(k0(), this::v0)); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testSupplyIfAbsent_unsupportedPresentDifferentValue() { + try { + assertEquals("SUPPLY_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENT(k0(), this::v3)); + } catch (UnsupportedOperationException tolerated) { + } + expectUnchanged(); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapToStringTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapToStringTester.template new file mode 100644 index 00000000..9cf007b6 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/MapToStringTester.template @@ -0,0 +1,58 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.NON_STANDARD_TOSTRING; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import java.util.Set; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.maps.impl.hash.LINKED_HASH_MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapToStringTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ + public void testToString_minimal() { + assertNotNull("toString() should not return null", getMap().toString()); + } + +#ignore + @CollectionSize.Require(ZERO) + @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING) +#endignore + public void testToString_size0() { + assertEquals("emptyMap.toString should return {}", "{}", getMap().toString()); + } + +#ignore + @CollectionSize.Require(ONE) + @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING) +#endignore + public void testToString_size1() { + assertEquals("size1Map.toString should return {entry}", "{" + e0() + "}", getMap().toString()); + } + +#ignore + @CollectionFeature.Require(absent = NON_STANDARD_TOSTRING) +#endignore + public void testToString_formatting() { + assertEquals("map.toString() incorrect", expectedToString(getMap().ENTRY_SET()), getMap().toString()); + } + + private String expectedToString(Set entries) { + MAP KEY_VALUE_GENERIC_TYPE reference = new LINKED_HASH_MAPKV_BRACES(); + for (MAP.Entry KEY_VALUE_GENERIC_TYPE entry : entries) { + reference.put(entry.ENTRY_KEY(), entry.ENTRY_VALUE()); + } + return reference.toString(); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/NavigableMapNavigationTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/NavigableMapNavigationTester.template new file mode 100644 index 00000000..d3c029c5 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/NavigableMapNavigationTester.template @@ -0,0 +1,333 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; +#endignore + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +#if !TYPE_OBJECT +import speiger.src.collections.PACKAGE.functions.COMPARATOR; +#endif +import speiger.src.collections.PACKAGE.maps.interfaces.MAP.Entry; +import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP; +import speiger.src.collections.objects.lists.ObjectArrayList; +import speiger.src.collections.objects.lists.ObjectList; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; +import speiger.src.testers.objects.utils.ObjectHelpers; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPENavigableMapNavigationTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ + private NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE navigableMap; + private List entries; + private Entry KEY_VALUE_GENERIC_TYPE a; + private Entry KEY_VALUE_GENERIC_TYPE b; + private Entry KEY_VALUE_GENERIC_TYPE c; + + @Override + public void setUp() throws Exception { + super.setUp(); + navigableMap = (NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE) getMap(); + entries = ObjectHelpers.copyToList(getSampleElements(getNumElements())); + entries.sort(entryComparator(navigableMap.comparator())); + if (entries.size() >= 1) { + a = entries.get(0); + if (entries.size() >= 3) { + b = entries.get(1); + c = entries.get(2); + } + } + } + + public static GENERIC_KEY_VALUE_BRACES Comparator entryComparator(COMPARATOR KEY_GENERIC_TYPE keyComparator) { + return new Comparator() { + @Override + public int compare(Entry KEY_VALUE_GENERIC_TYPE a, Entry KEY_VALUE_GENERIC_TYPE b) { + return (keyComparator == null) ? COMPAREABLE_TO_KEY(a.ENTRY_KEY(), b.ENTRY_KEY()) : keyComparator.compare(a.ENTRY_KEY(), b.ENTRY_KEY()); + } + }; + } + + @SuppressWarnings("unchecked") + private void resetWithHole() { + Entry KEY_VALUE_GENERIC_TYPE[] entries = new Entry[] { a, c }; + super.resetMap(entries); + navigableMap = (NAVIGABLE_MAP KEY_VALUE_GENERIC_TYPE) getMap(); + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapFirst() { + assertNull(navigableMap.firstEntry()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapPollFirst() { + assertNull(navigableMap.pollFirstEntry()); + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapNearby() { +#if TYPE_OBJECT + assertNull(navigableMap.lowerEntry(k0())); + assertNull(navigableMap.lowerKey(k0())); + assertNull(navigableMap.floorEntry(k0())); + assertNull(navigableMap.floorKey(k0())); + assertNull(navigableMap.ceilingEntry(k0())); + assertNull(navigableMap.ceilingKey(k0())); + assertNull(navigableMap.higherEntry(k0())); + assertNull(navigableMap.higherKey(k0())); +#else + assertNull(navigableMap.lowerEntry(k0())); + assertEquals(CLASS_TYPE.MAX_VALUE, navigableMap.lowerKey(k0())); + assertNull(navigableMap.floorEntry(k0())); + assertEquals(CLASS_TYPE.MAX_VALUE, navigableMap.floorKey(k0())); + assertNull(navigableMap.ceilingEntry(k0())); + assertEquals(CLASS_TYPE.MIN_VALUE, navigableMap.ceilingKey(k0())); + assertNull(navigableMap.higherEntry(k0())); + assertEquals(CLASS_TYPE.MIN_VALUE, navigableMap.higherKey(k0())); +#endif + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapLast() { + assertNull(navigableMap.lastEntry()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapPollLast() { + assertNull(navigableMap.pollLastEntry()); + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapFirst() { + assertEquals(a, navigableMap.firstEntry()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapPollFirst() { + assertEquals(a, navigableMap.pollFirstEntry()); + assertTrue(navigableMap.isEmpty()); + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapNearby() { +#if TYPE_OBJECT + assertNull(navigableMap.lowerEntry(k0())); + assertNull(navigableMap.lowerKey(k0())); + assertEquals(a, navigableMap.floorEntry(k0())); + assertEquals(a.ENTRY_KEY(), navigableMap.floorKey(k0())); + assertEquals(a, navigableMap.ceilingEntry(k0())); + assertEquals(a.ENTRY_KEY(), navigableMap.ceilingKey(k0())); + assertNull(navigableMap.higherEntry(k0())); + assertNull(navigableMap.higherKey(k0())); +#else + assertNull(navigableMap.lowerEntry(k0())); + assertEquals(CLASS_TYPE.MAX_VALUE, navigableMap.lowerKey(k0())); + assertEquals(a, navigableMap.floorEntry(k0())); + assertEquals(a.ENTRY_KEY(), navigableMap.floorKey(k0())); + assertEquals(a, navigableMap.ceilingEntry(k0())); + assertEquals(a.ENTRY_KEY(), navigableMap.ceilingKey(k0())); + assertNull(navigableMap.higherEntry(k0())); + assertEquals(CLASS_TYPE.MIN_VALUE, navigableMap.higherKey(k0())); +#endif + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapLast() { + assertEquals(a, navigableMap.lastEntry()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapPollLast() { + assertEquals(a, navigableMap.pollLastEntry()); + assertTrue(navigableMap.isEmpty()); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testFirst() { + assertEquals(a, navigableMap.firstEntry()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testPollFirst() { + assertEquals(a, navigableMap.pollFirstEntry()); + assertEquals(entries.subList(1, entries.size()), ObjectHelpers.copyToList(navigableMap.ENTRY_SET())); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testPollFirstUnsupported() { + try { + navigableMap.pollFirstEntry(); + fail(); + } catch (UnsupportedOperationException e) { + } + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testLower() { + resetWithHole(); + assertEquals(null, navigableMap.lowerEntry(a.ENTRY_KEY())); +#if TYPE_OBJECT + assertNull(navigableMap.lowerKey(a.ENTRY_KEY())); +#else + assertEquals(CLASS_TYPE.MAX_VALUE, navigableMap.lowerKey(a.ENTRY_KEY())); +#endif + assertEquals(a, navigableMap.lowerEntry(b.ENTRY_KEY())); + assertEquals(a.ENTRY_KEY(), navigableMap.lowerKey(b.ENTRY_KEY())); + assertEquals(a, navigableMap.lowerEntry(c.ENTRY_KEY())); + assertEquals(a.ENTRY_KEY(), navigableMap.lowerKey(c.ENTRY_KEY())); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testFloor() { + resetWithHole(); + assertEquals(a, navigableMap.floorEntry(a.ENTRY_KEY())); + assertEquals(a.ENTRY_KEY(), navigableMap.floorKey(a.ENTRY_KEY())); + assertEquals(a, navigableMap.floorEntry(b.ENTRY_KEY())); + assertEquals(a.ENTRY_KEY(), navigableMap.floorKey(b.ENTRY_KEY())); + assertEquals(c, navigableMap.floorEntry(c.ENTRY_KEY())); + assertEquals(c.ENTRY_KEY(), navigableMap.floorKey(c.ENTRY_KEY())); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testCeiling() { + resetWithHole(); + assertEquals(a, navigableMap.ceilingEntry(a.ENTRY_KEY())); + assertEquals(a.ENTRY_KEY(), navigableMap.ceilingKey(a.ENTRY_KEY())); + assertEquals(c, navigableMap.ceilingEntry(b.ENTRY_KEY())); + assertEquals(c.ENTRY_KEY(), navigableMap.ceilingKey(b.ENTRY_KEY())); + assertEquals(c, navigableMap.ceilingEntry(c.ENTRY_KEY())); + assertEquals(c.ENTRY_KEY(), navigableMap.ceilingKey(c.ENTRY_KEY())); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testHigher() { + resetWithHole(); + assertEquals(c, navigableMap.higherEntry(a.ENTRY_KEY())); + assertEquals(c.ENTRY_KEY(), navigableMap.higherKey(a.ENTRY_KEY())); + assertEquals(c, navigableMap.higherEntry(b.ENTRY_KEY())); + assertEquals(c.ENTRY_KEY(), navigableMap.higherKey(b.ENTRY_KEY())); + assertEquals(null, navigableMap.higherEntry(c.ENTRY_KEY())); +#if TYPE_OBJECT + assertNull(navigableMap.higherKey(c.ENTRY_KEY())); +#else + assertEquals(CLASS_TYPE.MIN_VALUE, navigableMap.higherKey(c.ENTRY_KEY())); +#endif + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testLast() { + assertEquals(c, navigableMap.lastEntry()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testPollLast() { + assertEquals(c, navigableMap.pollLastEntry()); + assertEquals(entries.subList(0, entries.size() - 1), ObjectHelpers.copyToList(navigableMap.ENTRY_SET())); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testPollLastUnsupported() { + try { + navigableMap.pollLastEntry(); + fail(); + } catch (UnsupportedOperationException e) { + } + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testDescendingNavigation() { + ObjectList descending = new ObjectArrayList<>(navigableMap.descendingMap().ENTRY_SET()); + Collections.reverse(descending); + assertEquals(entries, descending); + } + +#ignore + @CollectionSize.Require(absent = ZERO) +#endignore + public void testHeadMapExclusive() { + assertFalse(navigableMap.headMap(a.ENTRY_KEY(), false).containsKey(a.ENTRY_KEY())); + } + +#ignore + @CollectionSize.Require(absent = ZERO) +#endignore + public void testHeadMapInclusive() { + assertTrue(navigableMap.headMap(a.ENTRY_KEY(), true).containsKey(a.ENTRY_KEY())); + } + +#ignore + @CollectionSize.Require(absent = ZERO) +#endignore + public void testTailMapExclusive() { + assertFalse(navigableMap.tailMap(a.ENTRY_KEY(), false).containsKey(a.ENTRY_KEY())); + } + +#ignore + @CollectionSize.Require(absent = ZERO) +#endignore + public void testTailMapInclusive() { + assertTrue(navigableMap.tailMap(a.ENTRY_KEY(), true).containsKey(a.ENTRY_KEY())); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/OrderedMapMoveTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/OrderedMapMoveTester.template new file mode 100644 index 00000000..351f2c93 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/OrderedMapMoveTester.template @@ -0,0 +1,374 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +import static org.junit.Assert.assertNotEquals; +#endignore + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP; +import speiger.src.collections.objects.lists.ObjectList; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; +import speiger.src.testers.objects.utils.ObjectHelpers; + +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapMoveTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ + private ORDERED_MAP KEY_VALUE_GENERIC_TYPE orderedMap; + private ObjectList values; + private KEY_TYPE a; + private VALUE_TYPE aValue; + private KEY_TYPE c; + private VALUE_TYPE cValue; + + @Override + public void setUp() throws Exception { + super.setUp(); + orderedMap = (ORDERED_MAP KEY_VALUE_GENERIC_TYPE)getMap(); + values = ObjectHelpers.copyToList(getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements())); + if (values.size() >= 1) { + a = values.get(0).ENTRY_KEY(); + aValue = values.get(0).ENTRY_VALUE(); + if (values.size() >= 3) { + c = values.get(2).ENTRY_KEY(); + cValue = values.get(2).ENTRY_VALUE(); + } + } + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testaddMoveToFirstMissing() + { + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(INVALID_VALUE, orderedMap.putAndMoveToFirst(k4(), v4())); + assertNotEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(k4(), orderedMap.FIRST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testaddMoveToFirstPreset() + { + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(cValue, orderedMap.putAndMoveToFirst(c, v4())); + assertNotEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(c, orderedMap.FIRST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testaddMoveToLastMissing() + { + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(INVALID_VALUE, orderedMap.putAndMoveToLast(k4(), v4())); + assertNotEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(k4(), orderedMap.LAST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testaddMoveToLastPreset() + { + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(aValue, orderedMap.putAndMoveToLast(a, v4())); + assertNotEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(a, orderedMap.LAST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveToFirstMissing() + { + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(false, orderedMap.moveToFirst(k4())); + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveToFirstPreset() + { + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(true, orderedMap.moveToFirst(c)); + assertNotEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(c, orderedMap.FIRST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveToLastMissing() + { + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(false, orderedMap.moveToLast(k4())); + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveToLastPreset() + { + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(true, orderedMap.moveToLast(a)); + assertNotEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(a, orderedMap.LAST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testGetAndMoveToFirstMissing() + { + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(INVALID_VALUE, orderedMap.getAndMoveToFirst(k4())); + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testGetAndMoveToFirstPreset() + { + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(cValue, orderedMap.getAndMoveToFirst(c)); + assertNotEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(c, orderedMap.FIRST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testGetAndMoveToLastMissing() + { + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(INVALID_VALUE, orderedMap.getAndMoveToLast(k4())); + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testGetAndMoveToLastPreset() + { + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(aValue, orderedMap.getAndMoveToLast(a)); + assertNotEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(a, orderedMap.LAST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testaddMoveToFirstUnsupported() + { + try { + orderedMap.putAndMoveToFirst(k4(), v4()); + fail("addAndMoveToFirst should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testaddMoveToLastUnsupported() + { + try { + orderedMap.putAndMoveToFirst(k4(), v4()); + fail("addAndMoveToLast should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testMoveToFirstUnsupported() + { + try { + orderedMap.moveToFirst(c); + fail("moveToFirst should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testMoveToLastUnsupported() + { + try { + orderedMap.moveToLast(a); + fail("moveToLast should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testGetAndMoveToFirstUnsupported() + { + try { + orderedMap.getAndMoveToFirst(c); + fail("getAndMoveToFirst should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_PUT) +#endignore + public void testGetMoveToLastUnsupported() + { + try { + orderedMap.getAndMoveToLast(a); + fail("getAndMoveToLast should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveCenterToLast() + { + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertTrue(orderedMap.moveToLast(k1())); + assertNotEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(k1(), orderedMap.LAST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveCenterToFirst() + { + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertTrue(orderedMap.moveToFirst(k1())); + assertNotEquals(c, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(k1(), orderedMap.FIRST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveForthAndBack() + { + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertTrue(orderedMap.moveToLast(k0())); + assertNotEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(a, orderedMap.LAST_ENTRY_KEY()); + assertNotEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertTrue(orderedMap.moveToFirst(k0())); + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveBackAndForth() + { + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertTrue(orderedMap.moveToFirst(k2())); + assertNotEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(c, orderedMap.FIRST_ENTRY_KEY()); + assertNotEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertTrue(orderedMap.moveToLast(k2())); + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testPutForthAndBack() + { + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(v0(), orderedMap.putAndMoveToLast(k0(), v0())); + assertNotEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(a, orderedMap.LAST_ENTRY_KEY()); + assertNotEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(v0(), orderedMap.putAndMoveToFirst(k0(), v0())); + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testPutBackAndForth() + { + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(v2(), orderedMap.putAndMoveToFirst(k2(), v2())); + assertNotEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(c, orderedMap.FIRST_ENTRY_KEY()); + assertNotEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(v2(), orderedMap.putAndMoveToLast(k2(), v2())); + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testGetForthAndBack() + { + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(v0(), orderedMap.getAndMoveToLast(k0())); + assertNotEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(a, orderedMap.LAST_ENTRY_KEY()); + assertNotEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(v0(), orderedMap.getAndMoveToFirst(k0())); + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(SEVERAL) +#endignore + public void testGetBackAndForth() + { + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(v2(), orderedMap.getAndMoveToFirst(k2())); + assertNotEquals(a, orderedMap.FIRST_ENTRY_KEY()); + assertEquals(c, orderedMap.FIRST_ENTRY_KEY()); + assertNotEquals(c, orderedMap.LAST_ENTRY_KEY()); + assertEquals(v2(), orderedMap.getAndMoveToLast(k2())); + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/OrderedMapNavigationTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/OrderedMapNavigationTester.template new file mode 100644 index 00000000..706dd937 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/OrderedMapNavigationTester.template @@ -0,0 +1,303 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; +#endignore + +import java.util.NoSuchElementException; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP; +import speiger.src.collections.objects.lists.ObjectList; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; +import speiger.src.testers.objects.utils.ObjectHelpers; + +@SuppressWarnings("javadoc") +@Ignore +public class FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ + private ORDERED_MAP KEY_VALUE_GENERIC_TYPE orderedMap; + private ObjectList values; + private KEY_TYPE a; + private VALUE_TYPE aValue; + private KEY_TYPE c; + private VALUE_TYPE cValue; + + @Override + public void setUp() throws Exception { + super.setUp(); + orderedMap = (ORDERED_MAP KEY_VALUE_GENERIC_TYPE) getMap(); + values = ObjectHelpers.copyToList(getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements())); + if (values.size() >= 1) { + a = values.get(0).ENTRY_KEY(); + aValue = values.get(0).ENTRY_VALUE(); + if (values.size() >= 3) { + c = values.get(2).ENTRY_KEY(); + cValue = values.get(2).ENTRY_VALUE(); + } + } + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(ZERO) +#endignore + public void testPutEmptyMapToFirst() { + orderedMap.putAndMoveToFirst(k0(), v0()); + expectAdded(e0()); + } + +#ignore + @MapFeature.Require(SUPPORTS_PUT) + @CollectionSize.Require(ZERO) +#endignore + public void testPutEmptyMapToLast() { + orderedMap.putAndMoveToLast(k0(), v0()); + expectAdded(e0()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testyMapPollFirstEmpty() { + int polled = 0; + int expectedPolls = orderedMap.size(); + while(polled < expectedPolls) { + orderedMap.POLL_FIRST_ENTRY_KEY(); + polled++; + } + assertTrue("Map should be empty", orderedMap.isEmpty()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testyMapPollLastEmpty() { + int polled = 0; + int expectedPolls = orderedMap.size(); + while(polled < expectedPolls) { + orderedMap.POLL_LAST_ENTRY_KEY(); + polled++; + } + assertTrue("Map should be empty", orderedMap.isEmpty()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapPollFirst() { + try { + orderedMap.POLL_FIRST_ENTRY_KEY(); + fail("OrderedMap.POLL_FIRST_ENTRY_KEY should throw NoSuchElementException"); + } catch (NoSuchElementException e) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapPollLast() { + try { + orderedMap.POLL_LAST_ENTRY_KEY(); + fail("OrderedMap.POLL_LAST_ENTRY_KEY should throw NoSuchElementException"); + } catch (NoSuchElementException e) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testUnsupportedMapPollFirst() { + try { + orderedMap.POLL_FIRST_ENTRY_KEY(); + fail("OrderedMap.POLL_FIRST_ENTRY_KEY should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testUnsupportedMapPollLast() { + try { + orderedMap.POLL_LAST_ENTRY_KEY(); + fail("OrderedMap.POLL_LAST_ENTRY_KEY should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapPollFirst() { + assertEquals(a, orderedMap.POLL_FIRST_ENTRY_KEY()); + assertTrue(orderedMap.isEmpty()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapPollLast() { + assertEquals(a, orderedMap.POLL_LAST_ENTRY_KEY()); + assertTrue(orderedMap.isEmpty()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testPollFirst() { + assertEquals(a, orderedMap.POLL_FIRST_ENTRY_KEY()); + assertEquals(values.subList(1, values.size()), ObjectHelpers.copyToList(orderedMap.ENTRY_SET())); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testPollLast() { + assertEquals(c, orderedMap.POLL_LAST_ENTRY_KEY()); + assertEquals(values.subList(0, values.size()-1), ObjectHelpers.copyToList(orderedMap.ENTRY_SET())); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testPollFirstUnsupported() { + try { + orderedMap.POLL_FIRST_ENTRY_KEY(); + fail(); + } catch (UnsupportedOperationException e) { + } + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testPollLastUnsupported() { + try { + orderedMap.POLL_LAST_ENTRY_KEY(); + fail(); + } catch (UnsupportedOperationException e) { + } + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapFirstKey() { + try { + orderedMap.FIRST_ENTRY_KEY(); + fail(); + } catch (NoSuchElementException e) { + } + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapFirstValue() { + try { + orderedMap.FIRST_ENTRY_VALUE(); + fail(); + } catch (NoSuchElementException e) { + } + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapLastKey() { + try { + orderedMap.LAST_ENTRY_KEY(); + fail(); + } catch (NoSuchElementException e) { + } + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapLastValue() { + try { + orderedMap.LAST_ENTRY_VALUE(); + fail(); + } catch (NoSuchElementException e) { + } + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapFirstKey() { + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapFirstValue() { + assertEquals(aValue, orderedMap.FIRST_ENTRY_VALUE()); + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapLastKey() { + assertEquals(a, orderedMap.LAST_ENTRY_KEY()); + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapLastValue() { + assertEquals(aValue, orderedMap.FIRST_ENTRY_VALUE()); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testFirstKey() { + assertEquals(a, orderedMap.FIRST_ENTRY_KEY()); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testFirstValue() { + assertEquals(aValue, orderedMap.FIRST_ENTRY_VALUE()); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testLastKey() { + assertEquals(c, orderedMap.LAST_ENTRY_KEY()); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testLastValue() { + assertEquals(cValue, orderedMap.LAST_ENTRY_VALUE()); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/maps/SortedMapNavigationTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/maps/SortedMapNavigationTester.template new file mode 100644 index 00000000..e27a129a --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/maps/SortedMapNavigationTester.template @@ -0,0 +1,328 @@ +package speiger.src.testers.PACKAGE.tests.maps; + +#ignore +import static com.google.common.collect.testing.Helpers.assertEqualInOrder; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; +#endignore + +import java.util.Comparator; +import java.util.Iterator; +import java.util.NoSuchElementException; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; + +#if !TYPE_OBJECT +import speiger.src.collections.PACKAGE.functions.COMPARATOR; +#endif +import speiger.src.collections.PACKAGE.maps.interfaces.MAP.Entry; +import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP; +import speiger.src.collections.objects.lists.ObjectList; +import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER; +import speiger.src.testers.objects.utils.ObjectHelpers; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPE2FILE_VALUE_TYPESortedMapNavigationTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE +{ + private SORTED_MAP KEY_VALUE_GENERIC_TYPE sortedMap; + private ObjectList entries; + private Entry KEY_VALUE_GENERIC_TYPE a; + private Entry KEY_VALUE_GENERIC_TYPE c; + + @Override + public void setUp() throws Exception { + super.setUp(); + sortedMap = (SORTED_MAP KEY_VALUE_GENERIC_TYPE) getMap(); + entries = ObjectHelpers.copyToList(getSampleElements(getNumElements())); + entries.sort(entryComparator(sortedMap.comparator())); + if (entries.size() >= 1) { + a = entries.get(0); + if (entries.size() >= 3) { + c = entries.get(2); + } + } + } + + public static GENERIC_KEY_VALUE_BRACES Comparator entryComparator(COMPARATOR KEY_GENERIC_TYPE keyComparator) { + return new Comparator() { + @Override + public int compare(Entry KEY_VALUE_GENERIC_TYPE a, Entry KEY_VALUE_GENERIC_TYPE b) { + return (keyComparator == null) ? COMPAREABLE_TO_KEY(a.ENTRY_KEY(), b.ENTRY_KEY()) : keyComparator.compare(a.ENTRY_KEY(), b.ENTRY_KEY()); + } + }; + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapPollFirst() { +#if TYPE_OBJECT + assertNull(sortedMap.POLL_FIRST_ENTRY_KEY()); +#else + assertEquals(CLASS_TYPE.MAX_VALUE, sortedMap.POLL_FIRST_ENTRY_KEY()); +#endif + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapPollLast() { +#if TYPE_OBJECT + assertNull(sortedMap.POLL_FIRST_ENTRY_KEY()); +#else + assertEquals(CLASS_TYPE.MIN_VALUE, sortedMap.POLL_LAST_ENTRY_KEY()); +#endif + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testUnsupportedMapPollFirst() { + try { + sortedMap.POLL_FIRST_ENTRY_KEY(); + fail("OrderedMap.POLL_FIRST_ENTRY_KEY should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testUnsupportedMapPollLast() { + try { + sortedMap.POLL_LAST_ENTRY_KEY(); + fail("OrderedMap.POLL_LAST_ENTRY_KEY should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapPollFirst() { + assertEquals(a.ENTRY_KEY(), sortedMap.POLL_FIRST_ENTRY_KEY()); + assertTrue(sortedMap.isEmpty()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapPollLast() { + assertEquals(a.ENTRY_KEY(), sortedMap.POLL_LAST_ENTRY_KEY()); + assertTrue(sortedMap.isEmpty()); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testPollFirst() { + assertEquals(a.ENTRY_KEY(), sortedMap.POLL_FIRST_ENTRY_KEY()); + assertEquals(entries.subList(1, entries.size()), ObjectHelpers.copyToList(sortedMap.ENTRY_SET())); + } + +#ignore + @MapFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testPollLast() { + assertEquals(c.ENTRY_KEY(), sortedMap.POLL_LAST_ENTRY_KEY()); + assertEquals(entries.subList(0, entries.size()-1), ObjectHelpers.copyToList(sortedMap.ENTRY_SET())); + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testPollFirstUnsupported() { + try { + sortedMap.POLL_FIRST_ENTRY_KEY(); + fail(); + } catch (UnsupportedOperationException e) { + } + } + +#ignore + @MapFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testPollLastUnsupported() { + try { + sortedMap.POLL_LAST_ENTRY_KEY(); + fail(); + } catch (UnsupportedOperationException e) { + } + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapFirst() { + try { + sortedMap.FIRST_ENTRY_KEY(); + fail(); + } catch (NoSuchElementException e) { + } + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapLast() { + try { + assertEquals(EMPTY_VALUE, sortedMap.LAST_ENTRY_KEY()); + fail(); + } catch (NoSuchElementException e) { + } + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapFirstValue() { + try { + sortedMap.FIRST_ENTRY_VALUE(); + fail(); + } catch (NoSuchElementException e) { + } + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptyMapLastValue() { + try { + sortedMap.LAST_ENTRY_VALUE(); + fail(); + } catch (NoSuchElementException e) { + } + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapFirstValue() { + assertEquals(a.ENTRY_VALUE(), sortedMap.FIRST_ENTRY_VALUE()); + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapLastValue() { + assertEquals(a.ENTRY_VALUE(), sortedMap.FIRST_ENTRY_VALUE()); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testFirstValue() { + assertEquals(a.ENTRY_VALUE(), sortedMap.FIRST_ENTRY_VALUE()); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testLastValue() { + assertEquals(c.ENTRY_VALUE(), sortedMap.LAST_ENTRY_VALUE()); + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapFirst() { + assertEquals(a.ENTRY_KEY(), sortedMap.FIRST_ENTRY_KEY()); + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonMapLast() { + assertEquals(a.ENTRY_KEY(), sortedMap.LAST_ENTRY_KEY()); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testFirst() { + assertEquals(a.ENTRY_KEY(), sortedMap.FIRST_ENTRY_KEY()); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testLast() { + assertEquals(c.ENTRY_KEY(), sortedMap.LAST_ENTRY_KEY()); + } + +#ignore + @CollectionSize.Require(absent = ZERO) +#endignore + public void testHeadMapExclusive() { + assertFalse(sortedMap.headMap(a.ENTRY_KEY()).containsKey(a.ENTRY_KEY())); + } + +#ignore + @CollectionSize.Require(absent = ZERO) +#endignore + public void testTailMapInclusive() { + assertTrue(sortedMap.tailMap(a.ENTRY_KEY()).containsKey(a.ENTRY_KEY())); + } + +#ignore + @CollectionSize.Require(absent = SEVERAL) +#endignore + public void testSubMap() { + ObjectList entries = ObjectHelpers.copyToList(getSampleElements(getNumElements())); + entries.sort(entryComparator(sortedMap.comparator())); + for (int i = 0; i < entries.size(); i++) { + for (int j = i + 1; j < entries.size(); j++) { + assertEqualInOrder(entries.subList(i, j), sortedMap.subMap(entries.get(i).ENTRY_KEY(), entries.get(j).ENTRY_KEY()).ENTRY_SET()); + } + } + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testSubMapIllegal() { + try { + sortedMap.subMap(c.ENTRY_KEY(), a.ENTRY_KEY()); + fail("Expected IllegalArgumentException"); + } catch (IllegalArgumentException expected) { + } + } + +#ignore + @CollectionSize.Require(absent = ZERO) +#endignore + public void testOrderedByComparator() { + @SuppressWarnings("unchecked") + COMPARATOR KEY_GENERIC_TYPE comparator = sortedMap.comparator(); + if (comparator == null) { +#if TYPE_OBJECT + comparator = (Comparator)Comparator.naturalOrder(); +#else + comparator = CLASS_TYPE::compare; +#endif + } + Iterator entryItr = sortedMap.ENTRY_SET().iterator(); + Entry KEY_VALUE_GENERIC_TYPE prevEntry = entryItr.next(); + while (entryItr.hasNext()) { + Entry KEY_VALUE_GENERIC_TYPE nextEntry = entryItr.next(); + assertTrue(comparator.compare(prevEntry.ENTRY_KEY(), nextEntry.ENTRY_KEY()) < 0); + prevEntry = nextEntry; + } + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/misc/PairTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/misc/PairTester.template new file mode 100644 index 00000000..d9575c33 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/misc/PairTester.template @@ -0,0 +1,261 @@ +package speiger.src.testers.PACKAGE.tests.misc; + +#if TYPE_OBJECT || VALUE_OBJECT +import java.util.Objects; +#endif + +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Supplier; + +import org.junit.Test; + +import junit.framework.TestCase; +import speiger.src.collections.VALUE_PACKAGE.functions.function.FILE_VALUE_TYPE2ObjectFunction; +#if !SAME_TYPE +import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION; +#endif +import speiger.src.collections.PACKAGE.misc.pairs.PAIR; + +@SuppressWarnings("javadoc") +public class PAIRTester KEY_VALUE_GENERIC_TYPE extends TestCase +{ + Supplier simple; + Function copier; + BiFunction constructor; + TO_OBJECT_FUNCTION KKS_GENERIC_TYPE keyConstructor; + FILE_VALUE_TYPE2ObjectFunction VVS_GENERIC_TYPE valueConstructor; + boolean mutable; + + protected PAIRTester(boolean mutable) { + this.mutable = mutable; + } + + protected void setSimple(Supplier simple) { + this.simple = simple; + } + + protected void setCopier(Function copier) { + this.copier = copier; + } + + protected void setConstructor(BiFunction constructor) { + this.constructor = constructor; + } + + protected void setKeyConstructor(TO_OBJECT_FUNCTION KKS_GENERIC_TYPE keyConstructor) { + this.keyConstructor = keyConstructor; + } + + protected void setValueConstructor(FILE_VALUE_TYPE2ObjectFunction VVS_GENERIC_TYPE valueConstructor) { + this.valueConstructor = valueConstructor; + } + +#if TYPE_BOOLEAN + protected KEY_TYPE getKey() { + return true; + } + +#else + protected KEY_TYPE getKey() { + return INVALID_KEY_VALUE; + } + +#endif +#if VALUE_BOOLEAN + protected VALUE_TYPE getValue() { + return true; + } + +#else + protected VALUE_TYPE getValue() { + return INVALID_VALUE; + } + +#endif + protected KEY_TYPE[] getKeyArray() { + KEY_TYPE[] keys = NEW_KEY_ARRAY(1); + keys[0] = getKey(); + return keys; + } + + protected VALUE_TYPE[] getValueArray() { + VALUE_TYPE[] values = NEW_VALUE_ARRAY(1); + values[0] = getValue(); + return values; + } + + @Test + public void testCopyConstructor() { + PAIR KEY_VALUE_GENERIC_TYPE base = PAIR.of(); + PAIR KEY_VALUE_GENERIC_TYPE result = copier.apply(base); + assertTrue(base != result); + } + + @Test + public void testKeyMatching() { +#if TYPE_OBJECT + PAIR KEY_VALUE_GENERIC_TYPE pair = keyConstructor.getObject(getKey()); +#else + PAIR KEY_VALUE_GENERIC_TYPE pair = keyConstructor.GET_VALUE(getKey()); +#endif + assertEquals(getKey(), pair.ENTRY_KEY()); + assertEquals(EMPTY_VALUE, pair.ENTRY_VALUE()); + } + + @Test + public void testValueMatching() { +#if VALUE_OBJECT + PAIR KEY_VALUE_GENERIC_TYPE pair = valueConstructor.getObject(getValue()); +#else + PAIR KEY_VALUE_GENERIC_TYPE pair = valueConstructor.get(getValue()); +#endif + assertEquals(EMPTY_KEY_VALUE, pair.ENTRY_KEY()); + assertEquals(getValue(), pair.ENTRY_VALUE()); + } + + @Test + public void testEntryMatching() { + PAIR KEY_VALUE_GENERIC_TYPE pair = constructor.apply(getKeyArray(), getValueArray()); + assertEquals(getKey(), pair.ENTRY_KEY()); + assertEquals(getValue(), pair.ENTRY_VALUE()); + } + + @Test + public void testCopying() { + PAIR KEY_VALUE_GENERIC_TYPE pair = simple.get(); + PAIR KEY_VALUE_GENERIC_TYPE copy = pair.shallowCopy(); + if(mutable) { + assertTrue(pair != copy); + assertEquals(pair.ENTRY_KEY(), copy.ENTRY_KEY()); + assertEquals(pair.ENTRY_VALUE(), copy.ENTRY_VALUE()); + } + else { + assertTrue(pair == copy); + assertEquals(pair.ENTRY_KEY(), copy.ENTRY_KEY()); + assertEquals(pair.ENTRY_VALUE(), copy.ENTRY_VALUE()); + } + assertTrue(pair.equals(copy)); + assertFalse(pair.equals(null)); + assertFalse(pair.equals(PAIR.of(getKey(), getValue()))); + assertEquals(KEY_TO_STRING(pair.ENTRY_KEY())+"->"+VALUE_TO_STRING(pair.ENTRY_VALUE()), pair.toString()); + assertEquals(KEY_TO_HASH(pair.ENTRY_KEY()) ^ VALUE_TO_HASH(pair.ENTRY_VALUE()), pair.hashCode()); + } + + @Test + public void testSetKey() { + PAIR KEY_VALUE_GENERIC_TYPE pair = simple.get(); + if(mutable) { + PAIR KEY_VALUE_GENERIC_TYPE changed = pair.KEY_ENTRY(getKey()); + assertTrue(pair == changed); + assertEquals(pair.ENTRY_KEY(), changed.ENTRY_KEY()); + } + else { + PAIR KEY_VALUE_GENERIC_TYPE changed = pair.KEY_ENTRY(getKey()); + assertTrue(pair != changed); + assertTrue(KEY_EQUALS_NOT(pair.ENTRY_KEY(), changed.ENTRY_KEY())); + } + } + + @Test + public void testSetValue() { + PAIR KEY_VALUE_GENERIC_TYPE pair = simple.get(); + if(mutable) { + PAIR KEY_VALUE_GENERIC_TYPE changed = pair.VALUE_ENTRY(getValue()); + assertTrue(pair == changed); + assertEquals(pair.ENTRY_VALUE(), changed.ENTRY_VALUE()); + } + else { + PAIR KEY_VALUE_GENERIC_TYPE changed = pair.VALUE_ENTRY(getValue()); + assertTrue(pair != changed); + assertTrue(VALUE_EQUALS_NOT(pair.ENTRY_VALUE(), changed.ENTRY_VALUE())); + } + } + + @Test + public void testSetEntry() { + PAIR KEY_VALUE_GENERIC_TYPE pair = simple.get(); + if(mutable) { + PAIR KEY_VALUE_GENERIC_TYPE changed = pair.set(getKey(), getValue()); + assertTrue(pair == changed); + assertEquals(pair.ENTRY_VALUE(), changed.ENTRY_VALUE()); + assertEquals(pair.ENTRY_KEY(), changed.ENTRY_KEY()); + } + else { + PAIR KEY_VALUE_GENERIC_TYPE changed = pair.set(getKey(), getValue()); + assertTrue(pair != changed); + assertTrue(VALUE_EQUALS_NOT(pair.ENTRY_VALUE(), changed.ENTRY_VALUE())); + assertTrue(KEY_EQUALS_NOT(pair.ENTRY_KEY(), changed.ENTRY_KEY())); + } + } + + public static class Mutable extends PAIRTester KEY_VALUE_STRING_GENERIC_TYPE + { + public Mutable() { + super(true); + setSimple(PAIR::mutable); + setCopier(PAIR::mutable); + setConstructor((K, V) -> PAIR.mutable(K[0], V[0])); + setKeyConstructor(PAIR::mutableKey); + setValueConstructor(PAIR::mutableValue); + } + +#if TYPE_OBJECT + @Override + public String getKey() { + return "key"; + } + + @Override + public String[] getKeyArray() { + return new String[]{"key"}; + } +#endif +#if VALUE_OBJECT + @Override + public String getValue() { + return "value"; + } + + @Override + public String[] getValueArray() { + return new String[]{"value"}; + } +#endif + } + + public static class Immutable extends PAIRTester KEY_VALUE_STRING_GENERIC_TYPE + { + public Immutable() { + super(false); + setSimple(PAIR::of); + setCopier(PAIR::of); + setConstructor((K, V) -> PAIR.of(K[0], V[0])); + setKeyConstructor(PAIR::ofKey); + setValueConstructor(PAIR::ofValue); + } + +#if TYPE_OBJECT + @Override + public String getKey() { + return "key"; + } + + @Override + public String[] getKeyArray() { + return new String[]{"key"}; + } +#endif +#if VALUE_OBJECT + @Override + public String getValue() { + return "value"; + } + + @Override + public String[] getValueArray() { + return new String[]{"value"}; + } +#endif + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/DequeueDequeueTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/DequeueDequeueTester.template new file mode 100644 index 00000000..200acc2c --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/DequeueDequeueTester.template @@ -0,0 +1,62 @@ +package speiger.src.testers.PACKAGE.tests.queue; + +import java.util.NoSuchElementException; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEDequeueDequeueTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ + protected PRIORITY_DEQUEUE KEY_GENERIC_TYPE getDequeue() { + return (PRIORITY_DEQUEUE KEY_GENERIC_TYPE)queue; + } + +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_REMOVE) + @CollectionSize.Require(CollectionSize.ZERO) +#endignore + public void testDequeueFirst_Empty() { + try { + getDequeue().dequeueLast(); + fail("Queue.dequeue should throw a NoSuchElementException"); + } + catch(NoSuchElementException e) { } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.SUPPORTS_REMOVE) +#endignore + public void testDequeueFirst_Unsupported() { + try { + getDequeue().dequeueLast(); + fail("Queue.dequeue should throw a UnsupportedOperationException"); + } + catch(UnsupportedOperationException e) { } + } + +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_REMOVE) + @CollectionSize.Require(CollectionSize.ONE) +#endignore + public void testDequeueFirst() { + assertEquals("Queue.dequeue should match", e0(), getDequeue().dequeueLast()); + expectMissing(e0()); + } + +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_REMOVE) + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testDequeueFirstSeveral() { + assertEquals("Queue.dequeue should match", e2(), getDequeue().dequeueLast()); + expectMissing(e2()); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/DequeueEnqueueTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/DequeueEnqueueTester.template new file mode 100644 index 00000000..8b658c8a --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/DequeueEnqueueTester.template @@ -0,0 +1,73 @@ +package speiger.src.testers.PACKAGE.tests.queue; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionFeature; + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEDequeueEnqueueTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ + protected PRIORITY_DEQUEUE KEY_GENERIC_TYPE getDequeue() { + return (PRIORITY_DEQUEUE KEY_GENERIC_TYPE)queue; + } + +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_ADD) +#endignore + public void testEnqueue() { + int initSize = queue.size(); + getDequeue().enqueueFirst(e3()); + assertEquals(initSize+1, queue.size()); + expectAdded(e3()); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.SUPPORTS_ADD) +#endignore + public void testEnqueue_Unsupported() { + try { + getDequeue().enqueueFirst(e3()); + fail("Queue should throw a UnsupportedOperationException"); + } + catch(UnsupportedOperationException e) { + } + } + +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_ADD) +#endignore + public void testEnqueue_allArray() { + int initSize = queue.size(); + KEY_TYPE[] array = createDisjointArray(); + getDequeue().enqueueAllFirst(array); + assertEquals(initSize+array.length, queue.size()); + expectAdded(array); + } + +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_ADD) +#endignore + public void testEnqueue_allArrayPartial() { + int initSize = queue.size(); + KEY_TYPE[] array = createDisjointArray(); + getDequeue().enqueueAllFirst(array, 1); + assertEquals(initSize+1, queue.size()); + expectAdded(array[0]); + } + +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_ADD) +#endignore + public void testEnqueue_all() { + int initSize = queue.size(); + COLLECTION KEY_GENERIC_TYPE collection = createDisjointCollection(); + getDequeue().enqueueAllFirst(collection); + assertEquals(initSize+collection.size(), queue.size()); + expectAdded(collection.TO_ARRAY(NEW_KEY_ARRAY(collection.size()))); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/DequeueLastTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/DequeueLastTester.template new file mode 100644 index 00000000..b3c8e525 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/DequeueLastTester.template @@ -0,0 +1,48 @@ +package speiger.src.testers.PACKAGE.tests.queue; + +import java.util.NoSuchElementException; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.queues.PRIORITY_DEQUEUE; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEDequeueLastTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ + protected PRIORITY_DEQUEUE KEY_GENERIC_TYPE getDequeue() { + return (PRIORITY_DEQUEUE KEY_GENERIC_TYPE)queue; + } + +#ignore + @CollectionSize.Require(CollectionSize.ZERO) +#endignore + public void testQueueTopEmpty() { + try { + getDequeue().last(); + fail("Queue Should throw a NoSuchElementException"); + } + catch(NoSuchElementException e) {} + } + +#ignore + @CollectionSize.Require(CollectionSize.ONE) +#endignore + public void testQueueTopOne() { + assertEquals("PriorityQueue.first should be equal", e0(), getDequeue().last()); + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(CollectionFeature.KNOWN_ORDER) + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testQueueTopSeveral() { + assertEquals("PriorityQueue.first should be equal", e2(), getDequeue().last()); + expectUnchanged(); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueDequeueTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueDequeueTester.template new file mode 100644 index 00000000..3fcb07ac --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueDequeueTester.template @@ -0,0 +1,48 @@ +package speiger.src.testers.PACKAGE.tests.queue; + +import java.util.NoSuchElementException; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEQueueDequeueTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_REMOVE) + @CollectionSize.Require(CollectionSize.ZERO) +#endignore + public void testDequeueFirst_Empty() { + try { + queue.dequeue(); + fail("Queue.dequeue should throw a NoSuchElementException"); + } + catch(NoSuchElementException e) { } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.SUPPORTS_REMOVE) +#endignore + public void testDequeueFirst_Unsupported() { + try { + queue.dequeue(); + fail("Queue.dequeue should throw a UnsupportedOperationException"); + } + catch(UnsupportedOperationException e) { } + } + +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_REMOVE) + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testDequeueFirst() { + assertEquals("Queue.dequeue should match", e0(), queue.dequeue()); + expectMissing(e0()); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueEnqueueTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueEnqueueTester.template new file mode 100644 index 00000000..52a7f20d --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueEnqueueTester.template @@ -0,0 +1,68 @@ +package speiger.src.testers.PACKAGE.tests.queue; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionFeature; + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEQueueEnqueueTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_ADD) +#endignore + public void testEnqueue() { + int initSize = queue.size(); + queue.enqueue(e3()); + assertEquals(initSize+1, queue.size()); + expectAdded(e3()); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.SUPPORTS_ADD) +#endignore + public void testEnqueue_Unsupported() { + try { + queue.enqueue(e3()); + fail("Queue should throw a UnsupportedOperationException"); + } + catch(UnsupportedOperationException e) { + } + } + +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_ADD) +#endignore + public void testEnqueue_allArray() { + int initSize = queue.size(); + KEY_TYPE[] array = createDisjointArray(); + queue.enqueueAll(array); + assertEquals(initSize+array.length, queue.size()); + expectAdded(array); + } + +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_ADD) +#endignore + public void testEnqueue_allArrayPartial() { + int initSize = queue.size(); + KEY_TYPE[] array = createDisjointArray(); + queue.enqueueAll(array, 1); + assertEquals(initSize+1, queue.size()); + expectAdded(array[0]); + } + +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_ADD) +#endignore + public void testEnqueue_all() { + int initSize = queue.size(); + COLLECTION KEY_GENERIC_TYPE collection = createDisjointCollection(); + queue.enqueueAll(collection); + assertEquals(initSize+collection.size(), queue.size()); + expectAdded(collection.TO_ARRAY(NEW_KEY_ARRAY(collection.size()))); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueFirstTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueFirstTester.template new file mode 100644 index 00000000..d18a1242 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueFirstTester.template @@ -0,0 +1,43 @@ +package speiger.src.testers.PACKAGE.tests.queue; + +import java.util.NoSuchElementException; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEQueueFirstTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionSize.Require(CollectionSize.ZERO) +#endignore + public void testQueueTopEmpty() { + try { + queue.first(); + fail("Queue Should throw a NoSuchElementException"); + } + catch(NoSuchElementException e) {} + } + +#ignore + @CollectionSize.Require(CollectionSize.ONE) +#endignore + public void testQueueTopOne() { + assertEquals("PriorityQueue.first should be equal", e0(), queue.first()); + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(CollectionFeature.KNOWN_ORDER) + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testQueueTopSeveral() { + assertEquals("PriorityQueue.first should be equal", e0(), queue.first()); + expectUnchanged(); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueRemoveTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueRemoveTester.template new file mode 100644 index 00000000..a2d02e16 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/QueueRemoveTester.template @@ -0,0 +1,71 @@ +package speiger.src.testers.PACKAGE.tests.queue; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEQueueRemoveTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_REMOVE) +#endignore + public void testRemoveFirst_Missing() { + assertFalse("Queue.removeFirst(missing) should return false", queue.removeFirst(e3())); + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_REMOVE) + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testRemoveFirst_Present() { + assertTrue("Queue.removeFirst(present) should return true", queue.removeFirst(e0())); + expectMissing(e0()); + } + +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_REMOVE) +#endignore + public void testRemoveLast_Missing() { + assertFalse("Queue.removeLast(missing) should return false", queue.removeLast(e3())); + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(CollectionFeature.SUPPORTS_REMOVE) + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testRemoveLast_Present() { + assertTrue("Queue.removeLast(present) should return true", queue.removeLast(e0())); + expectMissing(e0()); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.SUPPORTS_REMOVE) +#endignore + public void testRemoveFirst_Unsupported() { + try { + queue.removeFirst(e3()); + fail("Queue.removeFirst should throw UnsupportedOperationException"); + } + catch(UnsupportedOperationException e) {} + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.SUPPORTS_REMOVE) +#endignore + public void testRemoveLast_Unsupported() { + try { + queue.removeLast(e3()); + fail("Queue.removeLast should throw UnsupportedOperationException"); + } + catch(UnsupportedOperationException e) {} + expectUnchanged(); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueCountTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueCountTester.template new file mode 100644 index 00000000..c6e096fc --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueCountTester.template @@ -0,0 +1,47 @@ +package speiger.src.testers.PACKAGE.tests.queue.iterators; + +#if TYPE_OBJECT +import java.util.Objects; + +#endif +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEQueueCountTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ + public void testQueueCount_null() { + try { + queue.count(null); + fail("This should throw a NullPointerException"); + } catch (NullPointerException e) { + } + } + + public void testQueueCount_NoneFound() { + assertEquals("Expected none to be found", 0, queue.count(T -> false)); + } + + public void testQueueCount_AllFound() { + assertEquals("Expected All to be found", getNumElements(), queue.count(T -> true)); + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testQueueCount_FindFirst() + { + assertEquals("First element should be found", 1, queue.count(T -> KEY_EQUALS(T, e0()))); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testQueueCount_FindLast() { + assertEquals("Last element should be found", 1, queue.count(T -> KEY_EQUALS(T, e2()))); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueDistinctTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueDistinctTester.template new file mode 100644 index 00000000..46187e06 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueDistinctTester.template @@ -0,0 +1,24 @@ +package speiger.src.testers.PACKAGE.tests.queue.iterators; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEQueueDistinctTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testDistinct() + { + ArrayWithDuplicate KEY_GENERIC_TYPE duplicate = createArrayWithDuplicateElement(); + resetContainer(queueGenerator.create(duplicate.elements)); + LIST KEY_GENERIC_TYPE list = queue.distinct().pourAsList(); + assertEquals("Distinct should remove duplicate elements", list.indexOf(duplicate.duplicate), list.lastIndexOf(duplicate.duplicate)); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueFilterTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueFilterTester.template new file mode 100644 index 00000000..94f5b5e5 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueFilterTester.template @@ -0,0 +1,52 @@ +package speiger.src.testers.PACKAGE.tests.queue.iterators; + +#if TYPE_OBJECT +import java.util.Objects; + +#endif +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.utils.SETS; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEQueueFilterTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ + public void testQueueFilter_missingElement() { + assertTrue(expectMissing(queue.filter(T -> KEY_EQUALS_NOT(T, e0())).pourAsList(), e0())); + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testQueueFilter_filterElement() { + assertFalse(expectMissing(SETS.singleton(e0()), queue.filter(T -> KEY_EQUALS(T, e0())).pourAsList().TO_ARRAY())); + } + +#ignore + @CollectionSize.Require(CollectionSize.ONE) +#endignore + public void testQueueFilter_filterMissing() { + assertTrue(queue.filter(T -> KEY_EQUALS(T, e1())).pourAsList().isEmpty()); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testQueueFilter_filterSeveral() { + assertTrue(expectMissing(SETS.singleton(e1()), queue.filter(T -> KEY_EQUALS_NOT(T, e1())).pourAsList().TO_ARRAY())); + } + + protected boolean expectMissing(COLLECTION KEY_GENERIC_TYPE result, KEY_OBJECT_TYPE...elements) + { + for(KEY_OBJECT_TYPE element : elements) + { + if(result.contains(element)) return false; + } + return true; + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueFindFirstTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueFindFirstTester.template new file mode 100644 index 00000000..d20b1b75 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueFindFirstTester.template @@ -0,0 +1,43 @@ +package speiger.src.testers.PACKAGE.tests.queue.iterators; + +#if TYPE_OBJECT +import java.util.Objects; + +#endif +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEQueueFindFirstTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ + public void testQueueFindFirst_null() { + try { + queue.findFirst(null); + fail("This should throw a NullPointerException"); + } + catch (NullPointerException e) { + } + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testQueueFindFirst_FindFirstElements() { + assertEquals("First Element should be found", e0(), queue.findFirst(T -> KEY_EQUALS(T, e0()))); + } + + public void testQueueFindFirst_FindNothing() { + assertEquals("No element should be found", EMPTY_KEY_VALUE, queue.findFirst(T -> KEY_EQUALS(T, e4()))); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testQueueFindFirst_FindLastElement() { + assertEquals("Last Element should be found", e2(), queue.findFirst(T -> KEY_EQUALS(T, e2()))); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueForEachTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueForEachTester.template new file mode 100644 index 00000000..d1ad591d --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueForEachTester.template @@ -0,0 +1,19 @@ +package speiger.src.testers.PACKAGE.tests.queue.iterators; + +import org.junit.Ignore; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEQueueForEachTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ + public void testQueueForEach() { + LIST KEY_GENERIC_TYPE peeked = new ARRAY_LISTBRACES(); + LIST KEY_GENERIC_TYPE result = new ARRAY_LISTBRACES(); + queue.peek(peeked::add).forEach(result, LIST::add); + assertEquals("Collections should match since peek is just a preview of foreach", result, peeked); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueLimitTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueLimitTester.template new file mode 100644 index 00000000..138122bf --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueLimitTester.template @@ -0,0 +1,25 @@ +package speiger.src.testers.PACKAGE.tests.queue.iterators; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEQueueLimitTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testQueueLimit() { + LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(queue.TO_ARRAY()); + list.REMOVE(list.size()-1); + LIST KEY_GENERIC_TYPE result = queue.limit(getNumElements()-1).pourAsList(); + assertEquals(list.size(), result.size()); + assertEquals("Limit does not retain the iteration order", list, result); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueMapTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueMapTester.template new file mode 100644 index 00000000..e7eeb374 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueMapTester.template @@ -0,0 +1,182 @@ +package speiger.src.testers.PACKAGE.tests.queue.iterators; + +#if TYPE_OBJECT || TYPE_BOOLEAN +import java.util.Objects; +#endif + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionFeature; + +#if TYPE_OBJECT || TYPE_BOOLEAN +import speiger.src.collections.chars.utils.CharArrays; +#endif +import speiger.src.collections.objects.lists.ObjectArrayList; +import speiger.src.collections.objects.lists.ObjectList; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; +#if !TYPE_OBJECT +import speiger.src.testers.objects.utils.ObjectHelpers; +#endif + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEQueueMapTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ + public void testQueueMap_ToString() { + assertEquals(HELPERS.copyToList(queue.TO_ARRAY()).toString(), queue.map(CLASS_OBJECT_TYPE::toString).pourAsList().toString()); + } +#if TYPE_BOOLEAN + +#ignore + @CollectionFeature.Require(CollectionFeature.KNOWN_ORDER) +#endignore + public void testQueueMap_Collection() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange(entry)); + } + assertEquals(result, queue.flatMap(T -> ObjectArrayList.wrap(toRange(T))).pourAsList()); + } + +#ignore + @CollectionFeature.Require(CollectionFeature.KNOWN_ORDER) +#endignore + public void testQueueMap_Array() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange(entry)); + } + assertEquals(result, queue.arrayflatMap(this::toRange).pourAsList()); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.KNOWN_ORDER) +#endignore + public void testQueueMap_CollectionUnordered() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange(entry)); + } + ObjectHelpers.assertEqualIgnoringOrder(result, queue.flatMap(T -> ObjectArrayList.wrap(toRange(T))).pourAsList()); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.KNOWN_ORDER) +#endignore + public void testQueueMap_ArrayUnordered() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange(entry)); + } + ObjectHelpers.assertEqualIgnoringOrder(result, queue.arrayflatMap(this::toRange).pourAsList()); + } + + private Character[] toRange(boolean value) { + return CharArrays.wrap(Objects.toString(value).toCharArray()); + + } +#else if !TYPE_OBJECT + +#ignore + @CollectionFeature.Require(CollectionFeature.KNOWN_ORDER) +#endignore + public void testQueueMap_Collection() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange((int)entry)); + } + assertEquals(result, queue.flatMap(T -> ObjectArrayList.wrap(toRange((int)T))).pourAsList()); + } + +#ignore + @CollectionFeature.Require(CollectionFeature.KNOWN_ORDER) +#endignore + public void testQueueMap_Array() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange((int)entry)); + } + assertEquals(result, queue.arrayflatMap(T -> toRange((int)T)).pourAsList()); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.KNOWN_ORDER) +#endignore + public void testQueueMap_CollectionUnordered() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange((int)entry)); + } + ObjectHelpers.assertEqualIgnoringOrder(result, queue.flatMap(T -> ObjectArrayList.wrap(toRange((int)T))).pourAsList()); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.KNOWN_ORDER) +#endignore + public void testQueueMap_ArrayUnordered() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange((int)entry)); + } + ObjectHelpers.assertEqualIgnoringOrder(result, queue.arrayflatMap(T -> toRange((int)T)).pourAsList()); + } + + private Integer[] toRange(int range) { + Integer[] result = new Integer[range]; + for(int i = 0;i result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange(entry)); + } + assertEquals(result, queue.flatMap(T -> ObjectArrayList.wrap(toRange(T))).pourAsList()); + } + +#ignore + @CollectionFeature.Require(CollectionFeature.KNOWN_ORDER) +#endignore + public void testQueueMap_Array() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange(entry)); + } + assertEquals(result, queue.arrayflatMap(this::toRange).pourAsList()); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.KNOWN_ORDER) +#endignore + public void testQueueMap_CollectionUnordered() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange(entry)); + } + ObjectHelpers.assertEqualIgnoringOrder(result, queue.flatMap(T -> ObjectArrayList.wrap(toRange(T))).pourAsList()); + } + +#ignore + @CollectionFeature.Require(absent = CollectionFeature.KNOWN_ORDER) +#endignore + public void testQueueMap_ArrayUnordered() { + ObjectList result = new ObjectArrayList<>(); + for(KEY_TYPE entry : getOrderedElements()) { + result.addAll(toRange(entry)); + } + ObjectHelpers.assertEqualIgnoringOrder(result, queue.arrayflatMap(this::toRange).pourAsList()); + } + + private Character[] toRange(T obj) { + return CharArrays.wrap(Objects.toString(obj).toCharArray()); + } +#endif +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueMatchesTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueMatchesTester.template new file mode 100644 index 00000000..2e8454cc --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueMatchesTester.template @@ -0,0 +1,107 @@ +package speiger.src.testers.PACKAGE.tests.queue.iterators; + +#if TYPE_OBJECT +import java.util.Objects; + +#endif +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEQueueMatchesTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ + public void testQueueMatch_AnyNull() { + try { + queue.matchesAny(null); + fail("MatchesAny should throw a NullPointException"); + } + catch (NullPointerException e) { + } + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testQueueMatch_AnyFoundFirstElement() { + assertTrue("Element ["+e0()+"] should be found", queue.matchesAny(T -> KEY_EQUALS(T, e0()))); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testQueueMatch_AnyFoundLastElement() { + assertTrue("Element ["+e2()+"] should be found", queue.matchesAny(T -> KEY_EQUALS(T, e2()))); + } + + public void testQueueMatch_AnyFoundNoElement() { + assertFalse("Element ["+e4()+"] should not be found", queue.matchesAny(T -> KEY_EQUALS(T, e4()))); + } + + public void testQueueMatch_NoneNull() { + try { + queue.matchesNone(null); + fail("MatchesNone should throw a NullPointException"); + } + catch (NullPointerException e) { + } + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testQueueMatch_NoneFoundFirstElement() { + assertFalse("Element ["+e0()+"] should not be found", queue.matchesNone(T -> KEY_EQUALS(T, e0()))); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testQueueMatch_NoneFoundLastElement() { + assertFalse("Element ["+e2()+"] should not be found", queue.matchesNone(T -> KEY_EQUALS(T, e2()))); + } + + public void testQueueMatch_NoneFoundNoElement() { + assertTrue("Element ["+e4()+"] should not be found", queue.matchesNone(T -> KEY_EQUALS(T, e4()))); + } + + public void testQueueMatch_AllNull() { + try { + queue.matchesAll(null); + fail("MatchesAny should throw a NullPointException"); + } + catch (NullPointerException e) { + } + } + + public void testQueueMatch_AllFoundAllElements() { + COLLECTION KEY_GENERIC_TYPE lists = new ARRAY_LISTBRACES(queue.TO_ARRAY()); + assertTrue("All elements should be found", queue.matchesAll(lists::contains)); + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testQueueMatch_AllFoundNone() { + assertFalse("It should not find anything", queue.matchesAll(T -> false)); + } + +#ignore + @CollectionSize.Require(CollectionSize.ZERO) +#endignore + public void testQueueMatch_AllFoundNoneEmpty() { + assertTrue("Empty Collections should return true even if all have to be found", queue.matchesAll(T -> false)); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testQueueMatches_AllPartical() { + assertFalse("Even if some elements were found, it should return false", queue.matchesAll(T -> KEY_EQUALS(T, e0()))); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueuePeekTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueuePeekTester.template new file mode 100644 index 00000000..000a3092 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueuePeekTester.template @@ -0,0 +1,19 @@ +package speiger.src.testers.PACKAGE.tests.queue.iterators; + +import org.junit.Ignore; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEQueuePeekTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ + public void testQueuePeek() { + LIST KEY_GENERIC_TYPE peeked = new ARRAY_LISTBRACES(); + LIST KEY_GENERIC_TYPE result = new ARRAY_LISTBRACES(); + queue.peek(peeked::add).forEach(result::add); + assertEquals("Collections should match since peek is just a preview of foreach", result, peeked); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueReduceTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueReduceTester.template new file mode 100644 index 00000000..590140e9 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueReduceTester.template @@ -0,0 +1,80 @@ +package speiger.src.testers.PACKAGE.tests.queue.iterators; + +#if TYPE_OBJECT +import java.util.Objects; + +#endif +import org.junit.Ignore; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEQueueReduceTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ + public void testQueueReduce_Null() { + try { + queue.reduce(null); + fail("This should crash"); + } catch (NullPointerException e) { + } + } + + public void testQueueReduce_extraNull() { + try { + queue.reduce(EMPTY_KEY_VALUE, null); + fail("This should crash"); + } catch (NullPointerException e) { + } + } + + public void testQueueReduce() { + assertEquals("The sum of the queue should match", getSum(), queue.reduce(this::sum)); + } + + public void testQueueExtraReduce() { +#if TYPE_OBJECT + assertEquals("The sum of the queue should match", getObjectSum(), queue.reduce(new StringBuilder(), this::sum).toString()); +#else + assertEquals("The sum of the queue should match", getSum(), queue.reduce(EMPTY_KEY_VALUE, this::sum)); +#endif + } + + public KEY_TYPE getSum() + { + KEY_TYPE result = EMPTY_KEY_VALUE; + for(KEY_TYPE key : queue.TO_ARRAY(NEW_KEY_ARRAY(queue.size()))) + { + result = sum(result, key); + } + return result; + } + + public KEY_TYPE sum(KEY_TYPE key, KEY_TYPE value) + { +#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR + return (KEY_TYPE)(key + value); +#else if TYPE_OBJECT + return value; +#else if TYPE_BOOLEAN + return key ^ value; +#else + return key + value; +#endif + } + +#if TYPE_OBJECT + public StringBuilder sum(StringBuilder builder, T value) { + return builder.append(Objects.toString(value)); + } + + public String getObjectSum() { + StringBuilder builder = new StringBuilder(); + for(T key : queue.TO_ARRAY(NEW_KEY_ARRAY(queue.size()))) + { + builder = sum(builder, key); + } + return builder.toString(); + } +#endif +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueSortedTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueSortedTester.template new file mode 100644 index 00000000..0c923f47 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/queue/iterators/QueueSortedTester.template @@ -0,0 +1,43 @@ +package speiger.src.testers.PACKAGE.tests.queue.iterators; + +import org.junit.Ignore; + +#if TYPE_OBJECT +import java.util.Comparator; +import java.util.Map; +#endif + +import com.google.common.collect.testing.features.CollectionFeature; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; +import speiger.src.testers.utils.SpecialFeature; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEQueueSortedTester KEY_GENERIC_TYPE extends ABSTRACT_QUEUE_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(absent = CollectionFeature.KNOWN_ORDER) + @SpecialFeature.Require(absent = SpecialFeature.MAP_ENTRY) +#endignore + public void testQueueSorted() { + LIST KEY_GENERIC_TYPE expected = new ARRAY_LISTBRACES(queue.TO_ARRAY()); + expected.sort(null); + assertEquals("Elements were expected to be sorted", expected, queue.sorted(null).pourAsList()); + } + +#if TYPE_OBJECT +#ignore + @CollectionFeature.Require(absent = CollectionFeature.KNOWN_ORDER) + @SpecialFeature.Require(SpecialFeature.MAP_ENTRY) +#endignore + public void testQueueSortedEntry() { + ObjectList expected = new ObjectArrayList<>(queue.TO_ARRAY()); + Comparator comparator = Comparator.comparing(T -> (Comparable)((Map.Entry)T).getKey()); + expected.sort(comparator); + assertEquals("Elements were expected to be sorted", expected, queue.sorted(comparator).pourAsList()); + } +#endif +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/set/NavigableSetNavigationTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/set/NavigableSetNavigationTester.template new file mode 100644 index 00000000..b3d5a53b --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/set/NavigableSetNavigationTester.template @@ -0,0 +1,285 @@ +package speiger.src.testers.PACKAGE.tests.set; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import java.util.TreeSet; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET; +import speiger.src.collections.PACKAGE.utils.LISTS; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_SET_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPENavigableSetNavigationTester KEY_GENERIC_TYPE extends ABSTRACT_SET_TESTER KEY_GENERIC_TYPE +{ + private NAVIGABLE_SET KEY_GENERIC_TYPE navigableSet; + private LIST KEY_GENERIC_TYPE values; + private KEY_TYPE a; + private KEY_TYPE b; + private KEY_TYPE c; + + @Override + public void setUp() throws Exception { + super.setUp(); + navigableSet = (NAVIGABLE_SET KEY_GENERIC_TYPE) getSet(); + values = HELPERS.copyToList(getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements())); + values.sort(navigableSet.comparator()); + if (values.size() >= 1) { + a = values.GET_KEY(0); + if (values.size() >= 3) { + b = values.GET_KEY(1); + c = values.GET_KEY(2); + } + } + } + + protected void resetWithHole() { + super.resetContainer(primitiveGenerator.create(createArray(a, c))); + navigableSet = (NAVIGABLE_SET KEY_GENERIC_TYPE) getSet(); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) +#endignore + public void testEmptySetPollFirst() { +#if TYPE_OBJECT + assertEquals(null, navigableSet.POLL_FIRST_KEY()); +#else + assertEquals(navigableSet.getDefaultMinValue(), navigableSet.POLL_FIRST_KEY()); +#endif + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptySetNearby() { +#if TYPE_OBJECT + assertEquals(null, navigableSet.lower(e0())); + assertEquals(null, navigableSet.floor(e0())); + assertEquals(null, navigableSet.ceiling(e0())); + assertEquals(null, navigableSet.higher(e0())); +#else + assertEquals(navigableSet.getDefaultMinValue(), navigableSet.lower(e0())); + assertEquals(navigableSet.getDefaultMinValue(), navigableSet.floor(e0())); + assertEquals(navigableSet.getDefaultMaxValue(), navigableSet.ceiling(e0())); + assertEquals(navigableSet.getDefaultMaxValue(), navigableSet.higher(e0())); +#endif + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) +#endignore + public void testEmptySetPollLast() { +#if TYPE_OBJECT + assertEquals(null, navigableSet.POLL_LAST_KEY()); +#else + assertEquals(navigableSet.getDefaultMaxValue(), navigableSet.POLL_LAST_KEY()); +#endif + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ONE) +#endignore + public void testSingletonSetPollFirst() { + assertEquals(a, navigableSet.POLL_FIRST_KEY()); + assertTrue(navigableSet.isEmpty()); + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonSetNearby() { +#if TYPE_OBJECT + assertEquals(null, navigableSet.lower(e0())); + assertEquals(a, navigableSet.floor(e0())); + assertEquals(a, navigableSet.ceiling(e0())); + assertEquals(null, navigableSet.higher(e0())); +#else + assertEquals(navigableSet.getDefaultMinValue(), navigableSet.lower(e0())); + assertEquals(a, navigableSet.floor(e0())); + assertEquals(a, navigableSet.ceiling(e0())); + assertEquals(navigableSet.getDefaultMaxValue(), navigableSet.higher(e0())); +#endif + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ONE) +#endignore + public void testSingletonSetPollLast() { + assertEquals(a, navigableSet.POLL_LAST_KEY()); + assertTrue(navigableSet.isEmpty()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testPollFirst() { + assertEquals(a, navigableSet.POLL_FIRST_KEY()); + assertEquals(values.subList(1, values.size()), HELPERS.copyToList(navigableSet)); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testPollFirstUnsupported() { + try { + navigableSet.POLL_FIRST_KEY(); + fail(); + } catch (UnsupportedOperationException e) { + } + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testLowerHole() { + resetWithHole(); +#if TYPE_OBJECT + assertEquals(null, navigableSet.lower(a)); +#else + assertEquals(navigableSet.getDefaultMinValue(), navigableSet.lower(a)); +#endif + assertEquals(a, navigableSet.lower(b)); + assertEquals(a, navigableSet.lower(c)); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testFloorHole() { + resetWithHole(); + assertEquals(a, navigableSet.floor(a)); + assertEquals(a, navigableSet.floor(b)); + assertEquals(c, navigableSet.floor(c)); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testCeilingHole() { + resetWithHole(); + assertEquals(a, navigableSet.ceiling(a)); + assertEquals(c, navigableSet.ceiling(b)); + assertEquals(c, navigableSet.ceiling(c)); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testHigherHole() { + resetWithHole(); + assertEquals(c, navigableSet.higher(a)); + assertEquals(c, navigableSet.higher(b)); +#if TYPE_OBJECT + assertEquals(null, navigableSet.higher(c)); +#else + assertEquals(navigableSet.getDefaultMaxValue(), navigableSet.higher(c)); +#endif + } + + /* + * TODO(cpovirk): make "too small" and "too large" elements available for + * better navigation testing. At that point, we may be able to eliminate the + * "hole" tests, which would mean that ContiguousSet's tests would no longer + * need to suppress them. + */ +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testLower() { +#if TYPE_OBJECT + assertEquals(null, navigableSet.lower(a)); +#else + assertEquals(navigableSet.getDefaultMinValue(), navigableSet.lower(a)); +#endif + assertEquals(a, navigableSet.lower(b)); + assertEquals(b, navigableSet.lower(c)); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testFloor() { + assertEquals(a, navigableSet.floor(a)); + assertEquals(b, navigableSet.floor(b)); + assertEquals(c, navigableSet.floor(c)); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testCeiling() { + assertEquals(a, navigableSet.ceiling(a)); + assertEquals(b, navigableSet.ceiling(b)); + assertEquals(c, navigableSet.ceiling(c)); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testHigher() { + assertEquals(b, navigableSet.higher(a)); + assertEquals(c, navigableSet.higher(b)); +#if TYPE_OBJECT + assertEquals(null, navigableSet.higher(c)); +#else + assertEquals(navigableSet.getDefaultMaxValue(), navigableSet.higher(c)); +#endif + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testPollLast() { + assertEquals(c, navigableSet.POLL_LAST_KEY()); + assertEquals(values.subList(0, values.size() - 1), HELPERS.copyToList(navigableSet)); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testPollLastUnsupported() { + try { + navigableSet.POLL_LAST_KEY(); + fail(); + } catch (UnsupportedOperationException e) { + } + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testDescendingNavigation() { + LIST KEY_GENERIC_TYPE descending = new ARRAY_LISTBRACES(); + for (ITERATOR KEY_GENERIC_TYPE i = navigableSet.descendingIterator(); i.hasNext();) { + descending.add(i.NEXT()); + } + LISTS.reverse(descending); + assertEquals(values, descending); + } + + public void testEmptySubSet() { + NAVIGABLE_SET KEY_GENERIC_TYPE empty = navigableSet.subSet(e0(), false, e0(), false); + assertEquals(new TreeSet<>(), empty); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/set/OrderedSetIterationTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/set/OrderedSetIterationTester.template new file mode 100644 index 00000000..533b3dc5 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/set/OrderedSetIterationTester.template @@ -0,0 +1,56 @@ +package speiger.src.testers.PACKAGE.tests.set; + +import java.util.NoSuchElementException; + +import org.junit.Assert; +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.sets.ORDERED_SET; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_SET_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEOrderedSetIterationTester KEY_GENERIC_TYPE extends ABSTRACT_SET_TESTER KEY_GENERIC_TYPE +{ + private ORDERED_SET KEY_GENERIC_TYPE orderedSet; + + @Override + public void setUp() throws Exception { + super.setUp(); + orderedSet = (ORDERED_SET KEY_GENERIC_TYPE) getSet(); + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testMissingIterator() { + try { + orderedSet.iterator(e3()); + fail("Iterator with missing Element should throw NoSuchElementException"); + } + catch(NoSuchElementException e) {} + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testFirstElement() { + Assert.assertTrue(orderedSet.iterator(e0()) != null); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testLastElement() { + Assert.assertTrue(orderedSet.iterator(e2()) != null); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testCenterElement() { + Assert.assertTrue(orderedSet.iterator(e1()) != null); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/set/OrderedSetMoveTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/set/OrderedSetMoveTester.template new file mode 100644 index 00000000..b45cd1db --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/set/OrderedSetMoveTester.template @@ -0,0 +1,271 @@ +package speiger.src.testers.PACKAGE.tests.set; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static org.junit.Assert.assertNotEquals; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.sets.ORDERED_SET; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_SET_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; +import speiger.src.testers.utils.SpecialFeature; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT_SET_TESTER KEY_GENERIC_TYPE +{ + private ORDERED_SET KEY_GENERIC_TYPE orderedSet; + private LIST KEY_GENERIC_TYPE values; + private KEY_TYPE a; + private KEY_TYPE c; + + @Override + public void setUp() throws Exception { + super.setUp(); + orderedSet = (ORDERED_SET KEY_GENERIC_TYPE) getSet(); + values = HELPERS.copyToList(getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements())); + if (values.size() >= 1) { + a = values.GET_KEY(0); + if (values.size() >= 3) { + c = values.GET_KEY(2); + } + } + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(SEVERAL) +#endignore + public void testaddMoveToFirstMissing() + { + assertEquals(a, orderedSet.FIRST_KEY()); + assertEquals(true, orderedSet.addAndMoveToFirst(e4())); + assertNotEquals(a, orderedSet.FIRST_KEY()); + assertEquals(e4(), orderedSet.FIRST_KEY()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(SEVERAL) +#endignore + public void testaddMoveToFirstPreset() + { + assertEquals(a, orderedSet.FIRST_KEY()); + assertEquals(false, orderedSet.addAndMoveToFirst(c)); + assertNotEquals(a, orderedSet.FIRST_KEY()); + assertEquals(c, orderedSet.FIRST_KEY()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(SEVERAL) +#endignore + public void testaddMoveToLastMissing() + { + assertEquals(c, orderedSet.LAST_KEY()); + assertEquals(true, orderedSet.addAndMoveToLast(e4())); + assertNotEquals(c, orderedSet.LAST_KEY()); + assertEquals(e4(), orderedSet.LAST_KEY()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(SEVERAL) +#endignore + public void testaddMoveToLastPreset() + { + assertEquals(c, orderedSet.LAST_KEY()); + assertEquals(false, orderedSet.addAndMoveToLast(a)); + assertNotEquals(c, orderedSet.LAST_KEY()); + assertEquals(a, orderedSet.LAST_KEY()); + } + +#ignore + @SpecialFeature.Require(SpecialFeature.MODIFIABLE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveToFirstMissing() + { + assertEquals(a, orderedSet.FIRST_KEY()); + assertEquals(false, orderedSet.moveToFirst(e4())); + assertEquals(a, orderedSet.FIRST_KEY()); + } + +#ignore + @SpecialFeature.Require(SpecialFeature.MODIFIABLE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveToFirstPreset() + { + assertEquals(a, orderedSet.FIRST_KEY()); + assertEquals(true, orderedSet.moveToFirst(c)); + assertNotEquals(a, orderedSet.FIRST_KEY()); + assertEquals(c, orderedSet.FIRST_KEY()); + } + +#ignore + @SpecialFeature.Require(SpecialFeature.MODIFIABLE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveToLastMissing() + { + assertEquals(c, orderedSet.LAST_KEY()); + assertEquals(false, orderedSet.moveToLast(e4())); + assertEquals(c, orderedSet.LAST_KEY()); + } + +#ignore + @SpecialFeature.Require(SpecialFeature.MODIFIABLE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveToLastPreset() + { + assertEquals(c, orderedSet.LAST_KEY()); + assertEquals(true, orderedSet.moveToLast(a)); + assertNotEquals(c, orderedSet.LAST_KEY()); + assertEquals(a, orderedSet.LAST_KEY()); + } + +#ignore + @SpecialFeature.Require(SpecialFeature.MODIFIABLE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveCenterToLast() + { + assertEquals(c, orderedSet.LAST_KEY()); + assertTrue(orderedSet.moveToLast(e1())); + assertNotEquals(c, orderedSet.LAST_KEY()); + assertEquals(e1(), orderedSet.LAST_KEY()); + } + +#ignore + @SpecialFeature.Require(SpecialFeature.MODIFIABLE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveCenterToFirst() + { + assertEquals(a, orderedSet.FIRST_KEY()); + assertTrue(orderedSet.moveToFirst(e1())); + assertNotEquals(c, orderedSet.FIRST_KEY()); + assertEquals(e1(), orderedSet.FIRST_KEY()); + } + +#ignore + @SpecialFeature.Require(SpecialFeature.MODIFIABLE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveForthAndBack() + { + assertEquals(c, orderedSet.LAST_KEY()); + assertTrue(orderedSet.moveToLast(e0())); + assertNotEquals(c, orderedSet.LAST_KEY()); + assertEquals(a, orderedSet.LAST_KEY()); + assertNotEquals(a, orderedSet.FIRST_KEY()); + assertTrue(orderedSet.moveToFirst(e0())); + assertEquals(a, orderedSet.FIRST_KEY()); + } + +#ignore + @SpecialFeature.Require(SpecialFeature.MODIFIABLE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testMoveBackAndForth() + { + assertEquals(a, orderedSet.FIRST_KEY()); + assertTrue(orderedSet.moveToFirst(e2())); + assertNotEquals(a, orderedSet.FIRST_KEY()); + assertEquals(c, orderedSet.FIRST_KEY()); + assertNotEquals(c, orderedSet.LAST_KEY()); + assertTrue(orderedSet.moveToLast(e2())); + assertEquals(c, orderedSet.LAST_KEY()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(SEVERAL) +#endignore + public void testAddForthAndBack() + { + assertEquals(c, orderedSet.LAST_KEY()); + assertFalse(orderedSet.addAndMoveToLast(e0())); + assertNotEquals(c, orderedSet.LAST_KEY()); + assertEquals(a, orderedSet.LAST_KEY()); + assertNotEquals(a, orderedSet.FIRST_KEY()); + assertFalse(orderedSet.addAndMoveToFirst(e0())); + assertEquals(a, orderedSet.FIRST_KEY()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(SEVERAL) +#endignore + public void testAddBackAndForth() + { + assertEquals(a, orderedSet.FIRST_KEY()); + assertFalse(orderedSet.addAndMoveToFirst(e2())); + assertNotEquals(a, orderedSet.FIRST_KEY()); + assertEquals(c, orderedSet.FIRST_KEY()); + assertNotEquals(c, orderedSet.LAST_KEY()); + assertFalse(orderedSet.addAndMoveToLast(e2())); + assertEquals(c, orderedSet.LAST_KEY()); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_ADD) +#endignore + public void testaddMoveToFirstUnsupported() + { + try { + orderedSet.addAndMoveToFirst(e4()); + fail("addAndMoveToFirst should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_ADD) +#endignore + public void testaddMoveToLastUnsupported() + { + try { + orderedSet.addAndMoveToLast(e4()); + fail("addAndMoveToLast should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } + +#ignore + @SpecialFeature.Require(absent = SpecialFeature.MODIFIABLE) +#endignore + public void testmoveToFirstUnsupported() + { + try { + orderedSet.moveToFirst(c); + fail("moveToFirst should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } + +#ignore + @SpecialFeature.Require(absent = SpecialFeature.MODIFIABLE) +#endignore + public void testmoveToLastUnsupported() + { + try { + orderedSet.moveToLast(a); + fail("moveToLast should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/set/OrderedSetNavigationTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/set/OrderedSetNavigationTester.template new file mode 100644 index 00000000..dc7935d6 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/set/OrderedSetNavigationTester.template @@ -0,0 +1,248 @@ +package speiger.src.testers.PACKAGE.tests.set; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import java.util.NoSuchElementException; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.sets.ORDERED_SET; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_SET_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends ABSTRACT_SET_TESTER KEY_GENERIC_TYPE +{ + private ORDERED_SET KEY_GENERIC_TYPE orderedSet; + private LIST KEY_GENERIC_TYPE values; + private KEY_TYPE a; + private KEY_TYPE c; + + @Override + public void setUp() throws Exception { + super.setUp(); + orderedSet = (ORDERED_SET KEY_GENERIC_TYPE) getSet(); + values = HELPERS.copyToList(getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements())); + if (values.size() >= 1) { + a = values.GET_KEY(0); + if (values.size() >= 3) { + c = values.GET_KEY(2); + } + } + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(ZERO) +#endignore + public void testAddEmptySetToFirst() { + orderedSet.addAndMoveToFirst(e0()); + expectAdded(e0()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(ZERO) +#endignore + public void testAddEmptySetToLast() { + orderedSet.addAndMoveToLast(e0()); + expectAdded(e0()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testyMapPollFirstEmpty() { + int polled = 0; + int expectedPolls = orderedSet.size(); + while(polled < expectedPolls) { + orderedSet.POLL_FIRST_KEY(); + polled++; + } + assertTrue("Map should be empty", orderedSet.isEmpty()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testyMapPollLastEmpty() { + int polled = 0; + int expectedPolls = orderedSet.size(); + while(polled < expectedPolls) { + orderedSet.POLL_LAST_KEY(); + polled++; + } + assertTrue("Map should be empty", orderedSet.isEmpty()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) +#endignore + public void testEmptySetPollFirst() { + try { + orderedSet.POLL_FIRST_KEY(); + fail("OrderedSet.POLL_FIRST_KEY should throw NoSuchElementException"); + } catch (NoSuchElementException e) { + } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) +#endignore + public void testEmptySetPollLast() { + try { + orderedSet.POLL_LAST_KEY(); + fail("OrderedSet.POLL_LAST_KEY should throw NoSuchElementException"); + } catch (NoSuchElementException e) { + } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testUnsupportedSetPollFirst() { + try { + orderedSet.POLL_FIRST_KEY(); + fail("OrderedSet.POLL_FIRST_KEY should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testUnsupportedSetPollLast() { + try { + orderedSet.POLL_LAST_KEY(); + fail("OrderedSet.POLL_LAST_KEY should throw UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + } + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ONE) +#endignore + public void testSingletonSetPollFirst() { + assertEquals(a, orderedSet.POLL_FIRST_KEY()); + assertTrue(orderedSet.isEmpty()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ONE) +#endignore + public void testSingletonSetPollLast() { + assertEquals(a, orderedSet.POLL_LAST_KEY()); + assertTrue(orderedSet.isEmpty()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testPollFirst() { + assertEquals(a, orderedSet.POLL_FIRST_KEY()); + assertEquals(values.subList(1, values.size()), HELPERS.copyToList(orderedSet)); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testPollLast() { + assertEquals(c, orderedSet.POLL_LAST_KEY()); + assertEquals(values.subList(0, values.size()-1), HELPERS.copyToList(orderedSet)); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testPollFirstUnsupported() { + try { + orderedSet.POLL_FIRST_KEY(); + fail(); + } catch (UnsupportedOperationException e) { + } + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testPollLastUnsupported() { + try { + orderedSet.POLL_LAST_KEY(); + fail(); + } catch (UnsupportedOperationException e) { + } + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptySetFirst() { + try { + orderedSet.FIRST_KEY(); + fail(); + } catch (NoSuchElementException e) { + } + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptySetLast() { + try { + orderedSet.LAST_KEY(); + fail(); + } catch (NoSuchElementException e) { + } + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonSetFirst() { + assertEquals(a, orderedSet.FIRST_KEY()); + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonSetLast() { + assertEquals(a, orderedSet.LAST_KEY()); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testFirst() { + assertEquals(a, orderedSet.FIRST_KEY()); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testLast() { + assertEquals(c, orderedSet.LAST_KEY()); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/set/SetAddAllTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/set/SetAddAllTester.template new file mode 100644 index 00000000..b53bccb7 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/set/SetAddAllTester.template @@ -0,0 +1,46 @@ +package speiger.src.testers.PACKAGE.tests.set; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_SET_TESTER; +import speiger.src.testers.PACKAGE.utils.MINIMAL_COLLECTION; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPESetAddAllTester KEY_GENERIC_TYPE extends ABSTRACT_SET_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAll_supportedSomePresent() { + assertTrue("add(somePresent) should return true", getSet().addAll(MINIMAL_COLLECTION.of(e3(), e0()))); + expectAdded(e3()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) +#endignore + public void testAddAll_withDuplicates() { + MINIMAL_COLLECTION KEY_GENERIC_TYPE elementsToAdd = MINIMAL_COLLECTION.of(e3(), e4(), e3(), e4()); + assertTrue("add(hasDuplicates) should return true", getSet().addAll(elementsToAdd)); + expectAdded(e3(), e4()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAddAll_supportedAllPresent() { + assertFalse("add(allPresent) should return false", getSet().addAll(MINIMAL_COLLECTION.of(e0()))); + expectUnchanged(); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/set/SetAddTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/set/SetAddTester.template new file mode 100644 index 00000000..557ddb36 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/set/SetAddTester.template @@ -0,0 +1,36 @@ +package speiger.src.testers.PACKAGE.tests.set; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_SET_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPESetAddTester KEY_GENERIC_TYPE extends ABSTRACT_SET_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testAdd_supportedPresent() { + assertFalse("add(present) should return false", getSet().add(e0())); + expectUnchanged(); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_ADD) + @CollectionSize.Require(ZERO) +#endignore + public void testAdd_supportedMissing() { + assertTrue("add(missing) should return true", getSet().add(e0())); + expectAdded(e0()); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/set/SetCreationTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/set/SetCreationTester.template new file mode 100644 index 00000000..7ed995d9 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/set/SetCreationTester.template @@ -0,0 +1,45 @@ +package speiger.src.testers.PACKAGE.tests.set; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.REJECTS_DUPLICATES_AT_CREATION; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_SET_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPESetCreationTester KEY_GENERIC_TYPE extends ABSTRACT_SET_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testCreateWithDuplicates_nonNullDuplicatesNotRejected() { + KEY_TYPE[] array = createSamplesArray(); + array[1] = e0(); + collection = primitiveGenerator.create(array); + expectContents(ARRAY_LIST.wrap(array).subList(1, getNumElements())); + } + +#ignore + @CollectionFeature.Require(REJECTS_DUPLICATES_AT_CREATION) + @CollectionSize.Require(absent = { ZERO, ONE }) +#endignore + public void testCreateWithDuplicates_nonNullDuplicatesRejected() { + KEY_TYPE[] array = createSamplesArray(); + array[1] = e0(); + try { + collection = primitiveGenerator.create(array); + fail("Should reject duplicate non-null elements at creation"); + } catch (IllegalArgumentException expected) { + } + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/set/SetEqualsTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/set/SetEqualsTester.template new file mode 100644 index 00000000..c197118b --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/set/SetEqualsTester.template @@ -0,0 +1,45 @@ +package speiger.src.testers.PACKAGE.tests.set; + +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_SET_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; +import speiger.src.testers.PACKAGE.utils.MINIMAL_SET; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPESetEqualsTester KEY_GENERIC_TYPE extends ABSTRACT_SET_TESTER KEY_GENERIC_TYPE +{ + public void testEquals_otherSetWithSameElements() { + assertTrue("A Set should equal any other Set containing the same elements.", getSet().equals(MINIMAL_SET.of(getSampleElements()))); + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testEquals_otherSetWithDifferentElements() { + COLLECTION KEY_GENERIC_TYPE elements = getSampleElements(getNumElements() - 1); + elements.add(e3()); + assertFalse("A Set should not equal another Set containing different elements.", getSet().equals(MINIMAL_SET.of(elements))); + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testEquals_smallerSet() { + COLLECTION KEY_GENERIC_TYPE fewerElements = getSampleElements(getNumElements() - 1); + assertFalse("Sets of different sizes should not be equal.", getSet().equals(MINIMAL_SET.of(fewerElements))); + } + + public void testEquals_largerSet() { + COLLECTION KEY_GENERIC_TYPE moreElements = getSampleElements(getNumElements() + 1); + assertFalse("Sets of different sizes should not be equal.", getSet().equals(MINIMAL_SET.of(moreElements))); + } + + public void testEquals_list() { + assertFalse("A List should never equal a Set.", getSet().equals(HELPERS.copyToList(getSet()))); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/set/SetRemoveTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/set/SetRemoveTester.template new file mode 100644 index 00000000..84bca9ab --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/set/SetRemoveTester.template @@ -0,0 +1,54 @@ +package speiger.src.testers.PACKAGE.tests.set; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +#endignore + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_SET_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPESetRemoveTester KEY_GENERIC_TYPE extends ABSTRACT_SET_TESTER KEY_GENERIC_TYPE +{ +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) +#endignore + public void testRemove_present() { + getSet().remove(e0()); + assertFalse("After remove(present) a set should not contain the removed element.", getSet().contains(e0())); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) +#endignore + public void testRemove_Missing() { + getSet().remove(e3()); + assertFalse("After remove(present) a set should not contain the removed element.", getSet().contains(e3())); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemove_middle() { + getSet().remove(e1()); + assertFalse("After remove(present) a set should not contain the removed element.", getSet().contains(e1())); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testRemove_last() { + getSet().remove(e2()); + assertFalse("After remove(present) a set should not contain the removed element.", getSet().contains(e2())); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/set/SortedSetIterationTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/set/SortedSetIterationTester.template new file mode 100644 index 00000000..aed6e8f6 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/set/SortedSetIterationTester.template @@ -0,0 +1,43 @@ +package speiger.src.testers.PACKAGE.tests.set; + +import org.junit.Assert; +import org.junit.Ignore; + +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.sets.SORTED_SET; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_SET_TESTER; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPESortedSetIterationTester KEY_GENERIC_TYPE extends ABSTRACT_SET_TESTER KEY_GENERIC_TYPE +{ + private SORTED_SET KEY_GENERIC_TYPE sortedSet; + + @Override + public void setUp() throws Exception { + super.setUp(); + sortedSet = (SORTED_SET KEY_GENERIC_TYPE) getSet(); + } + +#ignore + @CollectionSize.Require(absent = CollectionSize.ZERO) +#endignore + public void testFirstElement() { + Assert.assertTrue(sortedSet.iterator(e0()) != null); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testLastElement() { + Assert.assertTrue(sortedSet.iterator(e2()) != null); + } + +#ignore + @CollectionSize.Require(CollectionSize.SEVERAL) +#endignore + public void testCenterElement() { + Assert.assertTrue(sortedSet.iterator(e1()) != null); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/tests/set/SortedSetNaviationTester.template b/src/builder/resources/speiger/assets/testers/templates/tests/set/SortedSetNaviationTester.template new file mode 100644 index 00000000..111e9705 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/tests/set/SortedSetNaviationTester.template @@ -0,0 +1,178 @@ +package speiger.src.testers.PACKAGE.tests.set; + +import org.junit.Ignore; + +#ignore +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.ONE; +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; +#endignore + +import java.util.NoSuchElementException; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.sets.SORTED_SET; +import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_SET_TESTER; +import speiger.src.testers.PACKAGE.utils.HELPERS; + +@Ignore +@SuppressWarnings("javadoc") +public class FILE_KEY_TYPESortedSetNaviationTester KEY_GENERIC_TYPE extends ABSTRACT_SET_TESTER KEY_GENERIC_TYPE +{ + private SORTED_SET KEY_GENERIC_TYPE sortedSet; + private LIST KEY_GENERIC_TYPE values; + private KEY_TYPE a; + private KEY_TYPE c; + + @Override + public void setUp() throws Exception { + super.setUp(); + sortedSet = (SORTED_SET KEY_GENERIC_TYPE) getSet(); + values = HELPERS.copyToList(getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements())); + values.sort(sortedSet.comparator()); + + // some tests assume SEVERAL == 3 + if (values.size() >= 1) { + a = values.GET_KEY(0); + if (values.size() >= 3) { + c = values.GET_KEY(2); + } + } + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) +#endignore + public void testEmptySetPollFirst() { +#if TYPE_OBJECT + assertEquals(null, sortedSet.POLL_FIRST_KEY()); +#else + assertEquals(CLASS_TYPE.MAX_VALUE, sortedSet.POLL_FIRST_KEY()); +#endif + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) +#endignore + public void testEmptySetPollLast() { +#if TYPE_OBJECT + assertEquals(null, sortedSet.POLL_LAST_KEY()); +#else + assertEquals(CLASS_TYPE.MIN_VALUE, sortedSet.POLL_LAST_KEY()); +#endif + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ONE) +#endignore + public void testSingletonSetPollFirst() { + assertEquals(a, sortedSet.POLL_FIRST_KEY()); + assertTrue(sortedSet.isEmpty()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(ONE) +#endignore + public void testSingletonSetPollLast() { + assertEquals(a, sortedSet.POLL_LAST_KEY()); + assertTrue(sortedSet.isEmpty()); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testPollFirst() { + assertEquals(a, sortedSet.POLL_FIRST_KEY()); + assertEquals(values.subList(1, values.size()), HELPERS.copyToList(sortedSet)); + } + +#ignore + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(SEVERAL) +#endignore + public void testPollLast() { + assertEquals(c, sortedSet.POLL_LAST_KEY()); + assertEquals(values.subList(0, values.size()-1), HELPERS.copyToList(sortedSet)); + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testPollFirstUnsupported() { + try { + sortedSet.POLL_FIRST_KEY(); + fail(); + } catch (UnsupportedOperationException e) { + } + } + +#ignore + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) +#endignore + public void testPollLastUnsupported() { + try { + sortedSet.POLL_LAST_KEY(); + fail(); + } catch (UnsupportedOperationException e) { + } + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptySetFirst() { + try { + sortedSet.FIRST_KEY(); + fail(); + } catch (NoSuchElementException e) { + } + } + +#ignore + @CollectionSize.Require(ZERO) +#endignore + public void testEmptySetLast() { + try { + sortedSet.LAST_KEY(); + fail(); + } catch (NoSuchElementException e) { + } + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonSetFirst() { + assertEquals(a, sortedSet.FIRST_KEY()); + } + +#ignore + @CollectionSize.Require(ONE) +#endignore + public void testSingletonSetLast() { + assertEquals(a, sortedSet.LAST_KEY()); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testFirst() { + assertEquals(a, sortedSet.FIRST_KEY()); + } + +#ignore + @CollectionSize.Require(SEVERAL) +#endignore + public void testLast() { + assertEquals(c, sortedSet.LAST_KEY()); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/utils/AbstractIteratorTester.template b/src/builder/resources/speiger/assets/testers/templates/utils/AbstractIteratorTester.template new file mode 100644 index 00000000..a6a052d3 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/utils/AbstractIteratorTester.template @@ -0,0 +1,533 @@ +package speiger.src.testers.PACKAGE.utils; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.NoSuchElementException; +import java.util.Set; + +import org.junit.Assert; + +import com.google.common.collect.testing.Helpers; +import com.google.common.collect.testing.IteratorFeature; + +import junit.framework.AssertionFailedError; +import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; +import speiger.src.collections.PACKAGE.collections.ITERABLE; +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; + +@SuppressWarnings("javadoc") +public abstract class ABSTRACT_ITERATOR_TESTER KEY_GENERIC_TYPE +{ + private Stimulus[] stimuli; + private final ITERATOR KEY_GENERIC_TYPE elementsToInsert; + private final Set features; + private final LIST KEY_GENERIC_TYPE expectedElements; + private final int startIndex; + private final KnownOrder knownOrder; + + private abstract static class PermittedMetaException extends RuntimeException { + static final PermittedMetaException UOE_OR_ISE = new PermittedMetaException( + "UnsupportedOperationException or IllegalStateException") { + private static final long serialVersionUID = 1L; + + @Override + boolean isPermitted(RuntimeException exception) { + return exception instanceof UnsupportedOperationException || exception instanceof IllegalStateException; + } + }; + static final PermittedMetaException UOE = new PermittedMetaException("UnsupportedOperationException") { + private static final long serialVersionUID = 1L; + + @Override + boolean isPermitted(RuntimeException exception) { + return exception instanceof UnsupportedOperationException; + } + }; + static final PermittedMetaException ISE = new PermittedMetaException("IllegalStateException") { + private static final long serialVersionUID = 1L; + + @Override + boolean isPermitted(RuntimeException exception) { + return exception instanceof IllegalStateException; + } + }; + static final PermittedMetaException NSEE = new PermittedMetaException("NoSuchElementException") { + private static final long serialVersionUID = 1L; + + @Override + boolean isPermitted(RuntimeException exception) { + return exception instanceof NoSuchElementException; + } + }; + + private PermittedMetaException(String message) { + super(message); + } + + abstract boolean isPermitted(RuntimeException exception); + + void assertPermitted(RuntimeException exception) { + if (!isPermitted(exception)) { + String message = "Exception " + exception.getClass().getSimpleName() + " was thrown; expected " + + getMessage(); + AssertionFailedError assertionFailedError = new AssertionFailedError(String.valueOf(message)); + assertionFailedError.initCause(exception); + throw assertionFailedError; + } + } + + private static final long serialVersionUID = 0; + } + + private static final class UnknownElementException extends RuntimeException { + private UnknownElementException(Collection expected, Object actual) { + super("Returned value '" + actual + "' not found. Remaining elements: " + expected); + } + + private static final long serialVersionUID = 0; + } + + protected final class MultiExceptionListIterator implements LIST_ITERATOR KEY_GENERIC_TYPE { + final ARRAY_LIST KEY_GENERIC_TYPE nextElements = new ARRAY_LISTBRACES(); + final ARRAY_LIST KEY_GENERIC_TYPE previousElements = new ARRAY_LISTBRACES(); + ARRAY_LIST KEY_GENERIC_TYPE stackWithLastReturnedElementAtTop = null; + + MultiExceptionListIterator(LIST KEY_GENERIC_TYPE expectedElements) { + HELPERS.addAll(nextElements, HELPERS.reverse(expectedElements)); + for (int i = 0; i < startIndex; i++) { + previousElements.push(nextElements.pop()); + } + } + + @Override + public void add(KEY_TYPE e) { + if (!features.contains(IteratorFeature.SUPPORTS_ADD)) { + throw PermittedMetaException.UOE; + } + + previousElements.push(e); + stackWithLastReturnedElementAtTop = null; + } + + @Override + public boolean hasNext() { + return !nextElements.isEmpty(); + } + + @Override + public boolean hasPrevious() { + return !previousElements.isEmpty(); + } + + @Override + public KEY_TYPE NEXT() { + return transferElement(nextElements, previousElements); + } + + @Override + public int nextIndex() { + return previousElements.size(); + } + + @Override + public KEY_TYPE PREVIOUS() { + return transferElement(previousElements, nextElements); + } + + @Override + public int previousIndex() { + return nextIndex() - 1; + } + + @Override + public void remove() { +#ignore + throwIfInvalid(IteratorFeature.SUPPORTS_REMOVE); +#endignore + + stackWithLastReturnedElementAtTop.pop(); + stackWithLastReturnedElementAtTop = null; + } + + @Override + public void set(KEY_TYPE e) { +#ignore + throwIfInvalid(IteratorFeature.SUPPORTS_SET); +#endignore + + stackWithLastReturnedElementAtTop.pop(); + stackWithLastReturnedElementAtTop.push(e); + } + + void promoteToNext(KEY_TYPE e) { +#if TYPE_OBJECT + if (nextElements.remove(e)) { +#else + if (nextElements.REMOVE_KEY(e)) { +#endif + nextElements.push(e); + } else { + throw new UnknownElementException(nextElements, e); + } + } + + private KEY_TYPE transferElement(ARRAY_LIST KEY_GENERIC_TYPE source, ARRAY_LIST KEY_GENERIC_TYPE destination) { + if (source.isEmpty()) { + throw PermittedMetaException.NSEE; + } + + destination.push(source.pop()); + stackWithLastReturnedElementAtTop = destination; + return destination.top(); + } + + private void throwIfInvalid(IteratorFeature methodFeature) { + if (!features.contains(methodFeature)) { + if (stackWithLastReturnedElementAtTop == null) { + throw PermittedMetaException.UOE_OR_ISE; + } else { + throw PermittedMetaException.UOE; + } + } else if (stackWithLastReturnedElementAtTop == null) { + throw PermittedMetaException.ISE; + } + } + + private LIST KEY_GENERIC_TYPE getElements() { + LIST KEY_GENERIC_TYPE elements = new ARRAY_LISTBRACES(); + HELPERS.addAll(elements, previousElements); + HELPERS.addAll(elements, HELPERS.reverse(nextElements)); + return elements; + } + } + + public enum KnownOrder { +#ignore + KNOWN_ORDER, UNKNOWN_ORDER +#endignore + } + + ABSTRACT_ITERATOR_TESTER(int steps, ITERABLE KEY_GENERIC_TYPE elementsToInsertIterable, + Iterable features, ITERABLE KEY_GENERIC_TYPE expectedElements, KnownOrder knownOrder, int startIndex) { + stimuli = new Stimulus[steps]; + if (!elementsToInsertIterable.iterator().hasNext()) { + throw new IllegalArgumentException(); + } + elementsToInsert = HELPERS.cycle(elementsToInsertIterable); + this.features = Helpers.copyToSet(features); + this.expectedElements = HELPERS.copyToList(expectedElements); + this.knownOrder = knownOrder; + this.startIndex = startIndex; + } + + protected abstract Iterable> getStimulusValues(); + + protected abstract ITERATOR KEY_GENERIC_TYPE newTargetIterator(); + protected void verify(LIST KEY_GENERIC_TYPE elements) { + } + + /** Executes the test. */ + public final void test() { + try { + recurse(0); + } catch (RuntimeException e) { + throw new RuntimeException(Arrays.toString(stimuli), e); + } + } + + public void testForEachRemaining() { + for (int i = 0; i < expectedElements.size() - 1; i++) { + + LIST KEY_GENERIC_TYPE targetElements = new ARRAY_LISTBRACES(); + ITERATOR KEY_GENERIC_TYPE iterator = newTargetIterator(); + for (int j = 0; j < i; j++) { + targetElements.add(iterator.NEXT()); + } + iterator.forEachRemaining(targetElements::add); + if (knownOrder == KnownOrder.KNOWN_ORDER) { + Assert.assertEquals(expectedElements, targetElements); + } else { + HELPERS.assertEqualIgnoringOrder(expectedElements, targetElements); + } + } + } + + private void recurse(int level) { + if (level == stimuli.length) { + // We've filled the array. + compareResultsForThisListOfStimuli(); + } else { + // Keep recursing to fill the array. + for (Stimulus stimulus : getStimulusValues()) { + stimuli[level] = stimulus; + recurse(level + 1); + } + } + } + + private void compareResultsForThisListOfStimuli() { + int removes = Collections.frequency(Arrays.asList(stimuli), remove); +#ignore + if ((!features.contains(IteratorFeature.SUPPORTS_REMOVE) && removes > 1) || (stimuli.length >= 5 && removes > 2)) { +#endignore + // removes are the most expensive thing to test, since they often + // throw exceptions with stack + // traces, so we test them a bit less aggressively + return; + } + + MultiExceptionListIterator reference = new MultiExceptionListIterator(expectedElements); + ITERATOR KEY_GENERIC_TYPE target = newTargetIterator(); + for (int i = 0; i < stimuli.length; i++) { + String s = Arrays.asList(stimuli)+", Index: "+i; + try { + stimuli[i].executeAndCompare(reference, target, s); + verify(reference.getElements()); + } catch (AssertionFailedError cause) { + AssertionFailedError assertionFailedError = new AssertionFailedError(String.valueOf("failed with stimuli " + subListCopy(stimuli, i + 1))); + assertionFailedError.initCause(cause); + throw assertionFailedError; + } + } + } + + private static List subListCopy(Object[] source, int size) { + final Object[] copy = new Object[size]; + System.arraycopy(source, 0, copy, 0, size); + return Arrays.asList(copy); + } + + private interface IteratorOperation { + KEY_OBJECT_TYPE execute(ITERATOR NO_GENERIC_TYPE iterator); + } + + /** + * Apply this method to both iterators and return normally only if both + * produce the same response. + * + * @see Stimulus#executeAndCompare(ListIterator, Iterator) + */ + private void internalExecuteAndCompare(E reference, E target, IteratorOperation method) { + KEY_OBJECT_TYPE referenceReturnValue = INVALID_KEY_VALUE; + PermittedMetaException referenceException = null; + KEY_OBJECT_TYPE targetReturnValue = INVALID_KEY_VALUE; + RuntimeException targetException = null; + + try { + targetReturnValue = method.execute(target); + } catch (RuntimeException e) { + targetException = e; + } + + try { +#ignore + if (method == NEXT_METHOD && targetException == null && knownOrder == KnownOrder.UNKNOWN_ORDER) { +#endignore +#if TYPE_OBJECT + ((MultiExceptionListIterator) reference).promoteToNext((T)targetReturnValue); +#else + ((MultiExceptionListIterator) reference).promoteToNext(targetReturnValue); +#endif + } + + referenceReturnValue = method.execute(reference); + } catch (PermittedMetaException e) { + referenceException = e; + } catch (UnknownElementException e) { + AssertionFailedError assertionFailedError = new AssertionFailedError(String.valueOf(e.getMessage())); + assertionFailedError.initCause(e); + throw assertionFailedError; + } + + if (referenceException == null) { + if (targetException != null) { + AssertionFailedError assertionFailedError = new AssertionFailedError("Target threw exception when reference did not"); + assertionFailedError.initCause(targetException); + throw assertionFailedError; + } +#if TYPE_FLOAT + Assert.assertEquals(Float.floatToIntBits(referenceReturnValue), Float.floatToIntBits(targetReturnValue)); +#else if TYPE_DOUBLE + Assert.assertEquals(Double.doubleToLongBits(referenceReturnValue), Double.doubleToLongBits(targetReturnValue)); +#else + Assert.assertEquals(referenceReturnValue, targetReturnValue); +#endif + return; + } + + if (targetException == null) { + Assert.fail("Target failed to throw " + referenceException+", Stimuli: "+Arrays.asList(stimuli)); + } + + /* + * Reference iterator threw an exception, so we should expect an + * acceptable exception from the target. + */ + referenceException.assertPermitted(targetException); + } + +#ignore + private static final IteratorOperation REMOVE_METHOD = new IteratorOperation() { +#endignore + @Override + public KEY_OBJECT_TYPE execute(ITERATOR NO_GENERIC_TYPE iterator) { + iterator.remove(); + return INVALID_KEY_VALUE; + } + }; + +#ignore + private static final IteratorOperation NEXT_METHOD = new IteratorOperation() { +#endignore + @Override + public KEY_OBJECT_TYPE execute(ITERATOR NO_GENERIC_TYPE iterator) { + return iterator.NEXT(); + } + }; + +#ignore + private static final IteratorOperation PREVIOUS_METHOD = new IteratorOperation() { +#endignore + @Override + public KEY_OBJECT_TYPE execute(ITERATOR NO_GENERIC_TYPE iterator) { + return ((BI_ITERATOR NO_GENERIC_TYPE) iterator).PREVIOUS(); + } + }; + + private final IteratorOperation newAddMethod() { + final KEY_OBJECT_TYPE toInsert = elementsToInsert.NEXT(); + return new IteratorOperation() { + @Override + public KEY_OBJECT_TYPE execute(ITERATOR NO_GENERIC_TYPE iterator) { + @SuppressWarnings("unchecked") + LIST_ITERATOR KEY_SPECIAL_GENERIC_TYPE rawIterator = (LIST_ITERATOR KEY_SPECIAL_GENERIC_TYPE) iterator; + rawIterator.add(toInsert); + return INVALID_KEY_VALUE; + } + }; + } + + private final IteratorOperation newSetMethod() { + final KEY_OBJECT_TYPE toInsert = elementsToInsert.NEXT(); + return new IteratorOperation() { + @Override + public KEY_OBJECT_TYPE execute(ITERATOR NO_GENERIC_TYPE iterator) { + @SuppressWarnings("unchecked") + LIST_ITERATOR KEY_SPECIAL_GENERIC_TYPE li = (LIST_ITERATOR KEY_SPECIAL_GENERIC_TYPE) iterator; + li.set(toInsert); + return INVALID_KEY_VALUE; + } + }; + } + + abstract static class Stimulus { + private final String toString; + + protected Stimulus(String toString) { + this.toString = toString; + } + + abstract void executeAndCompare(LIST_ITERATOR NO_GENERIC_TYPE reference, E target, String stimuli); + + @Override + public String toString() { + return toString; + } + } + + Stimulus hasNext = new Stimulus("hasNext") { + @Override + void executeAndCompare(LIST_ITERATOR NO_GENERIC_TYPE reference, ITERATOR NO_GENERIC_TYPE target, String stimuli) { + Assert.assertEquals("hasNext wasn't matching. Stimuli: "+stimuli, reference.hasNext(), target.hasNext()); + } + }; + Stimulus next = new Stimulus("next") { + @Override + void executeAndCompare(LIST_ITERATOR NO_GENERIC_TYPE reference, ITERATOR NO_GENERIC_TYPE target, String stimuli) { +#ignore + internalExecuteAndCompare(reference, target, NEXT_METHOD); +#endignore + } + }; + Stimulus remove = new Stimulus("remove") { + @Override + void executeAndCompare(LIST_ITERATOR NO_GENERIC_TYPE reference, ITERATOR NO_GENERIC_TYPE target, String stimuli) { +#ignore + internalExecuteAndCompare(reference, target, REMOVE_METHOD); +#endignore + } + }; + Stimulus skip = new Stimulus("skip") { + @Override + void executeAndCompare(LIST_ITERATOR NO_GENERIC_TYPE reference, ITERATOR NO_GENERIC_TYPE target, String stimuli) { + Assert.assertEquals("skip wasn't matching. Stimuli: "+stimuli, reference.skip(1), target.skip(1)); + } + }; + + @SuppressWarnings("unchecked") + List> iteratorStimuli() { + return Arrays.asList(hasNext, skip, next, remove); + } + + Stimulus hasPrevious = new Stimulus("hasPrevious") { + @Override + void executeAndCompare(LIST_ITERATOR NO_GENERIC_TYPE reference, BI_ITERATOR NO_GENERIC_TYPE target, String stimuli) { + Assert.assertEquals("hasPrevious wasn't matching. Stimuli: "+stimuli, reference.hasPrevious(), target.hasPrevious()); + } + }; + Stimulus previous = new Stimulus("previous") { + @Override + void executeAndCompare(LIST_ITERATOR NO_GENERIC_TYPE reference, BI_ITERATOR NO_GENERIC_TYPE target, String stimuli) { +#ignore + internalExecuteAndCompare(reference, target, PREVIOUS_METHOD); +#endignore + } + }; + Stimulus back = new Stimulus("back") { + @Override + void executeAndCompare(LIST_ITERATOR NO_GENERIC_TYPE reference, BI_ITERATOR NO_GENERIC_TYPE target, String stimuli) { + Assert.assertEquals("back wasn't matching. Stimuli: "+stimuli, reference.back(1), target.back(1)); + } + }; + + + List> biIteratorStimuli() { + return Arrays.asList(hasPrevious, back, previous); + } + + Stimulus nextIndex = new Stimulus("nextIndex") { + @Override + void executeAndCompare(LIST_ITERATOR NO_GENERIC_TYPE reference, LIST_ITERATOR NO_GENERIC_TYPE target, String stimuli) { + Assert.assertEquals("nextIndex wasn't matching. Stimuli: "+stimuli, reference.nextIndex(), target.nextIndex()); + } + }; + Stimulus previousIndex = new Stimulus("previousIndex") { + @Override + void executeAndCompare(LIST_ITERATOR NO_GENERIC_TYPE reference, LIST_ITERATOR NO_GENERIC_TYPE target, String stimuli) { + Assert.assertEquals("previous wasn't matching. Stimuli: "+stimuli, reference.previousIndex(), target.previousIndex()); + } + }; + Stimulus add = new Stimulus("add") { + @Override + void executeAndCompare(LIST_ITERATOR NO_GENERIC_TYPE reference, LIST_ITERATOR NO_GENERIC_TYPE target, String stimuli) { + internalExecuteAndCompare(reference, target, newAddMethod()); + } + }; + Stimulus set = new Stimulus("set") { + @Override + void executeAndCompare(LIST_ITERATOR NO_GENERIC_TYPE reference, LIST_ITERATOR NO_GENERIC_TYPE target, String stimuli) { + internalExecuteAndCompare(reference, target, newSetMethod()); + } + }; + + List> listIteratorStimuli() { + return Arrays.asList(nextIndex, previousIndex, add, set); + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/utils/BidirectionalteratorTester.template b/src/builder/resources/speiger/assets/testers/templates/utils/BidirectionalteratorTester.template new file mode 100644 index 00000000..f92bdcda --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/utils/BidirectionalteratorTester.template @@ -0,0 +1,34 @@ +package speiger.src.testers.PACKAGE.utils; + +import java.util.ArrayList; +import java.util.List; + +import com.google.common.collect.testing.Helpers; +import com.google.common.collect.testing.IteratorFeature; + +import speiger.src.collections.PACKAGE.collections.ITERABLE; +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; +import speiger.src.collections.PACKAGE.utils.LISTS; + +@SuppressWarnings("javadoc") +public abstract class BIDIRECTIONAL_ITERATOR_TESTER KEY_GENERIC_TYPE extends ABSTRACT_ITERATOR_TESTER KEY_GENERIC_TYPE { + + public BIDIRECTIONAL_ITERATOR_TESTER(int steps, Iterable features, ITERABLE KEY_GENERIC_TYPE expectedElements, KnownOrder knownOrder) { + super(steps, LISTS.singleton(INVALID_KEY_VALUE), features, expectedElements, knownOrder, 0); + } + + @Override + protected Iterable> getStimulusValues() { + List> list = new ArrayList<>(); + Helpers.addAll(list, iteratorStimuli()); + for(Stimulus iter : biIteratorStimuli()) + { + list.add((Stimulus)iter); + } + return list; + } + + @Override + protected abstract BI_ITERATOR KEY_GENERIC_TYPE newTargetIterator(); +} diff --git a/src/builder/resources/speiger/assets/testers/templates/utils/Helpers.template b/src/builder/resources/speiger/assets/testers/templates/utils/Helpers.template new file mode 100644 index 00000000..8a85ed61 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/utils/Helpers.template @@ -0,0 +1,237 @@ +package speiger.src.testers.PACKAGE.utils; + +#if TYPE_OBJECT +import java.util.Comparator; +import java.util.Objects; +#endif + +import org.junit.Assert; + +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.collections.ITERABLE; +import speiger.src.collections.PACKAGE.collections.ITERATOR; +#if !TYPE_OBJECT +import speiger.src.collections.PACKAGE.functions.COMPARATOR; +#endif +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; +#if !TYPE_BOOLEAN +import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET; +import speiger.src.collections.PACKAGE.sets.SET; +#endif +import speiger.src.collections.PACKAGE.utils.ITERATORS; + +@SuppressWarnings("javadoc") +public class HELPERS { + public static GENERIC_KEY_BRACES boolean equals(KEY_TYPE key, KEY_TYPE value) { + return key == value; + } + + public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE copyToList(ITERABLE KEY_UNKNOWN_GENERIC_TYPE elements) { + LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); + addAll(list, elements); + return list; + } + + public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE copyToList(KEY_TYPE[] elements) { + return copyToList(ARRAY_LIST.wrap(elements)); + } + +#if !TYPE_BOOLEAN + public static GENERIC_KEY_BRACES SET KEY_GENERIC_TYPE copyToSet(ITERABLE KEY_UNKNOWN_GENERIC_TYPE elements) { + SET KEY_GENERIC_TYPE set = new LINKED_HASH_SETBRACES(); + addAll(set, elements); + return set; + } + + public static GENERIC_KEY_BRACES SET KEY_GENERIC_TYPE copyToSet(KEY_TYPE[] elements) { + return copyToSet(ARRAY_LIST.wrap(elements)); + } + +#endif + public static GENERIC_KEY_BRACES boolean addAll(COLLECTION KEY_GENERIC_TYPE addTo, ITERABLE KEY_UNKNOWN_GENERIC_TYPE elementsToAdd) { + boolean modified = false; + for (ITERATOR KEY_UNKNOWN_GENERIC_TYPE iter = elementsToAdd.iterator(); iter.hasNext();) { + modified |= addTo.add(iter.NEXT()); + } + return modified; + } + + public static GENERIC_KEY_BRACES void assertEqualInOrder(ITERABLE KEY_UNKNOWN_GENERIC_TYPE expected, ITERABLE KEY_UNKNOWN_GENERIC_TYPE actual) { + ITERATOR KEY_UNKNOWN_GENERIC_TYPE expectedIter = expected.iterator(); + ITERATOR KEY_UNKNOWN_GENERIC_TYPE actualIter = actual.iterator(); + while (expectedIter.hasNext() && actualIter.hasNext()) { + if (KEY_EQUALS(expectedIter.NEXT(), actualIter.NEXT())) + continue; + Assert.fail("contents were not equal and in the same order: expected = "+expected+", actual = "+actual); + } + if (expectedIter.hasNext() || actualIter.hasNext()) { + Assert.fail("contents were not equal and in the same order: expected = "+expected+", actual = "+actual); + } + } + + public static GENERIC_KEY_BRACES void assertContentsInOrder(ITERABLE KEY_UNKNOWN_GENERIC_TYPE actual, KEY_TYPE... expected) { + assertEqualInOrder(ARRAY_LIST.wrap(expected), actual); + } + + public static GENERIC_KEY_BRACES void assertEqualIgnoringOrder(ITERABLE KEY_UNKNOWN_GENERIC_TYPE expected, ITERABLE KEY_UNKNOWN_GENERIC_TYPE actual) { + LIST KEY_GENERIC_TYPE exp = copyToList(expected); + LIST KEY_GENERIC_TYPE act = copyToList(actual); + String actString = act.toString(); + for (ITERATOR KEY_UNKNOWN_GENERIC_TYPE iter = exp.iterator(); iter.hasNext();) { + KEY_TYPE value = iter.NEXT(); +#if TYPE_OBJECT + if (!act.remove(value)) { +#else + if (!act.REMOVE_KEY(value)) { +#endif + Assert.fail("did not contain expected element "+value+", expected = "+exp+", actual = "+ actString); + } + } + Assert.assertTrue("unexpected elements: "+act, act.isEmpty()); + } + + public static GENERIC_KEY_BRACES void assertContentsAnyOrder(ITERABLE KEY_UNKNOWN_GENERIC_TYPE actual, KEY_TYPE... expected) { + assertEqualIgnoringOrder(ARRAY_LIST.wrap(expected), actual); + } + + public static GENERIC_KEY_BRACES void assertContains(ITERABLE KEY_UNKNOWN_GENERIC_TYPE actual, KEY_TYPE expected) { + boolean contained = false; + if (actual instanceof COLLECTION) { + contained = ((COLLECTION KEY_GENERIC_TYPE) actual).contains(expected); + } else { + for (ITERATOR KEY_UNKNOWN_GENERIC_TYPE iter = actual.iterator(); iter.hasNext();) { + if (KEY_EQUALS(iter.NEXT(), expected)) { + contained = true; + break; + } + } + } + + if (!contained) { + Assert.fail("Not true that "+actual+" contains "+expected); + } + } + + public static GENERIC_KEY_BRACES void assertContainsAllOf(ITERABLE KEY_UNKNOWN_GENERIC_TYPE actual, KEY_TYPE... expected) { + LIST KEY_GENERIC_TYPE expectedList = new ARRAY_LISTBRACES(); + expectedList.addAll(expected); + + for (ITERATOR KEY_UNKNOWN_GENERIC_TYPE iter = actual.iterator(); iter.hasNext();) { +#if TYPE_OBJECT + expectedList.remove(iter.NEXT()); +#else + expectedList.REMOVE_KEY(iter.NEXT()); +#endif + } + if (!expectedList.isEmpty()) { + Assert.fail("Not true that "+actual+" contains all of "+ARRAY_LIST.wrap(expected)); + } + } + + static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE reverse(LIST KEY_GENERIC_TYPE list) { + return new ITERABLE KEY_GENERIC_TYPE() { + @Override + public ITERATOR KEY_GENERIC_TYPE iterator() { + final LIST_ITERATOR KEY_GENERIC_TYPE listIter = list.listIterator(list.size()); + return new ITERATOR KEY_GENERIC_TYPE() { + @Override + public boolean hasNext() { + return listIter.hasPrevious(); + } + + @Override + public KEY_TYPE NEXT() { + return listIter.PREVIOUS(); + } + + @Override + public void remove() { + listIter.remove(); + } + }; + } + }; + } + + static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE cycle(ITERABLE KEY_GENERIC_TYPE iterable) { + return new ITERATOR KEY_GENERIC_TYPE() { + ITERATOR KEY_GENERIC_TYPE iterator = ITERATORS.empty(); + + @Override + public boolean hasNext() { + return true; + } + + @Override + public KEY_TYPE NEXT() { + if (!iterator.hasNext()) { + iterator = iterable.iterator(); + } + return iterator.NEXT(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + static GENERIC_KEY_BRACES KEY_TYPE get(ITERATOR KEY_GENERIC_TYPE iterator, int position) { + for (int i = 0; i < position; i++) { + iterator.NEXT(); + } + return iterator.NEXT(); + } + + public static GENERIC_KEY_BRACES void testComparator(COMPARATOR KEY_GENERIC_TYPE comparator, KEY_TYPE... valuesInExpectedOrder) { + testComparator(comparator, ARRAY_LIST.wrap(valuesInExpectedOrder)); + } + + public static GENERIC_KEY_BRACES void testComparator(COMPARATOR KEY_GENERIC_TYPE comparator, LIST KEY_GENERIC_TYPE valuesInExpectedOrder) { + for (int i = 0; i < valuesInExpectedOrder.size(); i++) { + KEY_TYPE t = valuesInExpectedOrder.GET_KEY(i); + for (int j = 0; j < i; j++) { + KEY_TYPE lesser = valuesInExpectedOrder.GET_KEY(j); + Assert.assertTrue(comparator+".compare("+lesser+", "+t+")", comparator.compare(lesser, t) < 0); + } + Assert.assertEquals(comparator+".compare("+t+", "+t+")", 0, comparator.compare(t, t)); + for (int j = i+1; j < valuesInExpectedOrder.size(); j++) { + KEY_TYPE greater = valuesInExpectedOrder.GET_KEY(j); + Assert.assertTrue(comparator+".compare("+greater+", "+t+")", comparator.compare(greater, t) > 0); + } + } + } + + public static COMPAREABLE_KEY_BRACES void testCompareToAndEquals(LIST KEY_GENERIC_TYPE valuesInExpectedOrder) { + for (int i = 0; i < valuesInExpectedOrder.size(); i++) { + KEY_TYPE t = valuesInExpectedOrder.GET_KEY(i); + + for (int j = 0; j < i; j++) { + KEY_TYPE lesser = valuesInExpectedOrder.GET_KEY(j); + Assert.assertTrue(lesser+".compareTo("+t+')', COMPARE_TO_KEY(lesser, t) < 0); + Assert.assertFalse(lesser == t); + } + + Assert.assertEquals(t+".compareTo("+t+')', 0, COMPARE_TO_KEY(t, t)); + Assert.assertTrue(equals(t, t)); + + for (int j = i+1; j < valuesInExpectedOrder.size(); j++) { + KEY_TYPE greater = valuesInExpectedOrder.GET_KEY(j); + Assert.assertTrue(greater+".compareTo("+t+')', COMPARE_TO_KEY(greater, t) > 0); + Assert.assertFalse(greater == t); + } + } + } + + public static GENERIC_KEY_BRACES COLLECTION KEY_GENERIC_TYPE misleadingSizeCollection(final int delta) { + return new ARRAY_LIST KEY_GENERIC_TYPE() { + @Override + public int size() { + return Math.max(0, super.size()+delta); + } + }; + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/utils/IteratorTester.template b/src/builder/resources/speiger/assets/testers/templates/utils/IteratorTester.template new file mode 100644 index 00000000..5a3d36d9 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/utils/IteratorTester.template @@ -0,0 +1,20 @@ +package speiger.src.testers.PACKAGE.utils; + +import com.google.common.collect.testing.IteratorFeature; + +import speiger.src.collections.PACKAGE.collections.ITERABLE; +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.collections.PACKAGE.utils.LISTS; + +@SuppressWarnings("javadoc") +public abstract class ITERATOR_TESTER KEY_GENERIC_TYPE extends ABSTRACT_ITERATOR_TESTER KEY_GENERIC_TYPE +{ + public ITERATOR_TESTER(int steps, Iterable features, ITERABLE KEY_GENERIC_TYPE expectedElements, KnownOrder knownOrder) { + super(steps, LISTS.singleton(INVALID_KEY_VALUE), features, expectedElements, knownOrder, 0); + } + + @Override + protected Iterable> getStimulusValues() { + return iteratorStimuli(); + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/testers/templates/utils/ListIteratorTester.template b/src/builder/resources/speiger/assets/testers/templates/utils/ListIteratorTester.template new file mode 100644 index 00000000..1cf2fb73 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/utils/ListIteratorTester.template @@ -0,0 +1,36 @@ +package speiger.src.testers.PACKAGE.utils; + +import java.util.ArrayList; +import java.util.List; + +import com.google.common.collect.testing.Helpers; +import com.google.common.collect.testing.IteratorFeature; + +import speiger.src.collections.PACKAGE.collections.ITERABLE; +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR; + +@SuppressWarnings("javadoc") +public abstract class LIST_ITERATOR_TESTER KEY_GENERIC_TYPE extends ABSTRACT_ITERATOR_TESTER KEY_GENERIC_TYPE { + public LIST_ITERATOR_TESTER(int steps, ITERABLE KEY_GENERIC_TYPE elementsToInsertIterable, Iterable features, ITERABLE KEY_GENERIC_TYPE expectedElements, int startIndex) { + super(steps, elementsToInsertIterable, features, expectedElements, KnownOrder.KNOWN_ORDER, startIndex); + } + + @Override + protected Iterable> getStimulusValues() { + List> list = new ArrayList<>(); + Helpers.addAll(list, iteratorStimuli()); + for(Stimulus iter : biIteratorStimuli()) + { + list.add((Stimulus)iter); + } + for(Stimulus iter : listIteratorStimuli()) + { + list.add((Stimulus)iter); + } + return list; + } + + @Override + protected abstract LIST_ITERATOR KEY_GENERIC_TYPE newTargetIterator(); +} diff --git a/src/builder/resources/speiger/assets/testers/templates/utils/MinimalCollection.template b/src/builder/resources/speiger/assets/testers/templates/utils/MinimalCollection.template new file mode 100644 index 00000000..77a554ac --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/utils/MinimalCollection.template @@ -0,0 +1,95 @@ +package speiger.src.testers.PACKAGE.utils; + +import java.util.Collection; +#if TYPE_OBJECT +import java.util.function.Consumer; +#endif + +import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION; +import speiger.src.collections.PACKAGE.collections.COLLECTION; +import speiger.src.collections.PACKAGE.collections.ITERATOR; +#if !TYPE_OBJECT +import speiger.src.collections.PACKAGE.functions.CONSUMER; +#else +import speiger.src.collections.objects.utils.ObjectArrays; +#endif +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; + +@SuppressWarnings("javadoc") +public class MINIMAL_COLLECTION KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE { + + private final KEY_TYPE[] contents; + + protected MINIMAL_COLLECTION(KEY_TYPE[] contents) { + this.contents = contents; + } + + public static GENERIC_KEY_BRACES MINIMAL_COLLECTION KEY_GENERIC_TYPE of(KEY_TYPE... contents) { + return new MINIMAL_COLLECTIONBRACES(contents); + } + + @Override + public boolean add(KEY_TYPE o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(COLLECTION KEY_GENERIC_TYPE c, CONSUMER KEY_GENERIC_TYPE r) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public ITERATOR KEY_GENERIC_TYPE iterator() { + return ARRAY_LIST.wrap(contents).iterator(); + } + +#if !TYPE_OBJECT + @Override + public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) { + if(a.length < contents.length) a = new KEY_TYPE[contents.length]; + System.arraycopy(contents, 0, a, 0, contents.length); + if (a.length > contents.length) a[contents.length] = EMPTY_KEY_VALUE; + return a; + } + +#else + @Override + public E[] toArray(E[] a) { + if(a == null) a = (E[])new Object[contents.length]; + else if(a.length < contents.length) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), contents.length); + System.arraycopy(contents, 0, a, 0, contents.length); + if (a.length > contents.length) a[contents.length] = null; + return a; + } + +#endif + @Override + public int size() { + return contents.length; + } +} diff --git a/src/builder/resources/speiger/assets/testers/templates/utils/MinimalSet.template b/src/builder/resources/speiger/assets/testers/templates/utils/MinimalSet.template new file mode 100644 index 00000000..8213df45 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/utils/MinimalSet.template @@ -0,0 +1,84 @@ +package speiger.src.testers.PACKAGE.utils; + +#if TYPE_OBJECT +import java.util.Objects; +#endif + +import speiger.src.collections.PACKAGE.collections.ITERABLE; +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; +import speiger.src.collections.PACKAGE.sets.SET; + +@SuppressWarnings("javadoc") +public class MINIMAL_SET KEY_GENERIC_TYPE extends MINIMAL_COLLECTION KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE { + public static GENERIC_KEY_BRACES MINIMAL_SET KEY_GENERIC_TYPE of(KEY_TYPE...array) { + return MINIMAL_SET.of(ARRAY_LIST.wrap(array)); + } + + public static GENERIC_KEY_BRACES MINIMAL_SET KEY_GENERIC_TYPE of(ITERABLE KEY_GENERIC_TYPE iterable) + { + LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(); + for(ITERATOR KEY_GENERIC_TYPE iter = iterable.iterator();iter.hasNext();) + { + KEY_TYPE key = iter.NEXT(); + if(list.contains(key)) continue; + list.add(key); + } + return new MINIMAL_SETBRACES(list.TO_ARRAY(NEW_KEY_ARRAY(list.size()))); + } + + protected MINIMAL_SET(KEY_TYPE[] contents) { + super(contents); + } + + @Override + public SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); } + +#if TYPE_OBJECT + @Override + public T addOrGet(T o) { throw new UnsupportedOperationException(); } + +#endif + @Override + public boolean equals(Object object) { + if (object instanceof SET) { + SET KEY_GENERIC_TYPE that = (SET KEY_GENERIC_TYPE) object; + return (size() == that.size()) && this.containsAll(that); + } + return false; + } + + @Override + public int hashCode() { + int hashCodeSum = 0; + for (ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { + hashCodeSum += KEY_TO_HASH(iter.NEXT()); + } + return hashCodeSum; + } + +#if TYPE_OBJECT + @Override + public boolean remove(Object o) { + for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { + if(KEY_EQUALS(iter.NEXT(), o)) { + iter.remove(); + return true; + } + } + return false; + } +#else + @Override + public boolean remove(KEY_TYPE o) { + for(ITERATOR KEY_GENERIC_TYPE iter = iterator();iter.hasNext();) { + if(KEY_EQUALS(iter.NEXT(), o)) { + iter.remove(); + return true; + } + } + return false; + } +#endif +} diff --git a/src/builder/resources/speiger/assets/testers/templates/utils/Samples.template b/src/builder/resources/speiger/assets/testers/templates/utils/Samples.template new file mode 100644 index 00000000..c557db40 --- /dev/null +++ b/src/builder/resources/speiger/assets/testers/templates/utils/Samples.template @@ -0,0 +1,73 @@ +package speiger.src.testers.PACKAGE.utils; + +import com.google.common.collect.testing.SampleElements; + +import speiger.src.collections.PACKAGE.collections.ITERABLE; +import speiger.src.collections.PACKAGE.collections.ITERATOR; +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; + +@SuppressWarnings("javadoc") +public class SAMPLE_ELEMENTS KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE +{ + private final KEY_TYPE e0; + private final KEY_TYPE e1; + private final KEY_TYPE e2; + private final KEY_TYPE e3; + private final KEY_TYPE e4; + + public SAMPLE_ELEMENTS(SampleElements samples) + { + this(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4()); + } + + public SAMPLE_ELEMENTS(KEY_TYPE e0, KEY_TYPE e1, KEY_TYPE e2, KEY_TYPE e3, KEY_TYPE e4) + { + this.e0 = e0; + this.e1 = e1; + this.e2 = e2; + this.e3 = e3; + this.e4 = e4; + } + + public SampleElements toSamples() + { + return new SampleElements<>(e0(), e1(), e2(), e3(), e4()); + } + + @Override + public ITERATOR KEY_GENERIC_TYPE iterator() + { + return asList().iterator(); + } + + public LIST KEY_GENERIC_TYPE asList() + { + return ARRAY_LIST.wrap(e0(), e1(), e2(), e3(), e4()); + } + + public KEY_TYPE e0() + { + return e0; + } + + public KEY_TYPE e1() + { + return e1; + } + + public KEY_TYPE e2() + { + return e2; + } + + public KEY_TYPE e3() + { + return e3; + } + + public KEY_TYPE e4() + { + return e4; + } +} diff --git a/src/builder/resources/speiger/assets/tests/templates/collections/ListTests.template b/src/builder/resources/speiger/assets/tests/templates/collections/ListTests.template new file mode 100644 index 00000000..850982ef --- /dev/null +++ b/src/builder/resources/speiger/assets/tests/templates/collections/ListTests.template @@ -0,0 +1,358 @@ +package speiger.src.tests.PACKAGE.collections; + +import java.util.Arrays; +import java.util.Collection; +import java.util.function.Function; +#if TYPE_BOOLEAN +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +#endif + +import com.google.common.collect.testing.features.CollectionSize; +#if !TYPE_BOOLEAN +import com.google.common.collect.testing.features.CollectionFeature; +#endif +import com.google.common.collect.testing.features.ListFeature; +import com.google.common.collect.testing.features.Feature; + +#if TYPE_BOOLEAN +import com.google.common.collect.testing.testers.CollectionAddAllTester; +import com.google.common.collect.testing.testers.CollectionAddTester; +import com.google.common.collect.testing.testers.CollectionContainsAllTester; +import com.google.common.collect.testing.testers.CollectionContainsTester; +import com.google.common.collect.testing.testers.CollectionIteratorTester; +import com.google.common.collect.testing.testers.CollectionRemoveAllTester; +import com.google.common.collect.testing.testers.CollectionRemoveTester; +import com.google.common.collect.testing.testers.CollectionRetainAllTester; +import com.google.common.collect.testing.testers.ListAddAllAtIndexTester; +import com.google.common.collect.testing.testers.ListAddAtIndexTester; +import com.google.common.collect.testing.testers.ListEqualsTester; +import com.google.common.collect.testing.testers.ListIndexOfTester; +import com.google.common.collect.testing.testers.ListLastIndexOfTester; +import com.google.common.collect.testing.testers.ListRetainAllTester; +import com.google.common.collect.testing.testers.ListSubListTester; +#else +import com.google.common.collect.testing.testers.ListSubListTester; +#endif + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import speiger.src.collections.PACKAGE.lists.IMMUTABLE_LIST; +import speiger.src.collections.PACKAGE.lists.ARRAY_LIST; +import speiger.src.collections.PACKAGE.lists.LINKED_LIST; +import speiger.src.collections.PACKAGE.lists.COPY_ON_WRITE_LIST; +import speiger.src.collections.PACKAGE.lists.LIST; + +#if !TYPE_BOOLEAN +import speiger.src.collections.PACKAGE.utils.LISTS; +#endif +import speiger.src.testers.PACKAGE.builder.LIST_TEST_BUILDER; +import speiger.src.testers.PACKAGE.impl.COLLECTION_CONSTRUCTOR_TESTS; +import speiger.src.testers.PACKAGE.impl.SIMPLE_TEST_GENERATOR; +#if TYPE_OBJECT +import speiger.src.testers.PACKAGE.generators.TEST_LIST_GENERATOR; +#endif +import speiger.src.testers.utils.SpecialFeature; +import speiger.src.testers.utils.TestUtils; +#if TYPE_BOOLEAN +import speiger.src.testers.booleans.tests.collection.BooleanCollectionAddAllArrayTester; +import speiger.src.testers.booleans.tests.collection.BooleanCollectionAddAllTester; +import speiger.src.testers.booleans.tests.collection.BooleanCollectionAddTester; +import speiger.src.testers.booleans.tests.collection.BooleanCollectionContainsAllTester; +import speiger.src.testers.booleans.tests.collection.BooleanCollectionContainsTester; +import speiger.src.testers.booleans.tests.collection.BooleanCollectionIteratorTester; +import speiger.src.testers.booleans.tests.collection.BooleanCollectionRemoveAllTester; +import speiger.src.testers.booleans.tests.collection.BooleanCollectionRetainAllTester; +import speiger.src.testers.booleans.tests.list.BooleanListAddAllArrayAtIndexTester; +import speiger.src.testers.booleans.tests.list.BooleanListAddAllAtIndexTester; +import speiger.src.testers.booleans.tests.list.BooleanListAddAtIndexTester; +import speiger.src.testers.booleans.tests.list.BooleanListEqualsTester; +import speiger.src.testers.booleans.tests.list.BooleanListExtractElementsTester; +import speiger.src.testers.booleans.tests.list.BooleanListIndexOfTester; +import speiger.src.testers.booleans.tests.list.BooleanListLastIndexOfTester; +import speiger.src.testers.booleans.tests.list.BooleanListRemoveElementsTester; +import speiger.src.testers.booleans.tests.list.BooleanListRetainAllTester; +import speiger.src.testers.booleans.tests.list.BooleanListSubListTester; +#else +import speiger.src.testers.PACKAGE.tests.list.FILE_KEY_TYPEListSubListTester; +#endif + + +@SuppressWarnings("javadoc") +public class LIST_TESTS extends TestCase +{ + public static Test suite() { + TestSuite suite = new TestSuite("LISTS"); + suite(suite); + constructorSuite(suite); + System.out.println("Generated ["+suite.countTestCases()+"] Tests"); + return suite; + } + + public static void constructorSuite(TestSuite suite) { + TestSuite constructors = new TestSuite("Constructors"); + constructors.addTest(new TestSuite(COLLECTION_CONSTRUCTOR_TESTS.ArrayList.class)); + constructors.addTest(new TestSuite(COLLECTION_CONSTRUCTOR_TESTS.LinkedList.class)); + constructors.addTest(new TestSuite(COLLECTION_CONSTRUCTOR_TESTS.CopyOnWriteArrayList.class)); + constructors.addTest(new TestSuite(COLLECTION_CONSTRUCTOR_TESTS.ImmutableList.class)); + suite.addTest(constructors); + } + +#if TYPE_OBJECT + public static void suite(TestSuite suite) { + suite.addTest(listSuite("ARRAY_LIST", T -> new ARRAY_LISTBRACES(T), getFeatures(), -1)); + suite.addTest(listSuite("LINKED_LIST", T -> new LINKED_LISTBRACES(T), getFeatures(), -1)); + suite.addTest(copyOnWritelistSuite("COPY_ON_WRITE_LIST", T -> new COPY_ON_WRITE_LISTBRACES(T), getCopyOnWriteFeatures(), -1)); + suite.addTest(listSuite("IMMUTABLE_LIST", T -> new IMMUTABLE_LISTBRACES(T), getImmutableFeatures(), -1)); + suite.addTest(listSuite("Synchronized ARRAY_LIST", T -> new ARRAY_LISTBRACES(T).synchronize(), getFeatures(), -1)); + suite.addTest(listSuite("Unmodifiable ARRAY_LIST", T -> new ARRAY_LISTBRACES(T).unmodifiable(), getImmutableFeatures(), -1)); + suite.addTest(emptylistSuite("Empty LIST", T -> LISTS.empty(), getImmutableWrapperFeatures(), 0)); + suite.addTest(listSuite("Singleton LIST", T -> LISTS.singleton(T[0]), getImmutableWrapperFeatures(), 1)); + } + + private static Test listSuite(String name, Function factory, Collection> features, int size) { + return LIST_TEST_BUILDER.using((TEST_LIST_GENERATOR KEY_STRING_GENERIC_TYPE)new SIMPLE_TEST_GENERATOR.Lists KEY_STRING_GENERIC_TYPE(factory).setElements(createStrings())).setPrefixes(createPrefixes()).setSuffixes(createSuffixes()).named(name).withFeatures(getSizes(size)).withFeatures(features).createTestSuite(); + } + + private static Test copyOnWritelistSuite(String name, Function factory, Collection> features, int size) { + return LIST_TEST_BUILDER.using((TEST_LIST_GENERATOR KEY_STRING_GENERIC_TYPE)new SIMPLE_TEST_GENERATOR.Lists KEY_STRING_GENERIC_TYPE(factory).setElements(createStrings())).setPrefixes(createPrefixes()).setSuffixes(createSuffixes()).named(name).withFeatures(getSizes(size)).withFeatures(features).createTestSuite(); + } + + private static Test emptylistSuite(String name, Function factory, Collection> features, int size) { + return LIST_TEST_BUILDER.using((TEST_LIST_GENERATOR KEY_STRING_GENERIC_TYPE)new SIMPLE_TEST_GENERATOR.Lists KEY_STRING_GENERIC_TYPE(factory).setElements(createStrings())).setPrefixes(createPrefixes()).setSuffixes(createSuffixes()).named(name).withFeatures(getSizes(size)).suppressing(TestUtils.getSurpession(ListSubListTester.class)).suppressing(TestUtils.getSurpession(FILE_KEY_TYPEListSubListTester.class)).withFeatures(features).createTestSuite(); + } + + private static String[] createStrings() { + return new String[]{"a", "b", "c", "d", "e"}; + } + + private static String[] createPrefixes() { + return new String[]{"^", "_", "`"}; + } + + private static String[] createSuffixes() { + return new String[]{"f", "g", "h"}; + } + +#else if !TYPE_BOOLEAN + public static void suite(TestSuite suite) { + suite.addTest(listSuite("ARRAY_LIST", ARRAY_LIST::new, getFeatures(), -1)); + suite.addTest(listSuite("LINKED_LIST", LINKED_LIST::new, getFeatures(), -1)); + suite.addTest(copyOnWritelistSuite("COPY_ON_WRITE_LIST", COPY_ON_WRITE_LIST::new, getCopyOnWriteFeatures(), -1)); + suite.addTest(listSuite("IMMUTABLE_LIST", IMMUTABLE_LIST::new, getImmutableFeatures(), -1)); + suite.addTest(listSuite("Synchronized ARRAY_LIST", T -> new ARRAY_LISTBRACES(T).synchronize(), getFeatures(), -1)); + suite.addTest(listSuite("Unmodifiable ARRAY_LIST", T -> new ARRAY_LISTBRACES(T).unmodifiable(), getImmutableFeatures(), -1)); + suite.addTest(emptylistSuite("Empty LIST", T -> LISTS.empty(), getImmutableWrapperFeatures(), 0)); + suite.addTest(listSuite("Singleton LIST", T -> LISTS.singleton(T[0]), getImmutableWrapperFeatures(), 1)); + } + + private static Test listSuite(String name, Function factory, Collection> features, int size) { + return LIST_TEST_BUILDER.using(new SIMPLE_TEST_GENERATOR.ListsBRACES(factory)).named(name).withFeatures(getSizes(size)).withFeatures(features).createTestSuite(); + } + + private static Test copyOnWritelistSuite(String name, Function factory, Collection> features, int size) { + return LIST_TEST_BUILDER.using(new SIMPLE_TEST_GENERATOR.Lists KEY_STRING_GENERIC_TYPE(factory)).named(name).withFeatures(getSizes(size)).withFeatures(features).createTestSuite(); + } + + private static Test emptylistSuite(String name, Function factory, Collection> features, int size) { + return LIST_TEST_BUILDER.using(new SIMPLE_TEST_GENERATOR.ListsBRACES(factory)).named(name).withFeatures(getSizes(size)).suppressing(TestUtils.getSurpession(ListSubListTester.class)).suppressing(TestUtils.getSurpession(FILE_KEY_TYPEListSubListTester.class)).withFeatures(features).createTestSuite(); + } + +#else + public static void suite(TestSuite suite) { + listSuite(suite, "ARRAY_LIST", ARRAY_LIST::new, getFeatures(), false, -1); + listSuite(suite, "LINKED_LIST", LINKED_LIST::new, getFeatures(), false, -1); + copyOnWritelistSuite(suite, "COPY_ON_WRITE_LIST", COPY_ON_WRITE_LIST::new, getCopyOnWriteFeatures(), false, -1); + listSuite(suite, "IMMUTABLE_LIST", IMMUTABLE_LIST::new, getImmutableFeatures(), true, -1); + listSuite(suite, "Synchronized ARRAY_LIST", T -> new ARRAY_LISTBRACES(T).synchronize(), getFeatures(), false, -1); + listSuite(suite, "Unmodifiable ARRAY_LIST", T -> new ARRAY_LISTBRACES(T).unmodifiable(), getImmutableFeatures(), true, -1); + } + + private static void copyOnWritelistSuite(TestSuite suite, String name, Function factory, Collection> features, boolean immutable, int size) { + TestSuite data = new TestSuite(name); + Collection sizes = getSizes(size); +#ignore + if(sizes.contains(CollectionSize.ZERO) || sizes.contains(CollectionSize.ANY)) { +#endignore + data.addTest(LIST_TEST_BUILDER.using(new SIMPLE_TEST_GENERATOR.ListsBRACES(factory)) +#ignore + .named(name+" [collection size: zero]").withFeatures(CollectionSize.ZERO).withFeatures(features).suppressing(getSurpression(CollectionSize.ZERO, immutable)).createTestSuite()); +#endignore + } +#ignore + if(sizes.contains(CollectionSize.ONE) || sizes.contains(CollectionSize.ANY)) { +#endignore + data.addTest(LIST_TEST_BUILDER.using(new SIMPLE_TEST_GENERATOR.ListsBRACES(factory)) +#ignore + .named(name+" [collection size: one]").withFeatures(CollectionSize.ONE).withFeatures(features).suppressing(getSurpression(CollectionSize.ONE, immutable)).createTestSuite()); +#endignore + } +#ignore + if(sizes.contains(CollectionSize.SEVERAL) || sizes.contains(CollectionSize.ANY)) { +#endignore + data.addTest(LIST_TEST_BUILDER.using(new SIMPLE_TEST_GENERATOR.ListsBRACES(factory)) +#ignore + .named(name+" [collection size: several]").withFeatures(CollectionSize.SEVERAL).withFeatures(features).suppressing(getSurpression(CollectionSize.SEVERAL, immutable)).createTestSuite()); +#endignore + } + suite.addTest(data); + } + + private static void listSuite(TestSuite suite, String name, Function factory, Collection> features, boolean immutable, int size) { + TestSuite data = new TestSuite(name); + Collection sizes = getSizes(size); +#ignore + if(sizes.contains(CollectionSize.ZERO) || sizes.contains(CollectionSize.ANY)) { +#endignore + data.addTest(LIST_TEST_BUILDER.using(new SIMPLE_TEST_GENERATOR.ListsBRACES(factory)) +#ignore + .named(name+" [collection size: zero]").withFeatures(CollectionSize.ZERO).withFeatures(features).suppressing(getSurpression(CollectionSize.ZERO, immutable)).createTestSuite()); +#endignore + } +#ignore + if(sizes.contains(CollectionSize.ONE) || sizes.contains(CollectionSize.ANY)) { +#endignore + data.addTest(LIST_TEST_BUILDER.using(new SIMPLE_TEST_GENERATOR.ListsBRACES(factory)) +#ignore + .named(name+" [collection size: one]").withFeatures(CollectionSize.ONE).withFeatures(features).suppressing(getSurpression(CollectionSize.ONE, immutable)).createTestSuite()); +#endignore + } +#ignore + if(sizes.contains(CollectionSize.SEVERAL) || sizes.contains(CollectionSize.ANY)) { +#endignore + data.addTest(LIST_TEST_BUILDER.using(new SIMPLE_TEST_GENERATOR.ListsBRACES(factory)).named(name) +#ignore + .named(name+" [collection size: several]").withFeatures(CollectionSize.SEVERAL).withFeatures(features).suppressing(getSurpression(CollectionSize.SEVERAL, immutable)).createTestSuite()); +#endignore + } + suite.addTest(data); + } + + private static List getSurpression(CollectionSize size, boolean immutable) { + List list = new ArrayList<>(); + if(size == CollectionSize.ONE) { + TestUtils.getSurpession(list, CollectionRetainAllTester.class, "testRetainAll_disjointPreviouslyNonEmpty"); + if(immutable) { + TestUtils.getSurpession(list, CollectionAddAllTester.class, "testAddAll_unsupportedNonePresent"); + TestUtils.getSurpession(list, BooleanCollectionAddAllTester.class, "testAddAll_unsupportedNonePresent"); + TestUtils.getSurpession(list, BooleanCollectionAddAllArrayTester.class, "testAddAllArray_unsupportedNonePresent"); + } + } + else { + TestUtils.getSurpession(list, CollectionContainsAllTester.class, "testContainsAll_disjoint", "testContainsAll_partialOverlap"); + TestUtils.getSurpession(list, CollectionContainsTester.class, "testContains_no"); + TestUtils.getSurpession(list, CollectionIteratorTester.class, "testIterator_removeAffectsBackingCollection"); + TestUtils.getSurpession(list, CollectionRemoveAllTester.class, "testRemoveAll_nonePresent"); + TestUtils.getSurpession(list, CollectionRemoveTester.class, "testRemove_present", "testRemove_notPresent"); + TestUtils.getSurpession(list, CollectionRetainAllTester.class, "testRetainAll_disjointPreviouslyNonEmpty", "testRetainAll_containsDuplicatesSizeSeveral", "testRetainAll_partialOverlap"); + TestUtils.getSurpession(list, BooleanCollectionContainsAllTester.class, "testContainsAll_disjoint", "testContainsAll_partialOverlap"); + TestUtils.getSurpession(list, BooleanCollectionContainsTester.class, "testContains_no"); + TestUtils.getSurpession(list, BooleanCollectionIteratorTester.class, "testIterator_removeAffectsBackingCollection"); + TestUtils.getSurpession(list, BooleanCollectionRemoveAllTester.class, "testRemoveAll_nonePresentFetchRemoved", "testRemoveAll_someFetchRemovedElements", "testRemoveAll_nonePresent"); + TestUtils.getSurpession(list, BooleanCollectionRetainAllTester.class, "testRetainAllExtra_containsDuplicatesSizeSeveral", "testRetainAllExtra_partialOverlap", "testRetainAll_containsDuplicatesSizeSeveral", "testRetainAll_partialOverlap"); + TestUtils.getSurpession(list, ListAddAllAtIndexTester.class, "testAddAllAtIndex_negative", "testAddAllAtIndex_tooLarge"); + TestUtils.getSurpession(list, ListAddAtIndexTester.class, "testAddAtIndex_tooLarge", "testAddAtIndex_negative"); + TestUtils.getSurpession(list, ListEqualsTester.class, "testEquals_otherListWithDifferentElements"); + TestUtils.getSurpession(list, ListIndexOfTester.class, "testFind_no"); + TestUtils.getSurpession(list, ListLastIndexOfTester.class, "testLastIndexOf_duplicate", "testFind_no", "testFind_yes"); + TestUtils.getSurpession(list, ListRetainAllTester.class, "testRetainAll_duplicatesRemoved", "testRetainAll_countIgnored"); + TestUtils.getSurpession(list, ListSubListTester.class, "testSubList_lastIndexOf", "testSubList_contains", "testSubList_indexOf"); + TestUtils.getSurpession(list, BooleanListAddAllAtIndexTester.class, "testAddAllAtIndex_negative", "testAddAllAtIndex_tooLarge"); + TestUtils.getSurpession(list, BooleanListAddAllArrayAtIndexTester.class, "testAddAllArrayAtIndex_tooLarge", "testAddAllArrayAtIndex_negative"); + TestUtils.getSurpession(list, BooleanListAddAtIndexTester.class, "testAddAtIndex_tooLarge", "testAddAtIndex_negative"); + TestUtils.getSurpession(list, BooleanListEqualsTester.class, "testEquals_otherListWithDifferentElements"); + TestUtils.getSurpession(list, BooleanListExtractElementsTester.class, "testRemoveElements"); + TestUtils.getSurpession(list, BooleanListIndexOfTester.class, "testFind_no"); + TestUtils.getSurpession(list, BooleanListLastIndexOfTester.class, "testLastIndexOf_duplicate", "testFind_no", "testFind_yes"); + TestUtils.getSurpession(list, BooleanListRemoveElementsTester.class, "testRemoveElements"); + TestUtils.getSurpession(list, BooleanListRetainAllTester.class, "testRetainAll_duplicatesRemoved", "testRetainAll_countIgnored"); + TestUtils.getSurpession(list, BooleanListSubListTester.class, "testSubList_lastIndexOf", "testSubList_contains", "testSubList_indexOf"); + if(immutable) { + TestUtils.getSurpession(list, CollectionAddAllTester.class, "testAddAll_unsupportedNonePresent"); + TestUtils.getSurpession(list, CollectionAddTester.class, "testAdd_unsupportedNotPresent"); + TestUtils.getSurpession(list, CollectionRemoveTester.class, "testRemove_unsupportedNotPresent"); + TestUtils.getSurpession(list, BooleanCollectionAddAllTester.class, "testAddAll_unsupportedNonePresent"); + TestUtils.getSurpession(list, BooleanCollectionAddAllArrayTester.class, "testAddAllArray_unsupportedNonePresent"); + TestUtils.getSurpession(list, BooleanCollectionAddTester.class, "testAdd_unsupportedNotPresent"); + TestUtils.getSurpession(list, ListAddAllAtIndexTester.class, "testAddAllAtIndex_unsupportedSomePresent"); + TestUtils.getSurpession(list, ListAddAtIndexTester.class, "testAddAtIndex_unsupportedNotPresent"); + TestUtils.getSurpession(list, BooleanListAddAllAtIndexTester.class, "testAddAllAtIndex_unsupportedSomePresent"); + TestUtils.getSurpession(list, BooleanListAddAllArrayAtIndexTester.class, "testAddAllArrayAtIndex_unsupportedSomePresent"); + TestUtils.getSurpession(list, BooleanListAddAtIndexTester.class, "testAddAtIndex_unsupportedNotPresent"); + } + } + return list; + } + +#endif +#ignore + private static Collection getSizes(int size) { + switch(size) { + case 0: return Arrays.asList(CollectionSize.ZERO); + case 1: return Arrays.asList(CollectionSize.ONE); + case 2: return Arrays.asList(CollectionSize.ZERO, CollectionSize.ONE); + case 3: return Arrays.asList(CollectionSize.SEVERAL); + case 4: return Arrays.asList(CollectionSize.ZERO, CollectionSize.SEVERAL); + case 5: return Arrays.asList(CollectionSize.ONE, CollectionSize.SEVERAL); + default: return Arrays.asList(CollectionSize.ANY); + } + } + +#endignore + + private static Collection> getCopyOnWriteFeatures() { + +#if TYPE_OBJECT +#ignore + return Arrays.asList(ListFeature.SUPPORTS_SET, ListFeature.SUPPORTS_ADD_WITH_INDEX, ListFeature.SUPPORTS_REMOVE_WITH_INDEX, SpecialFeature.COPYING, CollectionFeature.ALLOWS_NULL_VALUES); +#endignore +#else +#ignore + return Arrays.asList(ListFeature.SUPPORTS_SET, ListFeature.SUPPORTS_ADD_WITH_INDEX, ListFeature.SUPPORTS_REMOVE_WITH_INDEX, SpecialFeature.COPYING); +#endignore +#endif + } + + private static Collection> getImmutableFeatures() { + +#if TYPE_OBJECT +#ignore + return Arrays.asList(SpecialFeature.COPYING, CollectionFeature.ALLOWS_NULL_VALUES); +#endignore +#else +#ignore + return Arrays.asList(SpecialFeature.COPYING); +#endignore +#endif + } + +#if !TYPE_BOOLEAN + private static Collection> getImmutableWrapperFeatures() { + +#if TYPE_OBJECT +#ignore + return Arrays.asList(SpecialFeature.COPYING, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.SUBSET_VIEW); +#endignore +#else +#ignore + return Arrays.asList(SpecialFeature.COPYING, CollectionFeature.SUBSET_VIEW); +#endignore +#endif + } + +#endif + private static Collection> getFeatures() { + +#if TYPE_OBJECT +#ignore + return Arrays.asList(ListFeature.GENERAL_PURPOSE, CollectionFeature.ALLOWS_NULL_VALUES, SpecialFeature.COPYING, SpecialFeature.ITERATOR_MODIFIABLE); +#endignore +#else +#ignore + return Arrays.asList(ListFeature.GENERAL_PURPOSE, SpecialFeature.COPYING, SpecialFeature.ITERATOR_MODIFIABLE); +#endignore +#endif + } +} \ No newline at end of file diff --git a/src/builder/resources/speiger/assets/tests/templates/collections/QueueTests.template b/src/builder/resources/speiger/assets/tests/templates/collections/QueueTests.template new file mode 100644 index 00000000..f9d0f4f5 --- /dev/null +++ b/src/builder/resources/speiger/assets/tests/templates/collections/QueueTests.template @@ -0,0 +1,89 @@ +package speiger.src.tests.PACKAGE.collections; + +import java.util.Arrays; +import java.util.Collection; +#if TYPE_OBJECT +import java.util.Comparator; +#endif +import java.util.function.Function; + +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.Feature; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import speiger.src.collections.PACKAGE.lists.LINKED_LIST; +import speiger.src.collections.PACKAGE.queues.ARRAY_FIFO_QUEUE; +import speiger.src.collections.PACKAGE.queues.ARRAY_PRIORITY_QUEUE; +import speiger.src.collections.PACKAGE.queues.HEAP_PRIORITY_QUEUE; +import speiger.src.collections.PACKAGE.queues.PRIORITY_QUEUE; +import speiger.src.testers.PACKAGE.builder.DEQUEUE_TEST_BUILDER; +import speiger.src.testers.PACKAGE.builder.QUEUE_TEST_BUILDER; +import speiger.src.testers.PACKAGE.impl.SIMPLE_QUEUE_TEST_GENERATOR; +import speiger.src.testers.utils.SpecialFeature; + +@SuppressWarnings("javadoc") +public class QUEUE_TESTS extends TestCase +{ + public static Test suite() { + TestSuite suite = new TestSuite("PRIORITY_QUEUES"); + suite(suite); + System.out.println("Generated ["+suite.countTestCases()+"] Tests"); + return suite; + } + + public static void suite(TestSuite suite) { + suite.addTest(dequeueSuite("ARRAY_FIFO_QUEUE", T -> new ARRAY_FIFO_QUEUEBRACES(T), getFeatures(), -1)); + suite.addTest(queueSuite("HEAP_PRIORITY_QUEUE", T -> new HEAP_PRIORITY_QUEUEBRACES(T), getFeatures(), -1)); +#if TYPE_OBJECT + suite.addTest(queueSuite("HEAP_PRIORITY_QUEUEComparator", T -> new HEAP_PRIORITY_QUEUEBRACES(T, Comparator.naturalOrder()), getFeatures(), -1)); + suite.addTest(queueSuite("ARRAY_PRIORITY_QUEUEComparator", T -> new ARRAY_PRIORITY_QUEUEBRACES(T, Comparator.naturalOrder()), getFeatures(), -1)); +#else + suite.addTest(queueSuite("HEAP_PRIORITY_QUEUEComparator", T -> new HEAP_PRIORITY_QUEUEBRACES(T, CLASS_TYPE::compare), getFeatures(), -1)); + suite.addTest(queueSuite("ARRAY_PRIORITY_QUEUEComparator", T -> new ARRAY_PRIORITY_QUEUEBRACES(T, CLASS_TYPE::compare), getFeatures(), -1)); +#endif + suite.addTest(queueSuite("ARRAY_PRIORITY_QUEUE", T -> new ARRAY_PRIORITY_QUEUEBRACES(T), getFeatures(), -1)); + suite.addTest(dequeueSuite("LINKED_LIST", T -> new LINKED_LISTBRACES(T), getFeatures(), -1)); + } + +#if TYPE_OBJECT + private static Test queueSuite(String name, Function> factory, Collection> features, int size) { + return QUEUE_TEST_BUILDER.using(new SIMPLE_QUEUE_TEST_GENERATOR(factory).setElements(createStrings())).named(name).withFeatures(features).withFeatures(getSizes(size)).createTestSuite(); + } + + private static Test dequeueSuite(String name, Function> factory, Collection> features, int size) { + return DEQUEUE_TEST_BUILDER.using(new SIMPLE_QUEUE_TEST_GENERATOR(factory).setElements(createStrings())).named(name).withFeatures(features).withFeatures(getSizes(size)).createTestSuite(); + } + + private static String[] createStrings() { + return new String[]{"a", "b", "c", "d", "e"}; + } + +#else + private static Test queueSuite(String name, Function factory, Collection> features, int size) { + return QUEUE_TEST_BUILDER.using(new SIMPLE_QUEUE_TEST_GENERATORBRACES(factory)).named(name).withFeatures(features).withFeatures(getSizes(size)).createTestSuite(); + } + + private static Test dequeueSuite(String name, Function factory, Collection> features, int size) { + return DEQUEUE_TEST_BUILDER.using(new SIMPLE_QUEUE_TEST_GENERATORBRACES(factory)).named(name).withFeatures(features).withFeatures(getSizes(size)).createTestSuite(); + } + +#endif + private static Collection getSizes(int size) { + switch(size) { + case 0: return Arrays.asList(CollectionSize.ZERO); + case 1: return Arrays.asList(CollectionSize.ONE); + case 2: return Arrays.asList(CollectionSize.ZERO, CollectionSize.ONE); + case 3: return Arrays.asList(CollectionSize.SEVERAL); + case 4: return Arrays.asList(CollectionSize.ZERO, CollectionSize.SEVERAL); + case 5: return Arrays.asList(CollectionSize.ONE, CollectionSize.SEVERAL); + default: return Arrays.asList(CollectionSize.ANY); + } + } + + private static Collection> getFeatures() { + return Arrays.asList(CollectionFeature.GENERAL_PURPOSE, SpecialFeature.COPYING, CollectionFeature.KNOWN_ORDER); + } +} diff --git a/src/builder/resources/speiger/assets/tests/templates/collections/SetTests.template b/src/builder/resources/speiger/assets/tests/templates/collections/SetTests.template new file mode 100644 index 00000000..c58cc82b --- /dev/null +++ b/src/builder/resources/speiger/assets/tests/templates/collections/SetTests.template @@ -0,0 +1,196 @@ +package speiger.src.tests.PACKAGE.collections; + +import java.util.Arrays; +import java.util.Collection; +import java.util.function.Function; +#if TYPE_OBJECT +import java.util.Comparator; +import java.util.Objects; +#endif + +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.SetFeature; +import com.google.common.collect.testing.features.Feature; +#if TYPE_OBJECT +import com.google.common.collect.testing.features.CollectionFeature; +#endif +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import speiger.src.collections.PACKAGE.sets.IMMUTABLE_HASH_SET; +import speiger.src.collections.PACKAGE.sets.AVL_TREE_SET; +import speiger.src.collections.PACKAGE.sets.ARRAY_SET; +import speiger.src.collections.PACKAGE.sets.LINKED_CUSTOM_HASH_SET; +import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET; +import speiger.src.collections.PACKAGE.sets.NAVIGABLE_SET; +import speiger.src.collections.PACKAGE.sets.CUSTOM_HASH_SET; +import speiger.src.collections.PACKAGE.sets.HASH_SET; +import speiger.src.collections.PACKAGE.sets.ORDERED_SET; +import speiger.src.collections.PACKAGE.sets.RB_TREE_SET; +import speiger.src.collections.PACKAGE.sets.SET; +import speiger.src.collections.PACKAGE.utils.SETS; +import speiger.src.collections.PACKAGE.utils.STRATEGY; +import speiger.src.testers.PACKAGE.builder.NAVIGABLE_SET_TEST_BUILDER; +import speiger.src.testers.PACKAGE.builder.ORDERED_SET_TEST_BUILDER; +import speiger.src.testers.PACKAGE.builder.SET_TEST_BUILDER; +#if TYPE_OBJECT +import speiger.src.testers.PACKAGE.generators.TEST_NAVIGABLE_SET_GENERATOR; +import speiger.src.testers.PACKAGE.generators.TEST_ORDERED_SET_GENERATOR; +import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR; +#endif +import speiger.src.testers.PACKAGE.impl.COLLECTION_CONSTRUCTOR_TESTS; +import speiger.src.testers.PACKAGE.impl.SIMPLE_TEST_GENERATOR; +#if TYPE_CHAR || TYPE_FLOAT || TYPE_DOUBLE || TYPE_OBJECT +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionIteratorTester; +#endif +import speiger.src.testers.utils.SpecialFeature; +#if TYPE_CHAR || TYPE_FLOAT || TYPE_DOUBLE || TYPE_OBJECT +import speiger.src.testers.utils.TestUtils; +#endif + +@SuppressWarnings("javadoc") +public class SET_TESTS extends TestCase +{ + public static Test suite() { + TestSuite suite = new TestSuite("SETS"); + suite(suite); + constructorSuite(suite); + System.out.println("Generated ["+suite.countTestCases()+"] Tests"); + return suite; + } + + public static void constructorSuite(TestSuite suite) { + TestSuite constructors = new TestSuite("Constructors"); + constructors.addTest(new TestSuite(COLLECTION_CONSTRUCTOR_TESTS.HashSet.class)); + constructors.addTest(new TestSuite(COLLECTION_CONSTRUCTOR_TESTS.LinkedHashSet.class)); + constructors.addTest(new TestSuite(COLLECTION_CONSTRUCTOR_TESTS.CustomHashSet.class)); + constructors.addTest(new TestSuite(COLLECTION_CONSTRUCTOR_TESTS.LinkedCustomHashSet.class)); + constructors.addTest(new TestSuite(COLLECTION_CONSTRUCTOR_TESTS.ImmutableHashSet.class)); + constructors.addTest(new TestSuite(COLLECTION_CONSTRUCTOR_TESTS.ArraySet.class)); + constructors.addTest(new TestSuite(COLLECTION_CONSTRUCTOR_TESTS.RBTreeSet.class)); + constructors.addTest(new TestSuite(COLLECTION_CONSTRUCTOR_TESTS.AVLTreeSet.class)); + constructors.addTest(new TestSuite(COLLECTION_CONSTRUCTOR_TESTS.RBTreeSetComparator.class)); + constructors.addTest(new TestSuite(COLLECTION_CONSTRUCTOR_TESTS.AVLTreeSetComparator.class)); + suite.addTest(constructors); + } + + public static void suite(TestSuite suite) { + suite.addTest(setSuite("HASH_SET", HASH_SET::new, getFeatures(), -1, true)); + suite.addTest(orderedSetSuite("LINKED_HASH_SET", LINKED_HASH_SET::new, getFeatures(), -1)); + suite.addTest(setSuite("CUSTOM_HASH_SET", T -> new CUSTOM_HASH_SETBRACES(T, HashStrategy.INSTANCE), getFeatures(), -1, true)); + suite.addTest(orderedSetSuite("LINKED_CUSTOM_HASH_SET", T -> new LINKED_CUSTOM_HASH_SETBRACES(T, HashStrategy.INSTANCE), getFeatures(), -1)); + suite.addTest(orderedSetSuite("IMMUTABLE_HASH_SET", IMMUTABLE_HASH_SET::new, getImmutableFeatures(), -1)); + suite.addTest(orderedSetSuite("ARRAY_SET", ARRAY_SET::new, getFeatures(), -1)); +#if TYPE_OBJECT + suite.addTest(navigableSetSuite("RB_TREE_SET", RB_TREE_SET::new, getFeatures(), false, -1)); + suite.addTest(navigableSetSuite("AVL_TREE_SET", AVL_TREE_SET::new, getFeatures(), false, -1)); + suite.addTest(navigableSetSuite("RB_TREE_SET_Null", T -> new RB_TREE_SET<>(T, Comparator.nullsFirst(Comparator.naturalOrder())), getFeatures(), true, -1)); + suite.addTest(navigableSetSuite("AVL_TREE_SET_Null", T -> new AVL_TREE_SET<>(T, Comparator.nullsFirst(Comparator.naturalOrder())), getFeatures(), true, -1)); + suite.addTest(navigableSetSuite("Synchronized RB_TREE_SET", T -> new RB_TREE_SET<>(T).synchronize(), getFeatures(), false, -1)); + suite.addTest(navigableSetSuite("Unmodifiable RB_TREE_SET", T -> new RB_TREE_SET<>(T).unmodifiable(), getImmutableFeatures(), false, -1)); +#else + suite.addTest(navigableSetSuite("RB_TREE_SET", RB_TREE_SET::new, getFeatures(), -1)); + suite.addTest(navigableSetSuite("AVL_TREE_SET", AVL_TREE_SET::new, getFeatures(), -1)); + suite.addTest(navigableSetSuite("Synchronized RB_TREE_SET", T -> new RB_TREE_SET(T).synchronize(), getFeatures(), -1)); + suite.addTest(navigableSetSuite("Unmodifiable RB_TREE_SET", T -> new RB_TREE_SET(T).unmodifiable(), getImmutableFeatures(), -1)); +#endif + suite.addTest(setSuite("Empty SET", T -> SETS.empty(), getImmutableFeatures(), 0, false)); + suite.addTest(setSuite("Singleton SET", T -> SETS.singleton(T[0]), getImmutableFeatures(), 1, false)); + suite.addTest(orderedSetSuite("Synchronized LINKED_HASH_SET", T -> new LINKED_HASH_SETBRACES(T).synchronize(), getFeatures(), -1)); + suite.addTest(orderedSetSuite("Unmodifiable LINKED_HASH_SET", T -> new LINKED_HASH_SETBRACES(T).unmodifiable(), getImmutableFeatures(), -1)); + } + +#if TYPE_OBJECT + public static Test setSuite(String name, Function> factory, Collection> features, int size, boolean sorted) { + SET_TEST_BUILDER builder = (SET_TEST_BUILDER)SET_TEST_BUILDER.using((TEST_SET_GENERATOR)new SIMPLE_TEST_GENERATOR.SetsBRACES(factory).setElements(createSortedStrings())).named(name) +#ignore + .withFeatures(getSizes(size)).withFeatures(CollectionFeature.ALLOWS_NULL_VALUES).withFeatures(features); +#endignore + if(sorted) builder.suppressing(TestUtils.getSurpession(FILE_KEY_TYPECollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported")); + return builder.createTestSuite(); + } + + public static Test orderedSetSuite(String name, Function> factory, Collection> features, int size) { + return ORDERED_SET_TEST_BUILDER.using((TEST_ORDERED_SET_GENERATOR)new SIMPLE_TEST_GENERATOR.OrderedSetsBRACES(factory).setElements(createSortedStrings())).named(name) +#ignore + .withFeatures(getSizes(size)).withFeatures(CollectionFeature.ALLOWS_NULL_VALUES).withFeatures(features).createTestSuite(); +#endignore + } + + public static Test navigableSetSuite(String name, Function> factory, Collection> features, boolean nullValues, int size) { + NAVIGABLE_SET_TEST_BUILDER builder = (NAVIGABLE_SET_TEST_BUILDER)NAVIGABLE_SET_TEST_BUILDER.using((TEST_NAVIGABLE_SET_GENERATOR)new SIMPLE_TEST_GENERATOR.NavigableSetsBRACES(factory).setElements(createSortedStrings())).named(name) +#ignore + .withFeatures(getSizes(size)).withFeatures(features); + if(nullValues) builder.withFeatures(CollectionFeature.ALLOWS_NULL_VALUES); +#endignore + return builder.createTestSuite(); + } + + private static class HashStrategy implements STRATEGY { + static final HashStrategy INSTANCE = new HashStrategy(); + @Override + public int hashCode(String o) { return KEY_TO_HASH(o); } + @Override + public boolean equals(String key, String value) { return KEY_EQUALS(key, value); } + } + + private static String[] createSortedStrings() { + return new String[]{"a", "b", "c", "d", "e", "!! a", "!! b", "~~ a", "~~ b"}; + } +#else + public static Test setSuite(String name, Function factory, Collection> features, int size, boolean sorted) { + SET_TEST_BUILDER builder = (SET_TEST_BUILDER)SET_TEST_BUILDER.using(new SIMPLE_TEST_GENERATOR.SetsBRACES(factory)).named(name) +#ignore + .withFeatures(getSizes(size)).withFeatures(features); +#endignore +#if TYPE_CHAR || TYPE_FLOAT || TYPE_DOUBLE + if(sorted) builder.suppressing(TestUtils.getSurpession(FILE_KEY_TYPECollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported")); +#endif + return builder.createTestSuite(); + } + + public static Test orderedSetSuite(String name, Function factory, Collection> features, int size) { + return ORDERED_SET_TEST_BUILDER.using(new SIMPLE_TEST_GENERATOR.OrderedSetsBRACES(factory)).named(name) +#ignore + .withFeatures(getSizes(size)).withFeatures(features).createTestSuite(); +#endignore + } + + public static Test navigableSetSuite(String name, Function factory, Collection> features, int size) { + return NAVIGABLE_SET_TEST_BUILDER.using(new SIMPLE_TEST_GENERATOR.NavigableSetsBRACES(factory)).named(name) +#ignore + .withFeatures(getSizes(size)).withFeatures(features).createTestSuite(); +#endignore + } + + private static class HashStrategy implements STRATEGY KEY_GENERIC_TYPE { + static final HashStrategy INSTANCE = new HashStrategy(); + @Override + public int hashCode(KEY_TYPE o) { return KEY_TO_HASH(o); } + @Override + public boolean equals(KEY_TYPE key, KEY_TYPE value) { return KEY_EQUALS(key, value); } + } +#endif + +#ignore + private static Collection getSizes(int size) { + switch(size) { + case 0: return Arrays.asList(CollectionSize.ZERO); + case 1: return Arrays.asList(CollectionSize.ONE); + case 2: return Arrays.asList(CollectionSize.ZERO, CollectionSize.ONE); + case 3: return Arrays.asList(CollectionSize.SEVERAL); + case 4: return Arrays.asList(CollectionSize.ZERO, CollectionSize.SEVERAL); + case 5: return Arrays.asList(CollectionSize.ONE, CollectionSize.SEVERAL); + default: return Arrays.asList(CollectionSize.ANY); + } + } + + private static Collection> getImmutableFeatures() { + return Arrays.asList(SpecialFeature.COPYING); + } + + private static Collection> getFeatures() { + return Arrays.asList(SetFeature.GENERAL_PURPOSE, SpecialFeature.COPYING, SpecialFeature.MODIFIABLE); + } +#endignore +} diff --git a/src/builder/resources/speiger/assets/tests/templates/maps/MapTests.template b/src/builder/resources/speiger/assets/tests/templates/maps/MapTests.template new file mode 100644 index 00000000..0a6f725b --- /dev/null +++ b/src/builder/resources/speiger/assets/tests/templates/maps/MapTests.template @@ -0,0 +1,395 @@ +package speiger.src.tests.PACKAGE.maps; + +#if VALUE_BOOLEAN +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +#endif +import java.util.Arrays; +import java.util.Collection; +#if TYPE_OBJECT +import java.util.Objects; +#endif +import java.util.function.BiFunction; + +#if TYPE_OBJECT +import com.google.common.collect.testing.AnEnum; +#endif +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; +import com.google.common.collect.testing.features.MapFeature; +import com.google.common.collect.testing.features.Feature; +#if VALUE_BOOLEAN +import com.google.common.collect.testing.testers.CollectionAddAllTester; +import com.google.common.collect.testing.testers.CollectionAddTester; +import com.google.common.collect.testing.testers.CollectionContainsAllTester; +import com.google.common.collect.testing.testers.CollectionContainsTester; +import com.google.common.collect.testing.testers.CollectionRetainAllTester; +#endif + + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import speiger.src.collections.PACKAGE.maps.impl.concurrent.CONCURRENT_HASH_MAP; +import speiger.src.collections.PACKAGE.maps.impl.hash.LINKED_HASH_MAP; +import speiger.src.collections.PACKAGE.maps.impl.immutable.IMMUTABLE_HASH_MAP; +import speiger.src.collections.PACKAGE.maps.impl.customHash.CUSTOM_HASH_MAP; +import speiger.src.collections.PACKAGE.maps.impl.customHash.LINKED_CUSTOM_HASH_MAP; +import speiger.src.collections.PACKAGE.maps.impl.hash.HASH_MAP; +import speiger.src.collections.PACKAGE.maps.impl.misc.ARRAY_MAP; +#if TYPE_OBJECT +import speiger.src.collections.PACKAGE.maps.impl.misc.ENUM_MAP; +import speiger.src.collections.PACKAGE.maps.impl.misc.LINKED_ENUM_MAP; +#endif +import speiger.src.collections.PACKAGE.maps.impl.tree.AVL_TREE_MAP; +import speiger.src.collections.PACKAGE.maps.impl.tree.RB_TREE_MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP; +import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP; +import speiger.src.collections.PACKAGE.utils.STRATEGY; +import speiger.src.collections.PACKAGE.utils.maps.MAPS; +import speiger.src.testers.PACKAGE.builder.maps.MAP_TEST_BUILDER; +import speiger.src.testers.PACKAGE.builder.maps.ORDERED_MAP_TEST_BUILDER; +import speiger.src.testers.PACKAGE.builder.maps.NAVIGABLE_MAP_TEST_BUILDER; +import speiger.src.testers.PACKAGE.impl.maps.SIMPLE_MAP_TEST_GENERATOR; +import speiger.src.testers.PACKAGE.impl.maps.MAP_CONSTRUCTOR_TESTS; +import speiger.src.testers.PACKAGE.impl.maps.SIMPLE_TEST_MAP; +import speiger.src.testers.objects.tests.collection.ObjectCollectionIteratorTester; +#if !SAME_TYPE && !TYPE_OBJECT +import speiger.src.testers.PACKAGE.tests.collection.FILE_KEY_TYPECollectionIteratorTester; +#endif +#if !VALUE_OBJECT +import speiger.src.testers.VALUE_PACKAGE.tests.collection.FILE_VALUE_TYPECollectionIteratorTester; +#endif +import speiger.src.testers.PACKAGE.tests.misc.PAIRTester; +#if VALUE_BOOLEAN +import speiger.src.testers.booleans.tests.collection.BooleanCollectionAddAllArrayTester; +import speiger.src.testers.booleans.tests.collection.BooleanCollectionAddAllTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsValueTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapMergeTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutIfAbsentTester; +import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveEntryTester; +#endif +import speiger.src.testers.utils.SpecialFeature; +import speiger.src.testers.utils.TestUtils; + +@SuppressWarnings("javadoc") +public class MAP_TESTS extends TestCase +{ + public static Test suite() { + TestSuite suite = new TestSuite("MAPS"); + suite(suite); + constructorSuite(suite); + pairSuite(suite); + System.out.println("Generated ["+suite.countTestCases()+"] Tests"); + return suite; + } + + public static void pairSuite(TestSuite suite) { + TestSuite pairs = new TestSuite("Constructors"); + pairs.addTest(new TestSuite(PAIRTester.Mutable.class)); + pairs.addTest(new TestSuite(PAIRTester.Immutable.class)); + suite.addTest(pairs); + } + + public static void constructorSuite(TestSuite suite) { + TestSuite constructors = new TestSuite("Constructors"); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.HashMap.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.LinkedHashMap.class)); +#if TYPE_OBJECT + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.EnumMap.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.LinkedEnumMap.class)); +#endif + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.CustomHashMap.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.LinkedCustomHashMap.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.ImmutableHashMap.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.ConcurrentHashMap.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.ArrayMap.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.RBTreeMap.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.AVLTreeMap.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.RBTreeMapComparator.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.AVLTreeMapComparator.class)); + + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.HashMapBuilder.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.LinkedHashMapBuilder.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.CustomHashMapBuilder.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.LinkedCustomHashMapBuilder.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.ImmutableHashMapBuilder.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.ConcurrentHashMapBuilder.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.ArrayMapBuilder.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.RBTreeMapBuilder.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.AVLTreeMapBuilder.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.RBTreeMapComparatorBuilder.class)); + constructors.addTest(new TestSuite(MAP_CONSTRUCTOR_TESTS.AVLTreeMapComparatorBuilder.class)); + suite.addTest(constructors); + } + + public static void suite(TestSuite suite) { + suite.addTest(mapSuite("HASH_MAP", HASH_MAP::new, getFeatures(), -1, true)); + suite.addTest(orderedMapSuite("LINKED_HASH_MAP", LINKED_HASH_MAP::new, getFeatures(), -1)); + suite.addTest(orderedMapSuite("IMMUTABLE_HASH_MAP", IMMUTABLE_HASH_MAP::new, getImmutableFeatures(), -1)); +#if TYPE_OBJECT + suite.addTest(enumMapSuite("ENUM_MAP", ENUM_MAP::new, getFeatures(), 5)); + suite.addTest(enumOrderedMapSuite("LINKED_ENUM_MAP", (K, V) -> K.length <= 0 ? new LINKED_ENUM_MAP<>(AnEnum.class) : new LINKED_ENUM_MAP<>(K, V), getFeatures(), 5)); +#endif + suite.addTest(mapSuite("CUSTOM_HASH_MAP", (K, V) -> new CUSTOM_HASH_MAPKV_BRACES(K, V, HashStrategy.INSTANCE), getFeatures(), -1, true)); + suite.addTest(orderedMapSuite("LINKED_CUSTOM_HASH_MAP", (K, V) -> new LINKED_CUSTOM_HASH_MAPKV_BRACES(K, V, HashStrategy.INSTANCE), getFeatures(), -1)); + suite.addTest(orderedMapSuite("ARRAY_MAP", ARRAY_MAP::new, getFeatures(), -1)); + suite.addTest(concurrentMapSuite("CONCURRENT_HASH_MAP", CONCURRENT_HASH_MAP::new, getFeatures(), 2)); + suite.addTest(concurrentMapSuite("CONCURRENT_HASH_MAP", CONCURRENT_HASH_MAP::new, getFeatures(), 3)); + suite.addTest(navigableMapSuite("RB_TREE_MAP", RB_TREE_MAP::new, getFeatures(), -1)); + suite.addTest(navigableMapSuite("AVL_TREE_MAP", AVL_TREE_MAP::new, getFeatures(), -1)); + suite.addTest(navigableMapSuite("SynchronizedRB_TREE_MAP", (K, V) -> new RB_TREE_MAPKV_BRACES(K, V).synchronize(), getLimitedFeatures(), -1)); + suite.addTest(navigableMapSuite("UnmodifiableRB_TREE_MAP", (K, V) -> new RB_TREE_MAPKV_BRACES(K, V).unmodifiable(), getLimitedImmutableFeatures(), -1)); + suite.addTest(orderedMapSuite("SynchronizedORDERED_MAP", (K, V) -> new LINKED_HASH_MAPKV_BRACES(K, V).synchronize(), getFeatures(), -1)); + suite.addTest(orderedMapSuite("UnmodifiableORDERED_MAP", (K, V) -> new LINKED_HASH_MAPKV_BRACES(K, V).unmodifiable(), getImmutableFeatures(), -1)); + suite.addTest(mapSuite("EmptyMAP", (K, V) -> MAPS.empty(), getEmptyFeatures(), 0, false)); + suite.addTest(mapSuite("SingletonMAP", (K, V) -> MAPS.singleton(K[0], V[0]), getEmptyFeatures(), 1, false)); + suite.addTest(mapSuite("AbstractMap", SIMPLE_TEST_MAP::new, getTestFeatures(), -1, false)); + } + +#if TYPE_OBJECT +#if VALUE_OBJECT + private static Test enumMapSuite(String name, BiFunction> factory, Collection> features, int size) { + SIMPLE_MAP_TEST_GENERATOR.Maps generator = new SIMPLE_MAP_TEST_GENERATOR.Maps(factory); + MAP_TEST_BUILDER builder = MAP_TEST_BUILDER.using(generator); +#else + private static Test enumMapSuite(String name, BiFunction> factory, Collection> features, int size) { + SIMPLE_MAP_TEST_GENERATOR.Maps generator = new SIMPLE_MAP_TEST_GENERATOR.Maps(factory); + MAP_TEST_BUILDER builder = MAP_TEST_BUILDER.using(generator); +#endif + builder.shouldBlockKeys(true); + generator.setKeys(AnEnum.values()); +#if VALUE_OBJECT + generator.setValues(createValues()); +#ignore + builder.withFeatures(MapFeature.ALLOWS_NULL_VALUES); +#endignore +#if SAME_TYPE + builder.withFeatures(MapFeature.ALLOWS_NULL_ENTRY_QUERIES); +#endif +#endif + builder.withFeatures(getSizes(size)).withFeatures(features); +#if VALUE_BOOLEAN + builder.suppressing(getSuppression()); +#endif + return builder.named(name).createTestSuite(); +} + +#if VALUE_OBJECT + private static Test enumOrderedMapSuite(String name, BiFunction> factory, Collection> features, int size) { + SIMPLE_MAP_TEST_GENERATOR.OrderedMaps generator = new SIMPLE_MAP_TEST_GENERATOR.OrderedMaps(factory); + ORDERED_MAP_TEST_BUILDER builder = ORDERED_MAP_TEST_BUILDER.using(generator); +#else + private static Test enumOrderedMapSuite(String name, BiFunction> factory, Collection> features, int size) { + SIMPLE_MAP_TEST_GENERATOR.OrderedMaps generator = new SIMPLE_MAP_TEST_GENERATOR.OrderedMaps(factory); + ORDERED_MAP_TEST_BUILDER builder = ORDERED_MAP_TEST_BUILDER.using(generator); +#endif + generator.setKeys(AnEnum.values()); +#if VALUE_OBJECT + generator.setValues(createValues()); +#ignore + builder.withFeatures(MapFeature.ALLOWS_NULL_VALUES); +#endignore +#if SAME_TYPE + builder.withFeatures(MapFeature.ALLOWS_NULL_ENTRY_QUERIES); +#endif +#endif + builder.withFeatures(getSizes(size)).withFeatures(features); +#if VALUE_BOOLEAN + builder.suppressing(getSuppression()); +#endif + return builder.named(name).createTestSuite(); + } + +#endif + + private static Test mapSuite(String name, BiFunction factory, Collection> features, int size, boolean sorted) { + SIMPLE_MAP_TEST_GENERATOR.Maps KEY_VALUE_STRING_GENERIC_TYPE generator = new SIMPLE_MAP_TEST_GENERATOR.Maps KEY_VALUE_STRING_GENERIC_TYPE(factory); + MAP_TEST_BUILDER KEY_VALUE_STRING_GENERIC_TYPE builder = MAP_TEST_BUILDER.using(generator); + builder.shouldBlockKeys(sorted); +#if TYPE_OBJECT + generator.setKeys(createKeys()); +#ignore + builder.withFeatures(MapFeature.ALLOWS_NULL_KEYS); +#endignore +#endif +#if VALUE_OBJECT + generator.setValues(createValues()); +#ignore + builder.withFeatures(MapFeature.ALLOWS_NULL_VALUES); +#endignore +#if SAME_TYPE + builder.withFeatures(MapFeature.ALLOWS_NULL_ENTRY_QUERIES); +#endif +#endif + builder.withFeatures(getSizes(size)).withFeatures(features); +#if VALUE_BOOLEAN + builder.suppressing(getSuppression()); +#endif + return builder.named(name).createTestSuite(); + } + + private static Test concurrentMapSuite(String name, BiFunction factory, Collection> features, int size) { + SIMPLE_MAP_TEST_GENERATOR.Maps KEY_VALUE_STRING_GENERIC_TYPE generator = new SIMPLE_MAP_TEST_GENERATOR.Maps KEY_VALUE_STRING_GENERIC_TYPE(factory); + MAP_TEST_BUILDER KEY_VALUE_STRING_GENERIC_TYPE builder = MAP_TEST_BUILDER.using(generator); +#if TYPE_OBJECT + generator.setKeys(createKeys()); +#ignore + builder.withFeatures(MapFeature.ALLOWS_NULL_KEYS); +#endignore +#endif +#if VALUE_OBJECT + generator.setValues(createValues()); +#ignore + builder.withFeatures(MapFeature.ALLOWS_NULL_VALUES); +#endignore +#if SAME_TYPE + builder.withFeatures(MapFeature.ALLOWS_NULL_ENTRY_QUERIES); +#endif +#endif + builder.withFeatures(getSizes(size)).withFeatures(features); + if(size == 3) { + builder.suppressing(TestUtils.getSurpession(ObjectCollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported")); + builder.suppressing(TestUtils.getSurpession(FILE_KEY_TYPECollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported")); + builder.suppressing(TestUtils.getSurpession(FILE_VALUE_TYPECollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported")); + } +#if VALUE_BOOLEAN + builder.suppressing(getSuppression()); +#endif + return builder.named(name).createTestSuite(); + } + + private static Test orderedMapSuite(String name, BiFunction factory, Collection> features, int size) { + SIMPLE_MAP_TEST_GENERATOR.OrderedMaps KEY_VALUE_STRING_GENERIC_TYPE generator = new SIMPLE_MAP_TEST_GENERATOR.OrderedMaps KEY_VALUE_STRING_GENERIC_TYPE(factory); + ORDERED_MAP_TEST_BUILDER KEY_VALUE_STRING_GENERIC_TYPE builder = ORDERED_MAP_TEST_BUILDER.using(generator); +#if TYPE_OBJECT + generator.setKeys(createKeys()); +#ignore + builder.withFeatures(MapFeature.ALLOWS_NULL_KEYS); +#endignore +#endif +#if VALUE_OBJECT + generator.setValues(createValues()); +#ignore + builder.withFeatures(MapFeature.ALLOWS_NULL_VALUES); +#endignore +#if SAME_TYPE + builder.withFeatures(MapFeature.ALLOWS_NULL_ENTRY_QUERIES); +#endif +#endif + builder.withFeatures(getSizes(size)).withFeatures(features); +#if VALUE_BOOLEAN + builder.suppressing(getSuppression()); +#endif + return builder.named(name).createTestSuite(); + } + + private static Test navigableMapSuite(String name, BiFunction factory, Collection> features, int size) { + SIMPLE_MAP_TEST_GENERATOR.SortedMaps KEY_VALUE_STRING_GENERIC_TYPE generator = new SIMPLE_MAP_TEST_GENERATOR.SortedMaps KEY_VALUE_STRING_GENERIC_TYPE(factory); + NAVIGABLE_MAP_TEST_BUILDER KEY_VALUE_STRING_GENERIC_TYPE builder = NAVIGABLE_MAP_TEST_BUILDER.using(generator); +#if TYPE_OBJECT + generator.setKeys(createKeys()); +#endif +#if VALUE_OBJECT + generator.setValues(createValues()); +#ignore + builder.withFeatures(MapFeature.ALLOWS_NULL_VALUES); +#endignore +#if SAME_TYPE + builder.withFeatures(MapFeature.ALLOWS_NULL_ENTRY_QUERIES); +#endif +#endif + builder.withFeatures(getSizes(size)).withFeatures(features); +#if VALUE_BOOLEAN + builder.suppressing(getSuppression()); +#endif + return builder.named(name).createTestSuite(); + } + + private static class HashStrategy implements STRATEGY KEY_STRING_GENERIC_TYPE { + static final HashStrategy INSTANCE = new HashStrategy(); + @Override + public int hashCode(KEY_STRING_TYPE o) { return KEY_TO_HASH(o); } + @Override + public boolean equals(KEY_STRING_TYPE key, KEY_STRING_TYPE value) { return KEY_EQUALS(key, value); } + } + +#ignore + private static Collection getSizes(int size) { + switch(size) { + case 0: return Arrays.asList(CollectionSize.ZERO); + case 1: return Arrays.asList(CollectionSize.ONE); + case 2: return Arrays.asList(CollectionSize.ZERO, CollectionSize.ONE); + case 3: return Arrays.asList(CollectionSize.SEVERAL); + case 4: return Arrays.asList(CollectionSize.ZERO, CollectionSize.SEVERAL); + case 5: return Arrays.asList(CollectionSize.ONE, CollectionSize.SEVERAL); + default: return Arrays.asList(CollectionSize.ANY); + } + } + + private static Collection> getFeatures() { + return Arrays.asList(MapFeature.GENERAL_PURPOSE, CollectionFeature.SUPPORTS_ITERATOR_REMOVE, SpecialFeature.COPYING, SpecialFeature.MODIFIABLE); + } + + private static Collection> getTestFeatures() { + return Arrays.asList(MapFeature.GENERAL_PURPOSE, CollectionFeature.SUPPORTS_ITERATOR_REMOVE, SpecialFeature.MODIFIABLE); + } + + private static Collection> getEmptyFeatures() { + return Arrays.asList(SpecialFeature.CHILDREN_COPY); + } + + private static Collection> getImmutableFeatures() { + return Arrays.asList(SpecialFeature.COPYING); + } + + private static Collection> getLimitedFeatures() { + return Arrays.asList(MapFeature.GENERAL_PURPOSE, CollectionFeature.SUPPORTS_ITERATOR_REMOVE, SpecialFeature.SUBMAP, SpecialFeature.DESCENDING, SpecialFeature.COPYING, SpecialFeature.MODIFIABLE); + } + + private static Collection> getLimitedImmutableFeatures() { + return Arrays.asList(SpecialFeature.SUBMAP, SpecialFeature.DESCENDING, SpecialFeature.COPYING); + } +#endignore +#if TYPE_OBJECT + private static String[] createKeys() { + return new String[]{"one", "two", "three", "four", "five", "!! a", "!! b", "~~ a", "~~ b"}; + } + +#endif +#if VALUE_OBJECT + private static String[] createValues() { + return new String[]{"January", "February", "March", "April", "May", "below view", "below view", "above view", "above view"}; + } + +#endif +#if VALUE_BOOLEAN + public static List getSuppression() { + List list = new ArrayList<>(); + TestUtils.getSurpession(list, FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester.class, "testCompute_absentToPresent", "testCompute_presentToPresent"); + TestUtils.getSurpession(list, FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester.class, "testComputeIfAbsent_supportedAbsent"); + TestUtils.getSurpession(list, FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester.class, "testCompute_presentToPresent", "testComputeIfPresent_supportedPresent"); + TestUtils.getSurpession(list, FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester.class, "testSupplyIfAbsent_supportedAbsent"); + TestUtils.getSurpession(list, FILE_KEY_TYPE2FILE_VALUE_TYPEMapMergeTester.class, "testAbsent"); + TestUtils.getSurpession(list, FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutIfAbsentTester.class, "testPutIfAbsent_supportedAbsent"); + TestUtils.getSurpession(list, FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveEntryTester.class, "testRemove_supportedPresentLastWrongValue", "testRemoveObject_supportedPresentLastWrongValue"); + + TestUtils.getSurpession(list, CollectionAddTester.class, "testAdd_unsupportedNotPresent"); + TestUtils.getSurpession(list, CollectionAddAllTester.class, "testAddAll_unsupportedNonePresent"); + TestUtils.getSurpession(list, FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsValueTester.class, "testContains_no"); + TestUtils.getSurpession(list, CollectionContainsTester.class, "testContains_no"); + TestUtils.getSurpession(list, CollectionRetainAllTester.class, "testRetainAll_disjointPreviouslyNonEmpty"); + TestUtils.getSurpession(list, BooleanCollectionAddAllTester.class, "testAddAll_unsupportedNonePresent"); + TestUtils.getSurpession(list, BooleanCollectionAddAllArrayTester.class, "testAddAllArray_unsupportedNonePresent"); + TestUtils.getSurpession(list, CollectionContainsAllTester.class, "testContainsAll_disjoint", "testContainsAll_partialOverlap"); + return list; + } + +#endif +} diff --git a/src/test/java/speiger/src/testers/base/tests/collection/JavaCollectionRemoveIfTester.java b/src/test/java/speiger/src/testers/base/tests/collection/JavaCollectionRemoveIfTester.java new file mode 100644 index 00000000..f247e684 --- /dev/null +++ b/src/test/java/speiger/src/testers/base/tests/collection/JavaCollectionRemoveIfTester.java @@ -0,0 +1,93 @@ +package speiger.src.testers.base.tests.collection; + +import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; +import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; +import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; +import static com.google.common.collect.testing.features.CollectionSize.ZERO; + +import java.util.ConcurrentModificationException; +import java.util.Iterator; +import java.util.function.Predicate; + +import org.junit.Ignore; + +import com.google.common.collect.testing.AbstractCollectionTester; +import com.google.common.collect.testing.features.CollectionFeature; +import com.google.common.collect.testing.features.CollectionSize; + +@Ignore +@SuppressWarnings({"unchecked", "javadoc" }) +public class JavaCollectionRemoveIfTester extends AbstractCollectionTester +{ + @CollectionFeature.Require(SUPPORTS_REMOVE) + public void testRemoveIf_alwaysFalse() + { + assertFalse("removeIf(x -> false) should return false", collection.removeIf(x -> false)); + expectUnchanged(); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) + public void testRemoveIf_sometimesTrue() + { + assertTrue("removeIf(isEqual(present)) should return true", collection.removeIf(Predicate.isEqual(samples.e0()))); + expectMissing(samples.e0()); + } + + @CollectionFeature.Require(SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) + public void testRemoveIf_allPresent() + { + assertTrue("removeIf(x -> true) should return true", collection.removeIf(x -> true)); + expectContents(); + } + + @CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION }) + @CollectionSize.Require(SEVERAL) + public void testRemoveIfSomeMatchesConcurrentWithIteration() + { + try + { + Iterator iterator = collection.iterator(); + assertTrue(collection.removeIf(Predicate.isEqual(samples.e0()))); + iterator.next(); + fail("Expected ConcurrentModificationException"); + } + catch(ConcurrentModificationException expected) + { + // success + } + } + + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(ZERO) + public void testRemoveIf_unsupportedEmptyCollection() + { + try + { + assertFalse("removeIf(Predicate) should return false or throw " + "UnsupportedOperationException", collection.removeIf(x -> { + throw new AssertionError("predicate should never be called"); + })); + } + catch(UnsupportedOperationException tolerated) + { + } + expectUnchanged(); + } + + @CollectionFeature.Require(absent = SUPPORTS_REMOVE) + @CollectionSize.Require(absent = ZERO) + public void testRemoveIf_alwaysTrueUnsupported() + { + try + { + collection.removeIf(x -> true); + fail("removeIf(x -> true) should throw " + "UnsupportedOperationException"); + } + catch(UnsupportedOperationException expected) + { + } + expectUnchanged(); + assertTrue(collection.contains(samples.e0())); + } +} diff --git a/src/test/java/speiger/src/testers/base/tests/list/JavaListListIteratorTester.java b/src/test/java/speiger/src/testers/base/tests/list/JavaListListIteratorTester.java new file mode 100644 index 00000000..4af73b1c --- /dev/null +++ b/src/test/java/speiger/src/testers/base/tests/list/JavaListListIteratorTester.java @@ -0,0 +1,84 @@ +package speiger.src.testers.base.tests.list; + +import static com.google.common.collect.testing.IteratorFeature.MODIFIABLE; +import static com.google.common.collect.testing.IteratorFeature.UNMODIFIABLE; +import static java.util.Collections.singleton; + +import java.util.List; +import java.util.ListIterator; +import java.util.Set; + +import org.junit.Ignore; + +import com.google.common.collect.testing.Helpers; +import com.google.common.collect.testing.IteratorFeature; +import com.google.common.collect.testing.ListIteratorTester; +import com.google.common.collect.testing.testers.AbstractListTester; + +import speiger.src.testers.utils.SpecialFeature; + +@Ignore +@SuppressWarnings("javadoc") +public class JavaListListIteratorTester extends AbstractListTester +{ + @SpecialFeature.Require(absent = SpecialFeature.ITERATOR_MODIFIABLE) + public void testListIterator_unmodifiable() + { + runListIteratorTest(UNMODIFIABLE); + } + + @SpecialFeature.Require(SpecialFeature.ITERATOR_MODIFIABLE) + public void testListIterator_fullyModifiable() + { + runListIteratorTest(MODIFIABLE); + } + + private void runListIteratorTest(Set features) + { + new ListIteratorTester(4, singleton(e4()), features, Helpers.copyToList(getOrderedElements()), 0) + { + @Override + protected ListIterator newTargetIterator() + { + resetCollection(); + return getList().listIterator(); + } + + @Override + protected void verify(List elements) + { + expectContents(elements); + } + }.test(); + } + + public void testListIterator_tooLow() + { + try + { + getList().listIterator(-1); + fail(); + } + catch(IndexOutOfBoundsException expected) + { + } + } + + public void testListIterator_tooHigh() + { + try + { + getList().listIterator(getNumElements() + 1); + fail(); + } + catch(IndexOutOfBoundsException expected) + { + } + } + + public void testListIterator_atSize() + { + getList().listIterator(getNumElements()); + // TODO: run the iterator through ListIteratorTester + } +} diff --git a/src/test/java/speiger/src/testers/utils/SpecialFeature.java b/src/test/java/speiger/src/testers/utils/SpecialFeature.java new file mode 100644 index 00000000..22a39b63 --- /dev/null +++ b/src/test/java/speiger/src/testers/utils/SpecialFeature.java @@ -0,0 +1,42 @@ +package speiger.src.testers.utils; + +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.util.Collection; +import java.util.Set; + +import com.google.common.collect.testing.Helpers; +import com.google.common.collect.testing.features.Feature; +import com.google.common.collect.testing.features.TesterAnnotation; + +@SuppressWarnings({"rawtypes", "javadoc"}) +public enum SpecialFeature implements Feature { + COPYING, + CHILDREN_COPY(COPYING), + MODIFIABLE, + ITERATOR_MODIFIABLE, + MAP_ENTRY, + DESCENDING, + SUBMAP; + + private final Set> implied; + + SpecialFeature(Feature... implied) { + this.implied = Helpers.copyToSet(implied); + } + + @Override + public Set> getImpliedFeatures() { + return implied; + } + + @Retention(RetentionPolicy.RUNTIME) + @Inherited + @TesterAnnotation + public @interface Require { + SpecialFeature[] value() default {}; + + SpecialFeature[] absent() default {}; + } +} diff --git a/src/test/java/speiger/src/testers/utils/TestUtils.java b/src/test/java/speiger/src/testers/utils/TestUtils.java new file mode 100644 index 00000000..6990024b --- /dev/null +++ b/src/test/java/speiger/src/testers/utils/TestUtils.java @@ -0,0 +1,56 @@ +package speiger.src.testers.utils; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@SuppressWarnings("javadoc") +public class TestUtils +{ + public static void getSurpession(Collection methods, Class clz, String...args) { + Set set = new HashSet<>(Arrays.asList(args)); + try { + for(Method method : clz.getMethods()) { + if(set.contains(method.getName())) methods.add(method); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void getSurpession(Collection methods, Class clz) { + try { + for(Method method : clz.getMethods()) { + methods.add(method); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static Method[] getSurpession(Class clz) { + try { + return clz.getMethods(); + } catch (Exception e) { + e.printStackTrace(); + } + return new Method[0]; + } + + public static Method[] getSurpession(Class clz, String...args) { + List methods = new ArrayList<>(); + Set set = new HashSet<>(Arrays.asList(args)); + try { + for(Method method : clz.getMethods()) { + if(set.contains(method.getName())) methods.add(method); + } + } catch (Exception e) { + e.printStackTrace(); + } + return methods.toArray(new Method[methods.size()]); + } +}