From 6275e9298ec6571d65dd1048de75e7d595569f4d Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Fri, 27 Mar 2020 19:09:26 -0400 Subject: [PATCH] Modify Tests --- .../transform/BlockTransformExtentTest.java | 9 +-- .../sk89q/worldedit/util/LocationTest.java | 24 ++++++- .../worldedit/util/io/file/MorePathsTest.java | 69 +++++++++++++++++++ 3 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 worldedit-core/src/test/java/com/sk89q/worldedit/util/io/file/MorePathsTest.java diff --git a/worldedit-core/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java b/worldedit-core/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java index 91a60be54..c650c3da8 100644 --- a/worldedit-core/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java +++ b/worldedit-core/src/test/java/com/sk89q/worldedit/extent/transform/BlockTransformExtentTest.java @@ -23,14 +23,15 @@ import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; -import java.util.HashSet; -import java.util.Set; import org.junit.jupiter.api.BeforeEach; - -import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertEquals; + @Disabled("A platform is currently required to get properties, preventing this test.") public class BlockTransformExtentTest { diff --git a/worldedit-core/src/test/java/com/sk89q/worldedit/util/LocationTest.java b/worldedit-core/src/test/java/com/sk89q/worldedit/util/LocationTest.java index b3c7576cd..418b09fb0 100644 --- a/worldedit-core/src/test/java/com/sk89q/worldedit/util/LocationTest.java +++ b/worldedit-core/src/test/java/com/sk89q/worldedit/util/LocationTest.java @@ -19,11 +19,13 @@ package com.sk89q.worldedit.util; -import static org.junit.jupiter.api.Assertions.assertEquals; - +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.World; +import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; /** @@ -133,5 +135,23 @@ public class LocationTest { assertEquals(0, location2.getY(), EPSILON); assertEquals(TEST_VALUE, location2.getZ(), EPSILON); } + + @RepeatedTest(value = 5) + public void testAddInt() throws Exception { + World world = mock(World.class); + long start = System.currentTimeMillis(); + BlockVector3 location1 = BlockVector3.ZERO; + BlockVector3.at(location1.getX() + 10, location1.getY() + 10, location1.getZ() + 10); + System.out.println(System.currentTimeMillis() - start + " ms"); + } + + @RepeatedTest(value = 5) + public void testAddObj() throws Exception { + World world = mock(World.class); + long start = System.currentTimeMillis(); + BlockVector3 location1 = BlockVector3.ZERO; + location1.add(10,10,10); + System.out.println(System.currentTimeMillis() - start + " ms"); + } } diff --git a/worldedit-core/src/test/java/com/sk89q/worldedit/util/io/file/MorePathsTest.java b/worldedit-core/src/test/java/com/sk89q/worldedit/util/io/file/MorePathsTest.java new file mode 100644 index 000000000..5bdf9bfe1 --- /dev/null +++ b/worldedit-core/src/test/java/com/sk89q/worldedit/util/io/file/MorePathsTest.java @@ -0,0 +1,69 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.util.io.file; + +import org.junit.jupiter.api.Test; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.stream.Stream; + +import static java.util.stream.Collectors.toList; +import static org.junit.jupiter.api.Assertions.assertEquals; + +class MorePathsTest { + + private static List paths(String... paths) { + return Stream.of(paths).map(Paths::get).collect(toList()); + } + + @Test + void testRelative() { + assertEquals( + paths("a", "a/b", "a/b/c"), + MorePaths.iterPaths(Paths.get("a/b/c")).collect(toList()) + ); + } + + @Test + void testAbsolute() { + assertEquals( + paths("/", "/a", "/a/b", "/a/b/c"), + MorePaths.iterPaths(Paths.get("/a/b/c")).collect(toList()) + ); + } + + @Test + void testEmpty() { + assertEquals( + paths(""), + MorePaths.iterPaths(Paths.get("")).collect(toList()) + ); + } + + @Test + void testJustFile() { + assertEquals( + paths("a"), + MorePaths.iterPaths(Paths.get("a")).collect(toList()) + ); + } +}