• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.geojson;
2 
3 import org.junit.Assert;
4 import org.junit.Test;
5 
6 public class LngLatAltTest {
7 
8 	@Test
should_LngLatAlt_equals_without_alt()9 	public void should_LngLatAlt_equals_without_alt() {
10 		LngLatAlt first = new LngLatAlt(14.D, 13.D);
11 		LngLatAlt second = new LngLatAlt(14.D, 13.D);
12 		Assert.assertEquals(second, first);
13 	}
14 
15 	@Test
should_LngLatAlt_equals_with_alt()16 	public void should_LngLatAlt_equals_with_alt() {
17 		LngLatAlt first = new LngLatAlt(14.D, 13.D, 15D);
18 		LngLatAlt second = new LngLatAlt(14.D, 13.D, 15D);
19 		Assert.assertEquals(second, first);
20 	}
21 
22 	@Test
should_not_LngLatAlt_equals_with_alt()23 	public void should_not_LngLatAlt_equals_with_alt() {
24 		LngLatAlt first = new LngLatAlt(14.D, 13.D, 15D);
25 		LngLatAlt second = new LngLatAlt(14.D, 13.D, 16D);
26 		Assert.assertNotEquals(second, first);
27 	}
28 
29 	@Test
should_not_LngLatAlt_equals_without_alt()30 	public void should_not_LngLatAlt_equals_without_alt() {
31 		LngLatAlt first = new LngLatAlt(14.D, 14.D, 15D);
32 		LngLatAlt second = new LngLatAlt(14.D, 13.D, 16D);
33 		Assert.assertNotEquals(second, first);
34 	}
35 
36 	@Test
should_LngLatAlt_equals_with_additional_elements()37 	public void should_LngLatAlt_equals_with_additional_elements() {
38 		LngLatAlt first = new LngLatAlt(14.D, 14.D, 15D, 16D, 17D);
39 		LngLatAlt second = new LngLatAlt(14.D, 14.D, 15D, 16D, 17D);
40 		Assert.assertEquals(second, first);
41 		Assert.assertEquals(second.hashCode(), first.hashCode());
42 	}
43 
44 	@Test
should_LngLatAlt_equals_with_additional_elements_and_null()45 	public void should_LngLatAlt_equals_with_additional_elements_and_null() {
46 		LngLatAlt first = new LngLatAlt(14.D, 14.D, 15D, 16D, 17D);
47 		LngLatAlt second = new LngLatAlt(14.D, 14.D, 15D, 16D, 17D);
48 		Assert.assertEquals(second, first);
49 		Assert.assertEquals(second.hashCode(), first.hashCode());
50 	}
51 
52 	@Test
should_not_LngLatAlt_equals_without_additional_elements()53 	public void should_not_LngLatAlt_equals_without_additional_elements() {
54 		LngLatAlt first = new LngLatAlt(14.D, 14.D, 15D, 16D, 17D);
55 		LngLatAlt second = new LngLatAlt(14.D, 14.D, 15D);
56 		Assert.assertNotEquals(second, first);
57 		Assert.assertNotEquals(second.hashCode(), first.hashCode());
58 	}
59 
60 	@Test
should_not_LngLatAlt_equals_with_additional_elements_in_different_order()61 	public void should_not_LngLatAlt_equals_with_additional_elements_in_different_order() {
62 		LngLatAlt first = new LngLatAlt(14.D, 14.D, 15D, 16D, 17D);
63 		LngLatAlt second = new LngLatAlt(14.D, 14.D, 15D, 17D, 16D);
64 		Assert.assertNotEquals(second, first);
65 		Assert.assertNotEquals(second.hashCode(), first.hashCode());
66 	}
67 
68 	@Test
should_not_LngLatAlt_equals_with_additional_elements_and_different_size()69 	public void should_not_LngLatAlt_equals_with_additional_elements_and_different_size() {
70 		LngLatAlt first = new LngLatAlt(14.D, 14.D, 15D, 16D, 17D);
71 		LngLatAlt second = new LngLatAlt(14.D, 14.D, 15D, 16D, 17D, 18D);
72 		Assert.assertNotEquals(second, first);
73 		Assert.assertNotEquals(second.hashCode(), first.hashCode());
74 	}
75 
76 	@Test
should_LngLatAlt_throw_if_alt_not_specified_in_constructor()77 	public void should_LngLatAlt_throw_if_alt_not_specified_in_constructor() {
78 		try {
79 			new LngLatAlt(14.D, 14.D, Double.NaN, 16D, 17D);
80 			Assert.fail("Additional elements are not allowed if altitude is Nan.");
81 		} catch (IllegalArgumentException e) {
82 			Assert.assertTrue("Expected exception.", true);
83 		}
84 	}
85 
86 	@Test
should_LngLatAlt_throw_if_alt_set_to_Nan_with_additional_elements()87 	public void should_LngLatAlt_throw_if_alt_set_to_Nan_with_additional_elements() {
88 		LngLatAlt lngLatAlt = new LngLatAlt(14.D, 14.D, 15.D, 16D, 17D);
89 
90 		try {
91 			lngLatAlt.setAltitude(Double.NaN);
92 			Assert.fail("Additional elements are not allowed if altitude is Nan.");
93 		} catch (IllegalArgumentException e) {
94 			Assert.assertTrue("Expected exception.", true);
95 		}
96 	}
97 
98 	@Test
should_LngLatAlt_throw_if_additional_elements_set_with_missing_alt()99 	public void should_LngLatAlt_throw_if_additional_elements_set_with_missing_alt() {
100 		LngLatAlt lngLatAlt = new LngLatAlt(14.D, 14.D);
101 
102 		try {
103 			lngLatAlt.setAdditionalElements(42);
104 			Assert.fail("Additional elements are not allowed if altitude is Nan.");
105 		} catch (IllegalArgumentException e) {
106 			Assert.assertTrue("Expected exception.", true);
107 		}
108 	}
109 
110 	@Test
should_LngLatAlt_throw_if_additional_elements_set_with_Nan_alt()111 	public void should_LngLatAlt_throw_if_additional_elements_set_with_Nan_alt() {
112 		LngLatAlt lngLatAlt = new LngLatAlt(14.D, 14.D, Double.NaN);
113 
114 		try {
115 			lngLatAlt.setAdditionalElements(42);
116 			Assert.fail("Additional elements are not allowed if altitude is Nan.");
117 		} catch (IllegalArgumentException e) {
118 			Assert.assertTrue("Expected exception.", true);
119 		}
120 	}
121 
122 	@Test
should_LngLatAlt_throw_if_any_additional_elements_constructed_to_Nan()123 	public void should_LngLatAlt_throw_if_any_additional_elements_constructed_to_Nan() {
124 		try {
125 			new LngLatAlt(14.D, 14.D, 15.D, 16.D, Double.NaN, 17.D);
126 			Assert.fail("Additional elements are not allowed to be Nan.");
127 		} catch (IllegalArgumentException e) {
128 			Assert.assertTrue("Expected exception.", true);
129 		}
130 	}
131 
132 	@Test
should_LngLatAlt_throw_if_any_additional_elements_constructed_to_Positive_Infinity()133 	public void should_LngLatAlt_throw_if_any_additional_elements_constructed_to_Positive_Infinity() {
134 		try {
135 			new LngLatAlt(14.D, 14.D, 15.D, 16.D, Double.POSITIVE_INFINITY, 17.D);
136 			Assert.fail("Additional elements are not allowed to be positive infinity.");
137 		} catch (IllegalArgumentException e) {
138 			Assert.assertTrue("Expected exception.", true);
139 		}
140 	}
141 
142 	@Test
should_LngLatAlt_throw_if_any_additional_elements_constructed_to_Negative_Infinity()143 	public void should_LngLatAlt_throw_if_any_additional_elements_constructed_to_Negative_Infinity() {
144 		try {
145 			new LngLatAlt(14.D, 14.D, 15.D, 16.D, Double.NEGATIVE_INFINITY, 17.D);
146 			Assert.fail("Additional elements are not allowed to be positive infinity.");
147 		} catch (IllegalArgumentException e) {
148 			Assert.assertTrue("Expected exception.", true);
149 		}
150 	}
151 
152 	@Test
should_LngLatAlt_throw_if_any_additional_elements_set_to_Nan()153 	public void should_LngLatAlt_throw_if_any_additional_elements_set_to_Nan() {
154 		LngLatAlt lngLatAlt = new LngLatAlt(14.D, 14.D, 15.D);
155 		try {
156 			lngLatAlt.setAdditionalElements(16.D, Double.NaN, 17.D);
157 			Assert.fail("Additional elements are not allowed to be Nan.");
158 		} catch (IllegalArgumentException e) {
159 			Assert.assertTrue("Expected exception.", true);
160 		}
161 	}
162 
163 	@Test
should_LngLatAlt_throw_if_any_additional_elements_set_to_Positive_Infinity()164 	public void should_LngLatAlt_throw_if_any_additional_elements_set_to_Positive_Infinity() {
165 		LngLatAlt lngLatAlt = new LngLatAlt(14.D, 14.D, 15.D);
166 		try {
167 			lngLatAlt.setAdditionalElements(16.D, Double.POSITIVE_INFINITY, 17.D);
168 			Assert.fail("Additional elements are not allowed to be positive infinity.");
169 		} catch (IllegalArgumentException e) {
170 			Assert.assertTrue("Expected exception.", true);
171 		}
172 	}
173 
174 	@Test
should_LngLatAlt_throw_if_any_additional_elements_set_to_Negative_Infinity()175 	public void should_LngLatAlt_throw_if_any_additional_elements_set_to_Negative_Infinity() {
176 		LngLatAlt lngLatAlt = new LngLatAlt(14.D, 14.D, 15.D);
177 		try {
178 			lngLatAlt.setAdditionalElements(16.D, Double.NEGATIVE_INFINITY, 17.D);
179 			Assert.fail("Additional elements are not allowed to be positive infinity.");
180 		} catch (IllegalArgumentException e) {
181 			Assert.assertTrue("Expected exception.", true);
182 		}
183 	}
184 }