Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into minor-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nab138 committed Jul 17, 2024
2 parents ba5a609 + 47ebd92 commit 1f0379f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Pathfinding/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ gradle-app.setting

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties
gradle.properties
13 changes: 10 additions & 3 deletions Pathfinding/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
"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"
}
15 changes: 15 additions & 0 deletions Pathfinding/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)));
}

}

0 comments on commit 1f0379f

Please sign in to comment.