jiayuasu commented on code in PR #1992: URL: https://github.com/apache/sedona/pull/1992#discussion_r2168133578
########## common/src/test/java/org/apache/sedona/common/S2Geography/PointGeographyTest.java: ########## @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sedona.common.S2Geography; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import com.google.common.geometry.*; +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; + +public class PointGeographyTest { + @Test + public void testEncodeTag() throws IOException { + // 1) Create an empty geography + PointGeography geog = new PointGeography(); + assertEquals(S2Geography.GeographyKind.POINT, geog.kind); + assertEquals(0, geog.numShapes()); + // Java returns -1 for no shapes; if yours returns 0, adjust accordingly + assertEquals(-1, geog.dimension()); + assertTrue(geog.getPoints().isEmpty()); + + // 2) Encode into a ByteArrayOutputStream + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + geog.encodeTagged(baos, new EncodeOptions()); + byte[] data = baos.toByteArray(); + assertEquals(4, data.length); + + // 2) Create a single-point geography at lat=45°, lng=-64° + S2Point pt = S2LatLng.fromDegrees(45, -64).toPoint(); + PointGeography geog2 = new PointGeography(pt); + assertEquals(1, geog2.numShapes()); + assertEquals(0, geog2.dimension()); + List<S2Point> originalPts = geog2.getPoints(); + assertEquals(1, originalPts.size()); + assertEquals(pt, originalPts.get(0)); + + // 3) EncodeTagged + ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); + geog2.encodeTagged(baos2, new EncodeOptions()); + byte[] data2 = baos2.toByteArray(); + // should be >4 bytes (header+payload) + assertTrue(data2.length > 4); + } + + @Test + public void testEmptyPointEncodeDecode() throws IOException { + // 1) Create an empty geography + PointGeography geog = new PointGeography(); + TestHelper.assertRoundTrip(geog, new EncodeOptions()); + } + + @Test + public void testEncodedPoint() throws IOException { + // 1) Create a single-point geography at lat=45°, lng=-64° + S2Point pt = S2LatLng.fromDegrees(45, -64).toPoint(); + PointGeography geog = new PointGeography(pt); + TestHelper.assertRoundTrip(geog, new EncodeOptions()); + } + + @Test + public void testEncodedSnappedPoint() throws IOException { + // 1) Build the original point and its snapped-to-cell-center version + S2Point pt = S2LatLng.fromDegrees(45, -64).toPoint(); + S2CellId cellId = S2CellId.fromPoint(pt); + S2Point ptSnapped = cellId.toPoint(); + System.out.println(ptSnapped.toString()); Review Comment: Please remove `print` command. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
