diff --git a/Examples/test-suite/csharp/li_std_map_runme.cs b/Examples/test-suite/csharp/li_std_map_runme.cs index 56ea197f1..f1a98d2d5 100644 --- a/Examples/test-suite/csharp/li_std_map_runme.cs +++ b/Examples/test-suite/csharp/li_std_map_runme.cs @@ -24,55 +24,55 @@ public class li_std_map_runme { public static void Main() { // Set up an int int map - IntIntMap iimap = new IntIntMap(); + StringIntMap simap = new StringIntMap(); for (int i = 0; i < collectionSize; i++) { int val = i * 18; - iimap.Add(i, val); + simap.Add(i.ToString(), val); } // Count property test - if (iimap.Count != collectionSize) + if (simap.Count != collectionSize) throw new Exception("Count test failed"); // IsReadOnly property test - if (iimap.IsReadOnly) + if (simap.IsReadOnly) throw new Exception("IsReadOnly test failed"); // Item indexing test - iimap[0] = 200; - if (iimap[0] != 200) + simap["0"] = 200; + if (simap["0"] != 200) throw new Exception("Item property test failed"); - iimap[0] = 0 * 18; + simap["0"] = 0 * 18; // ContainsKey() test for (int i = 0; i < collectionSize; i++) { - if (!iimap.ContainsKey(i)) + if (!simap.ContainsKey(i.ToString())) throw new Exception("ContainsKey test " + i + " failed"); } // ContainsKey() test for (int i = 0; i < collectionSize; i++) { - if (!iimap.Contains(new KeyValuePair(i, i * 18))) + if (!simap.Contains(new KeyValuePair(i.ToString(), i * 18))) throw new Exception("Contains test " + i + " failed"); } // TryGetValue() test int value; - bool rc = iimap.TryGetValue(3, out value); + bool rc = simap.TryGetValue("3", out value); if (rc != true || value != (3 * 18)) throw new Exception("TryGetValue test 1 failed"); - rc = iimap.TryGetValue(-1, out value); + rc = simap.TryGetValue("-1", out value); if (rc != false) throw new Exception("TryGetValue test 2 failed"); // Keys and Values test { - IList keys = new List(iimap.Keys); - IList values = new List(iimap.Values); + IList keys = new List(simap.Keys); + IList values = new List(simap.Values); if (keys.Count != collectionSize) throw new Exception("Keys count test failed"); @@ -81,7 +81,7 @@ public class li_std_map_runme { for (int i = 0; i < keys.Count; i++) { - if (iimap[keys[i]] != values[i]) + if (simap[keys[i]] != values[i]) throw new Exception("Keys and values test failed for index " + i); } } @@ -89,30 +89,30 @@ public class li_std_map_runme { // Add and Remove test for (int i = 100; i < 103; i++) { - iimap.Add(i, i * 18); - if (!iimap.ContainsKey(i) || iimap[i] != (i * 18)) + simap.Add(i.ToString(), i * 18); + if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18)) throw new Exception("Add test failed for index " + i); - iimap.Remove(i); - if (iimap.ContainsKey(i)) + simap.Remove(i.ToString()); + if (simap.ContainsKey(i.ToString())) throw new Exception("Remove test failed for index " + i); } for (int i = 200; i < 203; i++) { - iimap.Add(new KeyValuePair(i, i * 18)); - if (!iimap.ContainsKey(i) || iimap[i] != (i * 18)) + simap.Add(new KeyValuePair(i.ToString(), i * 18)); + if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18)) throw new Exception("Add explicit test failed for index " + i); - iimap.Remove(new KeyValuePair(i, i * 18)); - if (iimap.ContainsKey(i)) + simap.Remove(new KeyValuePair(i.ToString(), i * 18)); + if (simap.ContainsKey(i.ToString())) throw new Exception("Remove explicit test failed for index " + i); } // Duplicate key test try { - iimap.Add(3, 0); + simap.Add("3", 0); throw new Exception("Adding duplicate key test failed"); } catch (ArgumentException) @@ -121,29 +121,29 @@ public class li_std_map_runme { // CopyTo() test { - KeyValuePair[] outputarray = new KeyValuePair[collectionSize]; - iimap.CopyTo(outputarray); - foreach (KeyValuePair val in outputarray) + KeyValuePair[] outputarray = new KeyValuePair[collectionSize]; + simap.CopyTo(outputarray); + foreach (KeyValuePair val in outputarray) { - if (iimap[val.Key] != val.Value) + if (simap[val.Key] != val.Value) throw new Exception("CopyTo (1) test failed, index:" + val.Key); } } { - KeyValuePair[] outputarray = new KeyValuePair[midCollection + collectionSize]; - iimap.CopyTo(outputarray, midCollection); + KeyValuePair[] outputarray = new KeyValuePair[midCollection + collectionSize]; + simap.CopyTo(outputarray, midCollection); for (int i = midCollection; i < midCollection + collectionSize; i++) { - KeyValuePair val = outputarray[i]; - if (iimap[val.Key] != val.Value) + KeyValuePair val = outputarray[i]; + if (simap[val.Key] != val.Value) throw new Exception("CopyTo (2) test failed, index:" + val.Key); } } { - KeyValuePair[] outputarray = new KeyValuePair[collectionSize - 1]; + KeyValuePair[] outputarray = new KeyValuePair[collectionSize - 1]; try { - iimap.CopyTo(outputarray); + simap.CopyTo(outputarray); throw new Exception("CopyTo (4) test failed"); } catch (ArgumentException) @@ -152,18 +152,22 @@ public class li_std_map_runme { } // Clear test - iimap.Clear(); - if (iimap.Count != 0) + simap.Clear(); + if (simap.Count != 0) throw new Exception("Clear test failed"); // Test wrapped methods for (int i = 1; i <= 5; i++) { - iimap[i] = i; + simap[i.ToString()] = i; } - double avg = li_std_map.keyAverage(iimap); + double avg = li_std_map.valueAverage(simap); if (avg != 3.0) - throw new Exception("Wrapped method keyAverage test failed. Got " + avg); + throw new Exception("Wrapped method valueAverage test failed. Got " + avg); + + string keyStringified = li_std_map.stringifyKeys(simap); + if (keyStringified != " 1 2 3 4 5") + throw new Exception("Wrapped method stringifyKeys test failed. Got " + keyStringified); // Test a map with a new specialized type (Struct) { diff --git a/Examples/test-suite/li_std_map.i b/Examples/test-suite/li_std_map.i index 39e034bfa..356e86df3 100644 --- a/Examples/test-suite/li_std_map.i +++ b/Examples/test-suite/li_std_map.i @@ -15,19 +15,27 @@ // Add an inline function to test %inline %{ -double keyAverage(std::map m) { +double valueAverage(std::map m) { if (m.size() == 0) { return 0.0; } double a = 0.0; - for (std::map::iterator i = m.begin(); i != m.end(); i++) { - a += i->first; + for (std::map::iterator i = m.begin(); i != m.end(); i++) { + a += i->second; } return a / m.size(); } +std::string stringifyKeys(std::map m) { + std::string a; + for (std::map::iterator i = m.begin(); i != m.end(); i++) { + a += " " + i->first; + } + return a; +} + struct Struct { double num; Struct() : num(0.0) {}