diff --git a/bin/Mouse.class b/bin/Mouse.class index 20717de..e2e80ea 100644 Binary files a/bin/Mouse.class and b/bin/Mouse.class differ diff --git a/bin/MousePath.class b/bin/MousePath.class index 9bce8a6..1297fa2 100644 Binary files a/bin/MousePath.class and b/bin/MousePath.class differ diff --git a/bin/MousePathTest.class b/bin/MousePathTest.class new file mode 100644 index 0000000..7548ca0 Binary files /dev/null and b/bin/MousePathTest.class differ diff --git a/bin/Point.class b/bin/Point.class index 8b3b6dc..edb2aba 100644 Binary files a/bin/Point.class and b/bin/Point.class differ diff --git a/bin/PointTest.class b/bin/PointTest.class new file mode 100644 index 0000000..2f98a11 Binary files /dev/null and b/bin/PointTest.class differ diff --git a/src/Mouse.java b/src/Mouse.java index 3e84ee0..fcd3241 100644 --- a/src/Mouse.java +++ b/src/Mouse.java @@ -46,7 +46,7 @@ public class Mouse { continue; } - if (point.hasSameLocation(lastPoint)) { + if (point.isSameLocation(lastPoint)) { numberOfRepeats++; if (numberOfRepeats == 20) { if (currentPath.size() < 5) { diff --git a/src/MousePath.java b/src/MousePath.java index bad40da..876447d 100644 --- a/src/MousePath.java +++ b/src/MousePath.java @@ -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()); diff --git a/src/MousePathTest.java b/src/MousePathTest.java new file mode 100644 index 0000000..38232fc --- /dev/null +++ b/src/MousePathTest.java @@ -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 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() { + + } + +} diff --git a/src/Point.java b/src/Point.java index 26313e6..c25db5e 100644 --- a/src/Point.java +++ b/src/Point.java @@ -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); } } \ No newline at end of file diff --git a/src/PointTest.java b/src/PointTest.java new file mode 100644 index 0000000..b41e598 --- /dev/null +++ b/src/PointTest.java @@ -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); + } +}