Add unordered_{set|map} and set to Java

Add test suite

Add to makefile

Revert set change

Fix java map test

Fix some of the tests

Fix unordered map test
This commit is contained in:
Brad Kotsopoulos 2018-11-21 19:19:15 -05:00
commit 0f18b430fb
11 changed files with 481 additions and 12 deletions

View file

@ -44,6 +44,10 @@ CPP_TEST_CASES = \
java_typemaps_proxy \
java_typemaps_typewrapper \
li_std_list \
li_std_map \
li_std_set \
li_std_unordered_map \
li_std_unordered_set \
# li_boost_intrusive_ptr
CPP11_TEST_CASES = \

View file

@ -0,0 +1,101 @@
import li_std_map.*;
public class li_std_map_runme {
static {
try {
System.loadLibrary("li_std_map");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[]) throws Throwable
{
StringIntMap sim = new StringIntMap();
IntIntMap iim = new IntIntMap();
if (!sim.empty()) throw new RuntimeException("Test (1) failed");
if (!iim.empty()) throw new RuntimeException("Test (2) failed");
if (sim.size() != 0) throw new RuntimeException("Test (3) failed");
if (iim.size() != 0) throw new RuntimeException("Test (4) failed");
try {
sim.get("key");
throw new RuntimeException("Test (5) failed");
} catch (IndexOutOfBoundsException e) {
}
try {
iim.get(1);
throw new RuntimeException("Test (6) failed");
} catch (IndexOutOfBoundsException e) {
}
sim.set("key", 1);
iim.set(1, 1);
if (sim.size() != 1) throw new RuntimeException("Test (7) failed");
if (iim.size() != 1) throw new RuntimeException("Test (8) failed");
sim.del("key");
iim.del(1);
if (sim.has_key("key")) throw new RuntimeException("Test (9) failed");
if (iim.has_key(1)) throw new RuntimeException("Test (10) failed");
if (!sim.empty()) throw new RuntimeException("Test (11) failed");
if (!iim.empty()) throw new RuntimeException("Test (12) failed");
if (sim.size() != 0) throw new RuntimeException("Test (13) failed");
if (iim.size() != 0) throw new RuntimeException("Test (14) failed");
try {
sim.del("key");
throw new RuntimeException("Test (15) failed");
} catch (IndexOutOfBoundsException e) {
}
try {
iim.del(1);
throw new RuntimeException("Test (16) failed");
} catch (IndexOutOfBoundsException e) {
}
sim.set("key", 1);
iim.set(1, 1);
if (sim.size() != 1) throw new RuntimeException("Test (17) failed");
if (iim.size() != 1) throw new RuntimeException("Test (18) failed");
sim.clear();
iim.clear();
if (sim.has_key("key")) throw new RuntimeException("Test (19) failed");
if (iim.has_key(1)) throw new RuntimeException("Test (20) failed");
if (!sim.empty()) throw new RuntimeException("Test (21) failed");
if (!iim.empty()) throw new RuntimeException("Test (22) failed");
if (sim.size() != 0) throw new RuntimeException("Test (23) failed");
if (iim.size() != 0) throw new RuntimeException("Test (24) failed");
sim.set("key", 1);
sim.set("key2", 2);
iim.set(1, 1);
iim.set(2, 2);
if (sim.get("key") != 1) throw new RuntimeException("Test (25) failed");
if (sim.get("key2") != 2) throw new RuntimeException("Test (26) failed");
if (iim.get(1) != 1) throw new RuntimeException("Test (27) failed");
if (iim.get(2) != 2) throw new RuntimeException("Test (28) failed");
sim.set("key", 3);
iim.set(1, 3);
if (sim.get("key") != 3) throw new RuntimeException("Test (29) failed");
if (sim.get("key2") != 2) throw new RuntimeException("Test (30) failed");
if (iim.get(1) != 3) throw new RuntimeException("Test (31) failed");
if (iim.get(2) != 2) throw new RuntimeException("Test (32) failed");
}
}

View file

@ -0,0 +1,40 @@
import li_std_set.*;
public class li_std_set_runme {
static {
try {
System.loadLibrary("li_std_set");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[]) throws Throwable
{
StringSet ss = new StringSet();
if (!ss.empty()) throw new RuntimeException("Test (1) failed");
if (ss.size() != 0) throw new RuntimeException("Test (2) failed");
if (ss.has("key")) throw new RuntimeException("Test (3) failed");
if (ss.erase("key")) throw new RuntimeException("Test (4) failed");
if (!ss.insert("key")) throw new RuntimeException("Test (5) failed");
if (ss.insert("key")) throw new RuntimeException("Test (6) failed");
if (!ss.has("key")) throw new RuntimeException("Test (7) failed");
if (!ss.erase("key")) throw new RuntimeException("Test (8) failed");
if (!ss.empty()) throw new RuntimeException("Test (9) failed");
if (ss.size() != 0) throw new RuntimeException("Test (10) failed");
if (!ss.insert("key1")) throw new RuntimeException("Test (11) failed");
if (!ss.insert("key2")) throw new RuntimeException("Test (12) failed");
if (!ss.insert("key3")) throw new RuntimeException("Test (13) failed");
if (ss.size() != 3) throw new RuntimeException("Test (14) failed");
ss.clear();
if (!ss.empty()) throw new RuntimeException("Test (15) failed");
if (ss.size() != 0) throw new RuntimeException("Test (16) failed");
}
}

View file

@ -0,0 +1,101 @@
import li_std_unordered_map.*;
public class li_std_unordered_map_runme {
static {
try {
System.loadLibrary("li_std_unordered_map");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[]) throws Throwable
{
StringIntUnorderedMap sim = new StringIntUnorderedMap();
IntIntUnorderedMap iim = new IntIntUnorderedMap();
if (!sim.empty()) throw new RuntimeException("Test (1) failed");
if (!iim.empty()) throw new RuntimeException("Test (2) failed");
if (sim.size() != 0) throw new RuntimeException("Test (3) failed");
if (iim.size() != 0) throw new RuntimeException("Test (4) failed");
try {
sim.get("key");
throw new RuntimeException("Test (5) failed");
} catch (IndexOutOfBoundsException e) {
}
try {
iim.get(1);
throw new RuntimeException("Test (6) failed");
} catch (IndexOutOfBoundsException e) {
}
sim.set("key", 1);
iim.set(1, 1);
if (sim.size() != 1) throw new RuntimeException("Test (7) failed");
if (iim.size() != 1) throw new RuntimeException("Test (8) failed");
sim.del("key");
iim.del(1);
if (sim.has_key("key")) throw new RuntimeException("Test (9) failed");
if (iim.has_key(1)) throw new RuntimeException("Test (10) failed");
if (!sim.empty()) throw new RuntimeException("Test (11) failed");
if (!iim.empty()) throw new RuntimeException("Test (12) failed");
if (sim.size() != 0) throw new RuntimeException("Test (13) failed");
if (iim.size() != 0) throw new RuntimeException("Test (14) failed");
try {
sim.del("key");
throw new RuntimeException("Test (15) failed");
} catch (IndexOutOfBoundsException e) {
}
try {
iim.del(1);
throw new RuntimeException("Test (16) failed");
} catch (IndexOutOfBoundsException e) {
}
sim.set("key", 1);
iim.set(1, 1);
if (sim.size() != 1) throw new RuntimeException("Test (17) failed");
if (iim.size() != 1) throw new RuntimeException("Test (18) failed");
sim.clear();
iim.clear();
if (sim.has_key("key")) throw new RuntimeException("Test (19) failed");
if (iim.has_key(1)) throw new RuntimeException("Test (20) failed");
if (!sim.empty()) throw new RuntimeException("Test (21) failed");
if (!iim.empty()) throw new RuntimeException("Test (22) failed");
if (sim.size() != 0) throw new RuntimeException("Test (23) failed");
if (iim.size() != 0) throw new RuntimeException("Test (24) failed");
sim.set("key", 1);
sim.set("key2", 2);
iim.set(1, 1);
iim.set(2, 2);
if (sim.get("key") != 1) throw new RuntimeException("Test (25) failed");
if (sim.get("key2") != 2) throw new RuntimeException("Test (26) failed");
if (iim.get(1) != 1) throw new RuntimeException("Test (27) failed");
if (iim.get(2) != 2) throw new RuntimeException("Test (28) failed");
sim.set("key", 3);
iim.set(1, 3);
if (sim.get("key") != 3) throw new RuntimeException("Test (29) failed");
if (sim.get("key2") != 2) throw new RuntimeException("Test (30) failed");
if (iim.get(1) != 3) throw new RuntimeException("Test (31) failed");
if (iim.get(2) != 2) throw new RuntimeException("Test (32) failed");
}
}

View file

@ -0,0 +1,40 @@
import li_std_unordered_set.*;
public class li_std_unordered_set_runme {
static {
try {
System.loadLibrary("li_std_unordered_set");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static void main(String argv[]) throws Throwable
{
StringUnorderedSet ss = new StringUnorderedSet();
if (!ss.empty()) throw new RuntimeException("Test (1) failed");
if (ss.size() != 0) throw new RuntimeException("Test (2) failed");
if (ss.has("key")) throw new RuntimeException("Test (3) failed");
if (ss.erase("key")) throw new RuntimeException("Test (4) failed");
if (!ss.insert("key")) throw new RuntimeException("Test (5) failed");
if (ss.insert("key")) throw new RuntimeException("Test (6) failed");
if (!ss.has("key")) throw new RuntimeException("Test (7) failed");
if (!ss.erase("key")) throw new RuntimeException("Test (8) failed");
if (!ss.empty()) throw new RuntimeException("Test (9) failed");
if (ss.size() != 0) throw new RuntimeException("Test (10) failed");
if (!ss.insert("key1")) throw new RuntimeException("Test (11) failed");
if (!ss.insert("key2")) throw new RuntimeException("Test (12) failed");
if (!ss.insert("key3")) throw new RuntimeException("Test (13) failed");
if (ss.size() != 3) throw new RuntimeException("Test (14) failed");
ss.clear();
if (!ss.empty()) throw new RuntimeException("Test (15) failed");
if (ss.size() != 0) throw new RuntimeException("Test (16) failed");
}
}