Test more of the math/collections, fix VectorPList

Fixes #1291

(cherry picked from commit e0346ff53b8629a368cdbf62cbd347caecfae5fd)
This commit is contained in:
Octavia Togami
2020-06-03 14:51:57 -07:00
committed by MattBDev
parent 63b81b801b
commit 518f52ea6e
7 changed files with 330 additions and 189 deletions

View File

@ -27,7 +27,8 @@ import com.sk89q.worldedit.extension.platform.PlatformManager;
import com.sk89q.worldedit.extension.platform.Preference;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.Registry;
import com.sk89q.worldedit.util.VariedVectorsProvider;
import com.sk89q.worldedit.util.test.VariedVectorGenerator;
import com.sk89q.worldedit.util.test.VariedVectors;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
@ -265,49 +266,49 @@ class BlockMapTest {
// being able to parameterize classes. It's not part of JUnit
// yet though: https://github.com/junit-team/junit5/issues/878
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("has a size of one")
void hasSizeOne(BlockVector3 vec) {
map.put(vec, air);
assertEquals(1, map.size());
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("is equal to another map with the same entry")
void isEqualToSimilarMap(BlockVector3 vec) {
map.put(vec, air);
assertEquals(ImmutableMap.of(vec, air), map);
}
@VariedVectorsProvider.Test(provideNonMatching = true)
@VariedVectors.Test(provideNonMatching = true)
@DisplayName("is not equal to another map with a different key")
void isNotEqualToDifferentKeyMap(BlockVector3 vec, BlockVector3 nonMatch) {
map.put(vec, air);
assertNotEquals(ImmutableMap.of(nonMatch, air), map);
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("is not equal to another map with a different value")
void isNotEqualToDifferentValueMap(BlockVector3 vec) {
map.put(vec, air);
assertNotEquals(ImmutableMap.of(vec, oakWood), map);
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("is not equal to an empty map")
void isNotEqualToEmptyMap(BlockVector3 vec) {
map.put(vec, air);
assertNotEquals(ImmutableMap.of(), map);
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("has the same hashCode as another map with the same entry")
void isHashCodeEqualToSimilarMap(BlockVector3 vec) {
map.put(vec, air);
assertEquals(ImmutableMap.of(vec, air).hashCode(), map.hashCode());
}
@VariedVectorsProvider.Test(provideNonMatching = true)
@VariedVectors.Test(provideNonMatching = true)
@DisplayName("has a different hashCode from another map with a different key")
void isHashCodeNotEqualToDifferentKeyMap(BlockVector3 vec, BlockVector3 nonMatch) {
assumeFalse(vec.hashCode() == nonMatch.hashCode(),
@ -316,35 +317,35 @@ class BlockMapTest {
assertNotEquals(ImmutableMap.of(nonMatch, air).hashCode(), map.hashCode());
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("has a different hashCode from another map with a different value")
void isHashCodeNotEqualToDifferentValueMap(BlockVector3 vec) {
map.put(vec, air);
assertNotEquals(ImmutableMap.of(vec, oakWood).hashCode(), map.hashCode());
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("has a different hashCode from an empty map")
void isHashCodeNotEqualToEmptyMap(BlockVector3 vec) {
map.put(vec, air);
assertNotEquals(ImmutableMap.of().hashCode(), map.hashCode());
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("returns value from get")
void returnsValueFromGet(BlockVector3 vec) {
map.put(vec, air);
assertEquals(air, map.get(vec));
}
@VariedVectorsProvider.Test(provideNonMatching = true)
@VariedVectors.Test(provideNonMatching = true)
@DisplayName("returns `null` from get with different key")
void returnsValueFromGet(BlockVector3 vec, BlockVector3 nonMatch) {
map.put(vec, air);
assertNotEquals(air, map.get(nonMatch));
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("contains the key")
void containsTheKey(BlockVector3 vec) {
map.put(vec, air);
@ -353,7 +354,7 @@ class BlockMapTest {
assertTrue(map.containsKey(vec));
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("contains the value")
void containsTheValue(BlockVector3 vec) {
map.put(vec, air);
@ -362,7 +363,7 @@ class BlockMapTest {
assertTrue(map.containsValue(air));
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("contains the entry")
void containsTheEntry(BlockVector3 vec) {
map.put(vec, air);
@ -370,21 +371,21 @@ class BlockMapTest {
assertEquals(new AbstractMap.SimpleImmutableEntry<>(vec, air), map.entrySet().iterator().next());
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("returns the provided value from getOrDefault")
void returnsProvidedFromGetOrDefault(BlockVector3 vec) {
map.put(vec, air);
assertEquals(air, map.getOrDefault(vec, oakWood));
}
@VariedVectorsProvider.Test(provideNonMatching = true)
@VariedVectors.Test(provideNonMatching = true)
@DisplayName("returns the default value from getOrDefault with a different key")
void returnsDefaultFromGetOrDefaultWrongKey(BlockVector3 vec, BlockVector3 nonMatch) {
map.put(vec, air);
assertEquals(oakWood, map.getOrDefault(nonMatch, oakWood));
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("calls the forEach action once")
void neverCallsForEachAction(BlockVector3 vec) {
map.put(vec, air);
@ -393,7 +394,7 @@ class BlockMapTest {
verifyNoMoreInteractions(biConsumer);
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("replaces value using replaceAll")
void neverCallsReplaceAllFunction(BlockVector3 vec) {
map.put(vec, air);
@ -401,7 +402,7 @@ class BlockMapTest {
assertEquals(oakWood, map.get(vec));
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("does not insert on `putIfAbsent`")
void noInsertOnPutIfAbsent(BlockVector3 vec) {
map.put(vec, air);
@ -410,7 +411,7 @@ class BlockMapTest {
assertEquals(air, map.get(vec));
}
@VariedVectorsProvider.Test(provideNonMatching = true)
@VariedVectors.Test(provideNonMatching = true)
@DisplayName("inserts on `putIfAbsent` to a different key")
void insertOnPutIfAbsentDifferentKey(BlockVector3 vec, BlockVector3 nonMatch) {
map.put(vec, air);
@ -420,7 +421,7 @@ class BlockMapTest {
assertEquals(oakWood, map.get(nonMatch));
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("remove(key) returns the old value")
void removeKeyReturnsOldValue(BlockVector3 vec) {
map.put(vec, air);
@ -428,7 +429,7 @@ class BlockMapTest {
assertEquals(0, map.size());
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("keySet().remove(key) removes the entry from the map")
void keySetRemovePassesThrough(BlockVector3 vec) {
map.put(vec, air);
@ -436,7 +437,7 @@ class BlockMapTest {
assertEquals(0, map.size());
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("entrySet().iterator().remove() removes the entry from the map")
void entrySetIteratorRemovePassesThrough(BlockVector3 vec) {
map.put(vec, air);
@ -448,7 +449,7 @@ class BlockMapTest {
assertEquals(0, map.size());
}
@VariedVectorsProvider.Test(provideNonMatching = true)
@VariedVectors.Test(provideNonMatching = true)
@DisplayName("remove(nonMatch) returns null")
void removeNonMatchingKeyReturnsNull(BlockVector3 vec, BlockVector3 nonMatch) {
map.put(vec, air);
@ -456,7 +457,7 @@ class BlockMapTest {
assertEquals(1, map.size());
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("remove(key, value) returns true")
void removeKeyValueReturnsTrue(BlockVector3 vec) {
map.put(vec, air);
@ -464,7 +465,7 @@ class BlockMapTest {
assertEquals(0, map.size());
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("remove(key, value) returns false for wrong value")
void removeKeyValueReturnsFalseWrongValue(BlockVector3 vec) {
map.put(vec, air);
@ -472,7 +473,7 @@ class BlockMapTest {
assertEquals(1, map.size());
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("replaces value at key")
void replacesValueAtKey(BlockVector3 vec) {
map.put(vec, air);
@ -486,7 +487,7 @@ class BlockMapTest {
assertEquals(air, map.get(vec));
}
@VariedVectorsProvider.Test(provideNonMatching = true)
@VariedVectors.Test(provideNonMatching = true)
@DisplayName("does not replace value at different key")
void doesNotReplaceAtDifferentKey(BlockVector3 vec, BlockVector3 nonMatch) {
map.put(vec, air);
@ -500,7 +501,7 @@ class BlockMapTest {
assertEquals(air, map.get(vec));
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("does not insert on computeIfAbsent")
void doesNotInsertComputeIfAbsent(BlockVector3 vec) {
map.put(vec, air);
@ -512,7 +513,7 @@ class BlockMapTest {
assertEquals(air, map.get(vec));
}
@VariedVectorsProvider.Test(provideNonMatching = true)
@VariedVectors.Test(provideNonMatching = true)
@DisplayName("inserts on computeIfAbsent with different key")
void insertsOnComputeIfAbsentDifferentKey(BlockVector3 vec, BlockVector3 nonMatch) {
map.put(vec, air);
@ -525,7 +526,7 @@ class BlockMapTest {
assertEquals(oakWood, map.get(nonMatch));
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("replaces on compute")
void replaceOnCompute(BlockVector3 vec) {
map.put(vec, air);
@ -540,7 +541,7 @@ class BlockMapTest {
assertEquals(0, map.size());
}
@VariedVectorsProvider.Test(provideNonMatching = true)
@VariedVectors.Test(provideNonMatching = true)
@DisplayName("inserts on compute with different key")
void insertOnComputeDifferentKey(BlockVector3 vec, BlockVector3 nonMatch) {
map.put(vec, air);
@ -557,7 +558,7 @@ class BlockMapTest {
assertEquals(air, map.get(vec));
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("replaces on computeIfPresent")
void replacesOnComputeIfPresent(BlockVector3 vec) {
map.put(vec, air);
@ -572,7 +573,7 @@ class BlockMapTest {
assertEquals(0, map.size());
}
@VariedVectorsProvider.Test
@VariedVectors.Test
@DisplayName("inserts on merge, with call to merge function")
void insertsOnMerge(BlockVector3 vec) {
map.put(vec, air);
@ -590,7 +591,9 @@ class BlockMapTest {
@Test
@DisplayName("contains all inserted vectors")
void containsAllInsertedVectors() {
Set<BlockVector3> allVectors = VariedVectorsProvider.makeVectorsStream().collect(Collectors.toSet());
Set<BlockVector3> allVectors = new VariedVectorGenerator()
.makeVectorsStream()
.collect(Collectors.toSet());
for (BlockVector3 vec : allVectors) {
map.put(vec, air);
}