JTSTestBuilder之TestCase类的runtest()方法

发布时间 2023-08-30 14:54:21作者: 2086nmj

测试之前首先要给GeometryA和GeometryB赋值。

public void runTest() throws ParseException {
        failed = false;
        isRun = true;
        initGeometry();
        if (expectedIM != null) {
            IntersectionMatrix im = null;
            if (geom[0] != null && geom[1] != null) {
                im = relate(geom[0], geom[1]);
            }
            if (im != null) {
                String msg = " expected " + expectedIM + ", found " + im.toString();
                assertTrue(im.matches(expectedIM), msg);
            }
        }
        if (expectedBoundary != null) {
            Geometry result = geom[0].getBoundary();
            assertEqualsExact(expectedBoundary, result, " expected boundary "
                    + expectedBoundary.toText() + " , found " + result.toText());
        }
        if (expectedConvexHull != null) {
            Geometry result = geom[0].convexHull();
            assertEqualsExact(expectedConvexHull, result, " expected convex hull "
                    + expectedConvexHull.toText() + " , found " + result.toText());
        }
        if (expectedIntersection != null) {
            Geometry result = geom[0].intersection(geom[1]);
            assertEqualsExact(expectedIntersection, result, " expected intersection "
                    + expectedIntersection.toText() + " , found " + result.toText());
        }
        if (expectedUnion != null) {
            Geometry result = geom[0].union(geom[1]);
            assertEqualsExact(expectedUnion, result, " expected union "
                    + expectedUnion.toText() + " , found " + result.toText());
        }
        if (expectedDifference != null) {
            Geometry result = geom[0].difference(geom[1]);
            assertEqualsExact(expectedDifference, result, " expected difference "
                    + expectedDifference.toText() + " , found " + result.toText());
        }
        if (expectedSymDifference != null) {
            Geometry result = geom[0].symDifference(geom[1]);
            assertEqualsExact(expectedSymDifference, result, " expected sym difference "
                    + expectedSymDifference.toText() + " , found " + result.toText());
        }
    }

第一步先判断expectedIM是否为空。expectedIM表示需要进行验证的相交矩阵。如果它不为空,表示需要对该项测试进行验证。