Skip to content

Commit

Permalink
Start Testing MathUtil
Browse files Browse the repository at this point in the history
One ignored
One todo added
  • Loading branch information
Mineinjava committed Jul 30, 2024
1 parent 42f1a4d commit b1c353d
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions quail/src/test/java/quail/util/MathUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (C) Marcus Kauffman 2023-Present

// This work would not have been possible without the work of many
// contributors, most notably Colin Montigel. See ACKNOWLEDGEMENT.md for
// more details.

// This file is part of Quail.

// Quail is free software: you can redistribute it and/or modify it
// underthe terms of the GNU General Public License as published by the
// Free Software Foundation, version 3.

// Quail 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 General Public License
// for more details.

// You should have received a copy of the GNU General Public License
// along with Quail. If not, see <https://www.gnu.org/licenses/>

package quail.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Disabled;

import com.mineinjava.quail.util.MathUtil;
import com.mineinjava.quail.util.geometry.Pose2d;
import org.junit.jupiter.api.Test;

public class MathUtilTest {
@Test
void EpsilionEquals() {
assertTrue(
MathUtil.epsilonEquals(0, 1e-7),
"a difference of less than the epsilon should return true");
assertFalse(
MathUtil.epsilonEquals(0, 1e-5),
"a difference of greater than the epsilon should return false");
}

@Test
void SkewerCircle(){
assertTrue(
MathUtil.LineSegHitCircle(
new Pose2d(0, -1, 0), new Pose2d(0, 1, 0), new Pose2d(0, 0, 0), 0.1),
"skewer");
}
@Test
@Disabled
void PopCircle() { //TODO: Fix the function do make this work
assertTrue(
MathUtil.LineSegHitCircle(
new Pose2d(0, 0, 0), new Pose2d(1, 1, 0), new Pose2d(0, 0, 0), 1),
"pop");
}
@Test
void InsideCircle() {
assertFalse(
MathUtil.LineSegHitCircle(
new Pose2d(-1, -1, 0), new Pose2d(1, 1, 0), new Pose2d(0, 0, 0), 10),
"inside");
}
@Test
void MissCircle() {
assertFalse(
MathUtil.LineSegHitCircle(
new Pose2d(-1, -1, 0), new Pose2d(1, 1, 0), new Pose2d(0, -10, 0), 1),
"miss");
}

@Test
void Lerp() {
assertEquals(5, MathUtil.lerp(0, 10, 0.5));
}
}

0 comments on commit b1c353d

Please sign in to comment.