@Test public void pointWithinChannel() { DR = DataReader.use("equationTestNodes.txt", "equationTestEdges.txt"); DR.createNodeList(); Edge edge = new Edge( DR.getNodes().get(1), DR.getNodes().get(2), 0, "", 0, "0", "0", 0.1, 0, 0, 0, 0, true); assertFalse(Equation.pointWithinChannel(-3.0, 4.0, edge)); assertTrue(Equation.pointWithinChannel(4.0, 5.0, edge)); }
@Test public void distanceBetweenNodes() { DR = DataReader.use("equationTestNodes.txt", "equationTestEdges.txt"); DR.createNodeList(); Node node1 = DR.getNodes().get(1); Node node2 = DR.getNodes().get(2); Node node5 = DR.getNodes().get(5); assertEquals(5.0, Equation.distanceBetweenNodes(node1, node2), 0.001); assertFalse(Math.abs(Equation.distanceBetweenNodes(node2, node5) - 5.0) < 0.001); }
@Test public void getNormalVector() { DR = DataReader.use("equationTestNodes.txt", "equationTestEdges.txt"); DR.createNodeList(); Edge edge = new Edge( DR.getNodes().get(1), DR.getNodes().get(2), 0, "", 0, "0", "0", 0.1, 0, 0, 0, 0, true); double[] expArr = new double[] {-3.0, 4.0}; double[] expArr2 = new double[] {-3.3, 4.1}; assertArrayEquals(expArr, Equation.getNormalVector(edge), 0.001); assertFalse(Math.abs(expArr2[0] - Equation.getNormalVector(edge)[0]) < 0.001); assertFalse(Math.abs(expArr2[1] - Equation.getNormalVector(edge)[1]) < 0.001); }
@Test public void nodesToVector() { DR = DataReader.use("equationTestNodes.txt", "equationTestEdges.txt"); DR.createNodeList(); Node node5 = DR.getNodes().get(5); Node node1 = DR.getNodes().get(1); double[] expArr = new double[] {-3.0, 1.0}; assertArrayEquals(expArr, Equation.nodesToVector(node5, node1), 0.01); Node node2 = DR.getNodes().get(2); Node node3 = DR.getNodes().get(3); double[] expArr2 = new double[] {4.3, 3.2}; assertFalse(Math.abs(expArr2[0] - Equation.nodesToVector(node2, node3)[0]) < 0.001); assertFalse(Math.abs(expArr2[1] - Equation.nodesToVector(node2, node3)[1]) < 0.001); }
@Test public void distanceBetweenPointAndLine() { DR = DataReader.use("equationTestNodes.txt", "equationTestEdges.txt"); DR.createNodeList(); Edge edge = new Edge( DR.getNodes().get(1), DR.getNodes().get(2), 0, "", 0, "0", "0", 0.1, 0, 0, 0, 0, true); double x1 = 1.0; double y1 = 7.5; assertEquals(5.0, Equation.distanceBetweenPointAndLine(edge, x1, y1), 0.001); double x2 = 1.0; double y2 = 9.5; assertFalse(Math.abs(Equation.distanceBetweenPointAndLine(edge, x2, y2) - 7.0) < 0.001); }
@Test public void edgeToVector() { DR = DataReader.use("equationTestNodes.txt", "equationTestEdges.txt"); DR.createNodeList(); Edge edge1 = new Edge( DR.getNodes().get(1), DR.getNodes().get(2), 0, "", 0, "0", "0", 0.1, 0, 0, 0, 0, true); Edge edge2 = new Edge( DR.getNodes().get(2), DR.getNodes().get(3), 0, "", 0, "0", "0", 0.1, 0, 0, 0, 0, true); Edge edge3 = new Edge( DR.getNodes().get(3), DR.getNodes().get(4), 0, "", 0, "0", "0", 0.1, 0, 0, 0, 0, true); double[] expArr1 = new double[] {4.0, 3.0}; double[] expArr2 = new double[] {-7.0, 1.0}; double[] expArr3 = new double[] {-2.0, -4.0}; assertArrayEquals(expArr1, Equation.edgeToVector(edge1), 0.001); assertArrayEquals(expArr2, Equation.edgeToVector(edge2), 0.001); assertArrayEquals(expArr3, Equation.edgeToVector(edge3), 0.001); double[] expArr4 = new double[] {1.0, 3.1}; double[] expArr5 = new double[] {-7.5, 2.0}; double[] expArr6 = new double[] {2.0, -4.7}; assertFalse(Math.abs(expArr4[0] - Equation.edgeToVector(edge1)[0]) < 0.001); assertFalse(Math.abs(expArr4[1] - Equation.edgeToVector(edge1)[1]) < 0.001); assertFalse(Math.abs(expArr5[0] - Equation.edgeToVector(edge2)[0]) < 0.001); assertFalse(Math.abs(expArr5[1] - Equation.edgeToVector(edge2)[1]) < 0.001); assertFalse(Math.abs(expArr6[0] - Equation.edgeToVector(edge3)[0]) < 0.001); assertFalse(Math.abs(expArr6[1] - Equation.edgeToVector(edge3)[1]) < 0.001); }