File: li_std_map_runme.java

package info (click to toggle)
swig 4.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 42,876 kB
  • sloc: cpp: 61,013; ansic: 27,612; java: 14,670; python: 10,632; cs: 8,103; makefile: 6,287; yacc: 6,197; sh: 5,247; ruby: 5,172; perl: 3,541; php: 2,069; ml: 2,066; lisp: 1,894; javascript: 1,300; tcl: 1,091; xml: 115
file content (122 lines) | stat: -rw-r--r-- 4,068 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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 checkThat(boolean mustBeTrue) throws Throwable {
    if (!mustBeTrue) {
      // Index [2], since this function is one hop away from main, and [1] is the current method.
      throw new RuntimeException("Test failed at line number " + Thread.currentThread().getStackTrace()[2].getLineNumber());
    }
  }

  public static void main(String argv[]) throws Throwable
  {
    java.util.AbstractMap<String, Integer> sim = new StringIntMap();
    java.util.AbstractMap<Integer, Integer> iim = new IntIntMap();

    checkThat(sim.isEmpty());
    checkThat(iim.isEmpty());
    checkThat(sim.size() == 0);
    checkThat(iim.size() == 0);

    checkThat(sim.get("key") == null);
    checkThat(iim.get(1) == null);

    checkThat(!sim.containsKey("key"));
    checkThat(!iim.containsKey(1));

    checkThat(sim.put("key", 2) == null);
    checkThat(iim.put(1, 2) == null);

    checkThat(sim.size() == 1);
    checkThat(iim.size() == 1);
    checkThat(!sim.isEmpty());
    checkThat(!iim.isEmpty());

    checkThat(sim.get("key") == 2);
    checkThat(iim.get(1) == 2);

    checkThat(sim.remove("key") == 2);
    checkThat(iim.remove(1) == 2);

    checkThat(sim.isEmpty());
    checkThat(iim.isEmpty());
    checkThat(sim.size() == 0);
    checkThat(iim.size() == 0);

    checkThat(sim.get("key") == null);
    checkThat(iim.get(1) == null);

    checkThat(sim.remove("key") == null);
    checkThat(iim.remove(1) == null);

    checkThat(sim.put("key", 2) == null);
    checkThat(iim.put(1, 2) == null);

    sim.clear();
    iim.clear();
    checkThat(sim.isEmpty());
    checkThat(iim.isEmpty());

    checkThat(sim.put("key1", 1) == null);
    checkThat(iim.put(1, 1) == null);
    checkThat(sim.put("key2", 2) == null);
    checkThat(iim.put(2, 2) == null);

    checkThat(sim.size() == 2);
    checkThat(iim.size() == 2);
    checkThat(sim.get("key1") == 1);
    checkThat(iim.get(1) == 1);
    checkThat(sim.get("key2") == 2);
    checkThat(iim.get(2) == 2);

    checkThat(sim.put("key1", 3) == 1);
    checkThat(iim.put(1, 3) == 1);

    checkThat(sim.size() == 2);
    checkThat(iim.size() == 2);
    checkThat(sim.get("key1") == 3);
    checkThat(iim.get(1) == 3);

    java.util.Set<java.util.Map.Entry<String, Integer>> sim_es = sim.entrySet();
    java.util.Map<String, Integer> sim_default = new java.util.HashMap<String, Integer>();
    sim_default.put("key1", 3);
    sim_default.put("key2", 2);
    java.util.Set<java.util.Map.Entry<String, Integer>> sim_es_default = sim_default.entrySet();
    checkThat(sim_es.size() == sim_es_default.size());
    for (java.util.Map.Entry<String, Integer> entry : sim_es) {
      checkThat(sim_es_default.contains(entry));
      checkThat(sim_default.containsKey(entry.getKey()));
      checkThat(sim_default.containsValue(entry.getValue()));

      Integer oldValue = entry.getValue();
      entry.setValue(oldValue + 1);
      checkThat(sim.get(entry.getKey()) == (oldValue + 1));
    }

    java.util.Set<java.util.Map.Entry<Integer, Integer>> iim_es = iim.entrySet();
    java.util.Map<Integer, Integer> iim_default = new java.util.HashMap<Integer, Integer>();
    iim_default.put(1, 3);
    iim_default.put(2, 2);
    java.util.Set<java.util.Map.Entry<Integer, Integer>> iim_es_default = iim_default.entrySet();
    checkThat(iim_es.size() == iim_es_default.size());
    for (java.util.Map.Entry<Integer, Integer> entry : iim_es) {
      checkThat(iim_es_default.contains(entry));
      checkThat(iim_default.containsKey(entry.getKey()));
      checkThat(iim_default.containsValue(entry.getValue()));

      Integer oldValue = entry.getValue();
      entry.setValue(oldValue + 1);
      checkThat(iim.get(entry.getKey()) == (oldValue + 1));
    }
  }
}