mirror of
https://github.com/davpapp/PowerMiner
synced 2024-12-21 23:48:49 -05:00
Added basic tests for Point, MousePath, and Mouse
This commit is contained in:
parent
c56c246d4a
commit
5fa3894245
BIN
bin/Mouse.class
BIN
bin/Mouse.class
Binary file not shown.
Binary file not shown.
BIN
bin/MousePathTest.class
Normal file
BIN
bin/MousePathTest.class
Normal file
Binary file not shown.
BIN
bin/Point.class
BIN
bin/Point.class
Binary file not shown.
BIN
bin/PointTest.class
Normal file
BIN
bin/PointTest.class
Normal file
Binary file not shown.
@ -46,7 +46,7 @@ public class Mouse {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (point.hasSameLocation(lastPoint)) {
|
||||
if (point.isSameLocation(lastPoint)) {
|
||||
numberOfRepeats++;
|
||||
if (numberOfRepeats == 20) {
|
||||
if (currentPath.size() < 5) {
|
||||
|
@ -33,6 +33,10 @@ public class MousePath {
|
||||
return numPoints;
|
||||
}
|
||||
|
||||
public int getTimespan() {
|
||||
return timespan;
|
||||
}
|
||||
|
||||
public void display() {
|
||||
for (Point p : path) {
|
||||
System.out.println("(" + p.getX() + ", " + p.getY() + "), " + p.getTime());
|
||||
|
40
src/MousePathTest.java
Normal file
40
src/MousePathTest.java
Normal file
@ -0,0 +1,40 @@
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class MousePathTest {
|
||||
|
||||
Mouse mouse = new Mouse("/home/dpapp/eclipse-workspace/RunescapeAI/testfiles/mouse_path_test1.txt");
|
||||
ArrayList<MousePath> mousePaths = mouse.getMousePaths();
|
||||
|
||||
@Test
|
||||
void mousePathLengthTest() {
|
||||
assertEquals(mousePaths.get(0).getNumPoints(), 45);
|
||||
assertEquals(mousePaths.get(1).getNumPoints(), 17);
|
||||
assertEquals(mousePaths.get(2).getNumPoints(), 33);
|
||||
assertEquals(mousePaths.get(3).getNumPoints(), 14);
|
||||
assertEquals(mousePaths.get(4).getNumPoints(), 13);
|
||||
}
|
||||
|
||||
@Test
|
||||
void mousePathTimespanTest() {
|
||||
assertEquals(mousePaths.get(0).getTimespan(), 1225);
|
||||
assertEquals(mousePaths.get(1).getTimespan(), 192);
|
||||
assertEquals(mousePaths.get(2).getTimespan(), 458);
|
||||
assertEquals(mousePaths.get(3).getTimespan(), 157);
|
||||
assertEquals(mousePaths.get(4).getTimespan(), 142);
|
||||
}
|
||||
|
||||
@Test
|
||||
void mousePathStartingPointTest() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void mousePathEndingPointTest() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -26,10 +26,14 @@ public class Point {
|
||||
return time;
|
||||
}
|
||||
|
||||
public boolean hasSameLocation(Point p2) {
|
||||
public boolean isSameLocation(Point p2) {
|
||||
return (this.x == p2.getX() && this.y == p2.getY());
|
||||
}
|
||||
|
||||
public double distance(Point p2) {
|
||||
return Math.hypot(this.x - p2.getX(), this.y - p2.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
@ -46,6 +50,6 @@ public class Point {
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return (x >= 0 && x < 1920 && y >= 0 && y < 1920 && time >= 0);
|
||||
return (x >= 0 && x < 1920 && y >= 0 && y < 1080 && time >= 0);
|
||||
}
|
||||
}
|
60
src/PointTest.java
Normal file
60
src/PointTest.java
Normal file
@ -0,0 +1,60 @@
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PointTest {
|
||||
|
||||
@Test
|
||||
void initializePointTest() {
|
||||
Point p = new Point(54, 4, 134);
|
||||
assertEquals(p.getX(), 54);
|
||||
assertEquals(p.getY(), 4);
|
||||
assertEquals(p.getTime(), 134);
|
||||
}
|
||||
|
||||
@Test
|
||||
void isValidPointTest() {
|
||||
Point p1 = new Point(54, 4, 134);
|
||||
assertEquals(p1.isValid(), true);
|
||||
|
||||
Point p2 = new Point(-3, 84, 832);
|
||||
assertEquals(p2.isValid(), false);
|
||||
|
||||
Point p3 = new Point(1940, 84, 832);
|
||||
assertEquals(p3.isValid(), false);
|
||||
|
||||
Point p4 = new Point(3, -5, 832);
|
||||
assertEquals(p4.isValid(), false);
|
||||
|
||||
Point p5 = new Point(0, 1084, 832);
|
||||
assertEquals(p5.isValid(), false);
|
||||
|
||||
Point p6 = new Point(0, 1001, -4);
|
||||
assertEquals(p6.isValid(), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void isSameLocationTest() {
|
||||
Point p1 = new Point(54, 4, 134);
|
||||
Point p2 = new Point(54, 4, 832);
|
||||
Point p3 = new Point(85, 4, 832);
|
||||
Point p4 = new Point(54, 12, 832);
|
||||
assertEquals(p1.isSameLocation(p2), true);
|
||||
assertEquals(p1.isSameLocation(p3), false);
|
||||
assertEquals(p1.isSameLocation(p4), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void distanceTest() {
|
||||
Point p1 = new Point(54, 4, 134);
|
||||
Point p2 = new Point(54, 4, 832);
|
||||
Point p3 = new Point(85, 4, 832);
|
||||
Point p4 = new Point(85, 12, 832);
|
||||
|
||||
assertEquals(p1.distance(p2), 0.0);
|
||||
assertEquals(p1.distance(p3), 31.0);
|
||||
|
||||
double distance = p1.distance(p4) - 32.01562118;
|
||||
assertTrue(distance >= 0 && distance < 0.00001);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user