001/* 002 * Copyright 2020 Global Biodiversity Information Facility (GBIF) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.gbif.api.util; 017 018import org.junit.jupiter.api.Test; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021 022public class LengthUtilsTest { 023 024 @Test 025 public void testMetersToLatDegree() { 026 assertEquals(0.009043, LengthUtils.metersToLatDegree(1000), 0.0000001); 027 assertEquals(0.000904, LengthUtils.metersToLatDegree(100), 0.0000001); 028 assertEquals(0.00009, LengthUtils.metersToLatDegree(10), 0.0000001); 029 assertEquals(0.000045, LengthUtils.metersToLatDegree(5), 0.0000001); 030 assertEquals(0.000009, LengthUtils.metersToLatDegree(1), 0.0000001); 031 assertEquals(-0.000009, LengthUtils.metersToLatDegree(-1), 0.0000001); 032 033 assertEquals(0.0, LengthUtils.metersToLatDegree(0), 0.000001); 034 } 035 036 @Test 037 public void testLatDegreeToMeters() { 038 assertEquals(1000, LengthUtils.latDegreeToMeters(0.009044), 0.1); 039 assertEquals(100, LengthUtils.latDegreeToMeters(0.000904), 0.1); 040 assertEquals(10, LengthUtils.latDegreeToMeters(0.00009), 0.1); 041 assertEquals(5, LengthUtils.latDegreeToMeters(0.000045), 0.1); 042 assertEquals(1, LengthUtils.latDegreeToMeters(0.000009), 0.1); 043 044 assertEquals(0.0, LengthUtils.latDegreeToMeters(0), 0.000001); 045 } 046}