PowerMiner/src/CursorPathTest.java

116 lines
4.8 KiB
Java
Raw Normal View History

2018-02-04 15:34:27 -05:00
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import org.junit.jupiter.api.Test;
class CursorPathTest {
ArrayList<CursorPath> cursorPaths;
@Test
2018-02-15 06:27:12 -05:00
void testCursorPaths() {
2018-02-04 15:34:27 -05:00
initializeCursorPath();
for (CursorPath cursorPath : cursorPaths) {
//cursorPath.displayCursorPoints();
2018-02-15 06:27:12 -05:00
2018-02-04 15:34:27 -05:00
testCursorPathStartsAtOrigin(cursorPath);
testEndingCursorPointInCursorPathHasZeroDelay(cursorPath);
2018-02-12 19:40:09 -05:00
testCursorPathDistance(cursorPath);
testCursorPathTheta(cursorPath);
2018-02-15 06:27:12 -05:00
2018-02-12 19:40:09 -05:00
testCursorPathRotation(cursorPath, Math.PI);
2018-02-15 06:27:12 -05:00
testCursorPathRotation(cursorPath, 7 / 4 * Math.PI);
//testCursorPathRotation(cursorPath, 10.32184);
//testCursorPathRotation(cursorPath, 0.01372);
//testCursorPathRotation(cursorPath, -0.0001238);
//testCursorPathRotation(cursorPath, 0);
2018-02-04 15:34:27 -05:00
testCursorPathScaling(cursorPath, 1.15);
testCursorPathScaling(cursorPath, 0.48324);
testCursorPathScaling(cursorPath, 0.9999);
testCursorPathScaling(cursorPath, 1.8431838);
testCursorPathScaling(cursorPath, 2.10004);
testCursorPathScaling(cursorPath, 1.15);
testCursorPathScaling(cursorPath, 1.001010101);
testCursorPathScaling(cursorPath, 1.523521);
testCursorPathScaling(cursorPath, 1.12366);
testCursorPathScaling(cursorPath, 0.974324);
testCursorPathScaling(cursorPath, 0.72134);
2018-02-15 06:27:12 -05:00
//testDelays(cursorPath);
2018-02-04 15:34:27 -05:00
}
}
2018-02-15 06:27:12 -05:00
private void initializeCursorPath() {
CursorDataFileParser cursorDataFileParser = new CursorDataFileParser("/home/dpapp/eclipse-workspace/RunescapeAI/testfiles/cursorPathTest.txt");
this.cursorPaths = cursorDataFileParser.getArrayListOfCursorPathsFromFile();
}
2018-02-04 15:34:27 -05:00
private void testCursorPathStartsAtOrigin(CursorPath cursorPath) {
CursorPoint startingCursorPoint = cursorPath.getStartingCursorPoint();
assertTrue(startingCursorPoint.x == 0 && startingCursorPoint.y == 0);
}
private void testEndingCursorPointInCursorPathHasZeroDelay(CursorPath cursorPath) {
CursorPoint endingCursorPoint = cursorPath.getEndingCursorPoint();
2018-02-15 06:27:12 -05:00
assertEquals(0, endingCursorPoint.delay);
2018-02-04 15:34:27 -05:00
}
2018-02-12 19:40:09 -05:00
private void testCursorPathDistance(CursorPath cursorPath) {
2018-02-15 06:27:12 -05:00
int cursorPathDistance = cursorPath.getCursorPathDistance();
2018-02-12 19:40:09 -05:00
CursorPoint startingCursorPoint = cursorPath.getStartingCursorPoint();
CursorPoint endingCursorPoint = cursorPath.getEndingCursorPoint();
2018-02-15 06:27:12 -05:00
startingCursorPoint.display();
endingCursorPoint.display();
int expectedDistance = (int) Math.hypot(startingCursorPoint.x - endingCursorPoint.x, startingCursorPoint.y - endingCursorPoint.y);
assertEquals(expectedDistance, cursorPathDistance);
2018-02-12 19:40:09 -05:00
}
private void testCursorPathTheta(CursorPath cursorPath) {
double theta = cursorPath.getCursorPathTheta();
2018-02-15 06:27:12 -05:00
CursorPoint startingCursorPoint = cursorPath.getStartingCursorPoint();
2018-02-12 19:40:09 -05:00
CursorPoint endingCursorPoint = cursorPath.getEndingCursorPoint();
2018-02-15 06:27:12 -05:00
double actualTheta = Math.atan2(endingCursorPoint.x - startingCursorPoint.x, endingCursorPoint.y - startingCursorPoint.y);
2018-02-12 19:40:09 -05:00
assertEquals(theta, actualTheta);
}
2018-02-04 15:34:27 -05:00
2018-02-15 06:27:12 -05:00
void testCursorPathRotation(CursorPath cursorPath, double angleToRotateTo) {
CursorPath rotatedCursorPath = cursorPath.getRotatedCopyOfCursorPath(angleToRotateTo);
assertEquals(angleToRotateTo % Math.PI, ((rotatedCursorPath.getCursorPathTheta() % Math.PI) + Math.PI) % Math.PI, 0.01);
2018-02-15 06:27:12 -05:00
2018-02-04 15:34:27 -05:00
ArrayList<CursorPoint> cursorPoints = cursorPath.getCursorPathPoints();
2018-02-15 06:27:12 -05:00
ArrayList<CursorPoint> rotatedCursorPoints = rotatedCursorPath.getCursorPathPoints();
2018-02-04 15:34:27 -05:00
assertEquals(cursorPoints.size(), rotatedCursorPoints.size());
assertEquals(cursorPath.getStartingCursorPoint().x, rotatedCursorPath.getStartingCursorPoint().x);
assertEquals(cursorPath.getStartingCursorPoint().y, rotatedCursorPath.getStartingCursorPoint().y);
2018-02-15 06:27:12 -05:00
2018-02-04 15:34:27 -05:00
}
void testDelays(CursorPath cursorPath) {
2018-02-15 06:27:12 -05:00
CursorPath rotatedCursorPath = cursorPath.getRotatedCopyOfCursorPath(2.3 / 9.0 * Math.PI);
2018-02-04 15:34:27 -05:00
ArrayList<CursorPoint> cursorPoints = cursorPath.getCursorPathPoints();
2018-02-15 06:27:12 -05:00
ArrayList<CursorPoint> rotatedCursorPoints = rotatedCursorPath.getCursorPathPoints();
assertEquals(cursorPoints.size(), rotatedCursorPoints.size());
2018-02-04 15:34:27 -05:00
for (int i = 0; i < cursorPoints.size(); i++) {
2018-02-15 06:27:12 -05:00
assertEquals(cursorPoints.get(i).delay, rotatedCursorPoints.get(i).delay);
2018-02-04 15:34:27 -05:00
}
}
2018-02-15 06:27:12 -05:00
void testCursorPathScaling(CursorPath cursorPath, double factorToScaleBy) {
CursorPath scaledCursorPath = cursorPath.getScaledCopyOfCursorPath(factorToScaleBy);
ArrayList<CursorPoint> cursorPoints = cursorPath.getCursorPathPoints();
ArrayList<CursorPoint> scaledCursorPoints = scaledCursorPath.getCursorPathPoints();
assertEquals(cursorPoints.size(), scaledCursorPoints.size());
assertEquals(cursorPath.getStartingCursorPoint().x, scaledCursorPath.getStartingCursorPoint().x);
assertEquals(cursorPath.getStartingCursorPoint().y, scaledCursorPath.getStartingCursorPoint().y);
assertEquals(cursorPath.getCursorPathDistance() * factorToScaleBy, scaledCursorPath.getCursorPathDistance(), 3);
2018-02-04 15:34:27 -05:00
}
}