-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |