Skip to content

Commit 5b034f9

Browse files
committed
New test case added
1 parent d9ed359 commit 5b034f9

File tree

4 files changed

+147
-0
lines changed

4 files changed

+147
-0
lines changed

pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@
132132
<version>${junit.version}</version>
133133
<scope>test</scope>
134134
</dependency>
135+
<dependency>
136+
<groupId>org.mockito</groupId>
137+
<artifactId>mockito-core</artifactId>
138+
<version>3.12.4</version>
139+
<scope>test</scope>
140+
</dependency>
135141
<dependency>
136142
<groupId>org.openjdk.jol</groupId>
137143
<artifactId>jol-core</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.esri.core.geometry;
2+
3+
import junit.framework.TestCase;
4+
import org.junit.Test;
5+
public class TestEnvelope1D extends TestCase{
6+
@Test
7+
public void testCalculateToleranceFromEnvelopeEmpty() {
8+
Envelope1D envelope = new Envelope1D();
9+
envelope.setEmpty();
10+
double tolerance = envelope._calculateToleranceFromEnvelope();
11+
assertEquals(100.0 * NumberUtils.doubleEps(), tolerance, 0.0001);
12+
}
13+
14+
@Test
15+
public void testCalculateToleranceFromEnvelopeNonEmpty() {
16+
Envelope1D envelope = new Envelope1D(2.0, 4.0);
17+
double tolerance = envelope._calculateToleranceFromEnvelope();
18+
assertEquals(2.220446049250313e-14, tolerance, 1e-10);
19+
}
20+
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.esri.core.geometry;
2+
import org.junit.Test;
3+
import junit.framework.TestCase;
4+
public class TestIndexHashTable extends TestCase{
5+
@Test
6+
public void testAddElement() {
7+
IndexHashTable.HashFunction hashFunction = new IndexHashTable.HashFunction() {
8+
@Override
9+
public int getHash(int element) {
10+
return element % 10; // A simple hash function for testing
11+
}
12+
13+
@Override
14+
public boolean equal(int element1, int element2) {
15+
return element1 == element2;
16+
}
17+
18+
@Override
19+
public int getHash(Object elementDescriptor) {
20+
return ((Integer) elementDescriptor) % 10;
21+
}
22+
23+
@Override
24+
public boolean equal(Object elementDescriptor, int element) {
25+
return ((Integer) elementDescriptor) == element;
26+
}
27+
};
28+
29+
IndexHashTable hashTable = new IndexHashTable(10, hashFunction);
30+
31+
int element1 = 5;
32+
33+
int node1 = hashTable.addElement(element1);
34+
35+
assertEquals(node1, hashTable.findNode(element1));
36+
}
37+
38+
@Test
39+
public void testDeleteElement() {
40+
IndexHashTable.HashFunction hashFunction = new IndexHashTable.HashFunction() {
41+
@Override
42+
public int getHash(int element) {
43+
return element % 10; // A simple hash function for testing
44+
}
45+
46+
@Override
47+
public boolean equal(int element1, int element2) {
48+
return element1 == element2;
49+
}
50+
51+
@Override
52+
public int getHash(Object elementDescriptor) {
53+
return ((Integer) elementDescriptor) % 10;
54+
}
55+
56+
@Override
57+
public boolean equal(Object elementDescriptor, int element) {
58+
return ((Integer) elementDescriptor) == element;
59+
}
60+
};
61+
62+
IndexHashTable hashTable = new IndexHashTable(10, hashFunction);
63+
64+
int element1 = 5;
65+
66+
int node1 = hashTable.addElement(element1);
67+
68+
hashTable.deleteElement(element1);
69+
assertEquals(IndexHashTable.nullNode(), hashTable.findNode(element1));
70+
}
71+
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.esri.core.geometry;
2+
3+
import org.junit.Test;
4+
import junit.framework.TestCase;
5+
import org.mockito.Mockito;
6+
public class TestJSONUtils extends TestCase{
7+
8+
@Test
9+
public void testReadDoubleWithFloatValue() {
10+
JsonReader parser = Mockito.mock(JsonReader.class);
11+
Mockito.when(parser.currentToken()).thenReturn(JsonReader.Token.VALUE_NUMBER_FLOAT);
12+
Mockito.when(parser.currentDoubleValue()).thenReturn(3.14);
13+
14+
double result = JSONUtils.readDouble(parser);
15+
assertEquals(3.14, result, 0.0001);
16+
}
17+
18+
@Test
19+
public void testReadDoubleWithIntValue() {
20+
JsonReader parser = Mockito.mock(JsonReader.class);
21+
Mockito.when(parser.currentToken()).thenReturn(JsonReader.Token.VALUE_NUMBER_INT);
22+
Mockito.when(parser.currentIntValue()).thenReturn(42);
23+
24+
double result = JSONUtils.readDouble(parser);
25+
assertEquals(42.0, result, 0.0001);
26+
}
27+
28+
@Test
29+
public void testReadDoubleWithNullValue() {
30+
JsonReader parser = Mockito.mock(JsonReader.class);
31+
Mockito.when(parser.currentToken()).thenReturn(JsonReader.Token.VALUE_NULL);
32+
33+
double result = JSONUtils.readDouble(parser);
34+
assertTrue(Double.isNaN(result));
35+
}
36+
37+
@Test
38+
public void testReadDoubleWithNaNString() {
39+
JsonReader parser = Mockito.mock(JsonReader.class);
40+
Mockito.when(parser.currentToken()).thenReturn(JsonReader.Token.VALUE_STRING);
41+
Mockito.when(parser.currentString()).thenReturn("NaN");
42+
43+
double result = JSONUtils.readDouble(parser);
44+
assertTrue(Double.isNaN(result));
45+
}
46+
47+
}

0 commit comments

Comments
 (0)