diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 05a85ef..f5a8539 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -46,8 +46,8 @@ jobs: arguments: build build-root-directory: Pathfinding - # The USERNAME and TOKEN need to correspond to the credentials environment variables used in - # the publishing section of your build.gradle + # Yes, this is intentionally run on all pushes, not just releases + # This makes it easier to make changes to oxplorer during build season - name: Publish Oxplorer Publication to GitHub Packages uses: gradle/gradle-build-action@v2 with: diff --git a/Pathfinding/.gitignore b/Pathfinding/.gitignore index daac1c8..0138938 100644 --- a/Pathfinding/.gitignore +++ b/Pathfinding/.gitignore @@ -37,3 +37,4 @@ gradle-app.setting # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 # gradle/wrapper/gradle-wrapper.properties +gradle.properties \ No newline at end of file diff --git a/Pathfinding/.vscode/settings.json b/Pathfinding/.vscode/settings.json index a6b86d5..55787c1 100644 --- a/Pathfinding/.vscode/settings.json +++ b/Pathfinding/.vscode/settings.json @@ -1,4 +1,11 @@ { - "java.configuration.updateBuildConfiguration": "automatic", - "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -Xlog:disable" -} \ No newline at end of file + "java.configuration.updateBuildConfiguration": "automatic", + "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -Xlog:disable ", + "java.test.config": [ + { + "name": "WPIlibUnitTests", + "vmargs": ["-Dnohaljni=true"] + } + ], + "java.test.defaultConfig": "WPIlibUnitTests" +} diff --git a/Pathfinding/build.gradle b/Pathfinding/build.gradle index a0905f1..883dc85 100644 --- a/Pathfinding/build.gradle +++ b/Pathfinding/build.gradle @@ -25,6 +25,21 @@ dependencies { implementation wpi.java.vendor.java() implementation 'org.json:json:20231013' + + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + + testImplementation wpi.java.deps.wpilib() + +} + +test { + useJUnitPlatform() + systemProperty 'nohaljni', 'true' + testLogging { + events "passed", "skipped", "failed" + } } publishing { diff --git a/Pathfinding/src/test/java/me/nabdev/pathfinding/PathfinderTest.java b/Pathfinding/src/test/java/me/nabdev/pathfinding/PathfinderTest.java new file mode 100644 index 0000000..f98b9a3 --- /dev/null +++ b/Pathfinding/src/test/java/me/nabdev/pathfinding/PathfinderTest.java @@ -0,0 +1,82 @@ +package me.nabdev.pathfinding; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import me.nabdev.pathfinding.structures.ImpossiblePathException; +import me.nabdev.pathfinding.structures.Vector; +import me.nabdev.pathfinding.structures.Vertex; +import me.nabdev.pathfinding.utilities.FieldLoader.Field; + +public class PathfinderTest { + Pathfinder pathfinder; + + @BeforeEach + void setUp() { + pathfinder = new PathfinderBuilder(Field.CRESCENDO_2024).build(); + } + + @Test + @DisplayName("Impossible Path Should Throw Exception") + void impossiblePath() { + assertThrows(ImpossiblePathException.class, + () -> pathfinder.generatePath(new Vertex(-2, -2), new Vertex(2, 2))); + } + + @Test + @DisplayName("Pathfinder Should Generate Path") + void generatePath() { + assertDoesNotThrow(() -> pathfinder.generatePath(new Vertex(2, 2), new Vertex(4, 4))); + } + + @Test + @DisplayName("Diagonal Intersection") + void diagonalIntersect() { + assertTrue(Vector.dotIntersectFast(new Vertex(0, 0), new Vertex(10, 10), new Vertex(0, 10), new Vertex(10, 0))); + } + + @Test + @DisplayName("One vertex intersection") + void oneVertexIntersect() { + assertTrue( + Vector.dotIntersectFast(new Vertex(0, 0), new Vertex(10, 10), new Vertex(0, 10), new Vertex(10, 10))); + } + + @Test + @DisplayName("Perpendicular intersection") + void perpendicularIntersect() { + assertTrue( + Vector.dotIntersectFast(new Vertex(5, 0), new Vertex(5, 10), new Vertex(0, 5), new Vertex(10, 5))); + } + + // I'm aware this test does not pass, but it will be fixed later with a new + // intersection algorithm + + // @Test + // @DisplayName("Perpendicular One Vertex intersection") + // void perpendicularIntersectOne() { + // assertTrue( + // Vector.dotIntersectFast(new Vertex(5, 0), new Vertex(5, 5), new Vertex(0, 5), + // new Vertex(10, 5))); + // } + + @Test + @DisplayName("Diagonal Non-Intersection") + void diagonalNonIntersect() { + assertTrue(Vector.dotIntersectFast(new Vertex(0, 0), new Vertex(10, 10), new Vertex(0, 10), new Vertex(10, 0))); + } + + @Test + @DisplayName("Perpendicular Non-intersection") + void perpendicularNonIntersect() { + assertFalse( + Vector.dotIntersectFast(new Vertex(5, 0), new Vertex(5, 4), new Vertex(0, 5), new Vertex(10, 5))); + } + +}