def test01_builtin_map_type(self): """Test access to a map<int,int>""" import cppyy std = cppyy.gbl.std a = std.map(int, int)() for i in range(self.N): a[i] = i assert a[i] == i assert len(a) == self.N for key, value in a: assert key == value assert key == self.N-1 assert value == self.N-1 # add a variation, just in case m = std.map(int, int)() for i in range(self.N): m[i] = i*i assert m[i] == i*i for key, value in m: assert key*key == value assert key == self.N-1 assert value == (self.N-1)*(self.N-1)
def test03_empty_map_type(self): """Test behavior of empty map<int,int> (part of cintdlls)""" from cppyy.gbl import std m = std.map(int, int)() for key, value in m: pass
def test03_empty_maptype(self): """Test behavior of empty map<int,int>""" import cppyy std = cppyy.gbl.std m = std.map(int, int)() for key, value in m: pass
def test03_builtin_map_iterators(self): """Test iterator comparison for map""" from cppyy.gbl import std m = std.map(int, int)() m[1] = 1 self.__run_tests(m)
def test02_keyed_maptype(self): """Test access to a map<std::string,int>""" import cppyy std = cppyy.gbl.std a = std.map(std.string, int)() for i in range(self.N): a[str(i)] = i assert a[str(i)] == i assert len(a) == self.N
def test02_keyed_map_type(self): """Test access to a map<std::string,int> (part of cintdlls)""" from cppyy.gbl import std a = std.map(std.string, int)() for i in range(self.N): a[str(i)] = i assert a[str(i)] == i assert i == self.N - 1 assert len(a) == self.N
def test02_keyed_map_type(self): """Test access to a map<std::string,int> (part of cintdlls)""" from cppyy.gbl import std a = std.map(std.string, int)() for i in range(self.N): a[str(i)] = i assert a[str(i)] == i assert i == self.N-1 assert len(a) == self.N
def test04_unsigned_value_type_map_types(self): """Test assignability of maps with unsigned value types (not part of cintdlls)""" import math from cppyy.gbl import std mui = std.map(str, 'unsigned int')() mui['one'] = 1 assert mui['one'] == 1 raises(ValueError, mui.__setitem__, 'minus one', -1) # UInt_t is always 32b, sys.maxint follows system int maxint32 = int(math.pow(2,31)-1) mui['maxint'] = maxint32 + 3 assert mui['maxint'] == maxint32 + 3 mul = std.map(str, 'unsigned long')() mul['two'] = 2 assert mul['two'] == 2 mul['maxint'] = maxvalue + 3 assert mul['maxint'] == maxvalue + 3 raises(ValueError, mul.__setitem__, 'minus two', -2)
def test04_unsigned_value_type_map_types(self): """Test assignability of maps with unsigned value types (not part of cintdlls)""" import math from cppyy.gbl import std mui = std.map(str, 'unsigned int')() mui['one'] = 1 assert mui['one'] == 1 raises(ValueError, mui.__setitem__, 'minus one', -1) # UInt_t is always 32b, sys.maxint follows system int maxint32 = int(math.pow(2, 31) - 1) mui['maxint'] = maxint32 + 3 assert mui['maxint'] == maxint32 + 3 mul = std.map(str, 'unsigned long')() mul['two'] = 2 assert mul['two'] == 2 mul['maxint'] = maxvalue + 3 assert mul['maxint'] == maxvalue + 3 raises(ValueError, mul.__setitem__, 'minus two', -2)
def test04_unsignedvalue_typemap_types(self): """Test assignability of maps with unsigned value types""" import cppyy, math, sys std = cppyy.gbl.std mui = std.map(str, 'unsigned int')() mui['one'] = 1 assert mui['one'] == 1 raises(ValueError, mui.__setitem__, 'minus one', -1) # UInt_t is always 32b, maxvalue is sys.maxint/maxsize and follows system int maxint32 = int(math.pow(2,31)-1) mui['maxint'] = maxint32 + 3 assert mui['maxint'] == maxint32 + 3 mul = std.map(str, 'unsigned long')() mul['two'] = 2 assert mul['two'] == 2 mul['maxint'] = maxvalue + 3 assert mul['maxint'] == maxvalue + 3 raises(ValueError, mul.__setitem__, 'minus two', -2)
def test05_freshly_instantiated_map_type(self): """Instantiate a map from a newly defined class""" import cppyy cppyy.cppdef('template<typename T> struct Data { T fVal; };') from cppyy.gbl import std, Data results = std.map( std.string, Data(int) )() d = Data(int)(); d.fVal = 42 results['summary'] = d assert results.size() == 1 for tag, data in results: assert data.fVal == 42
def test04_unsignedvalue_typemap_types(self): """Test assignability of maps with unsigned value types""" import cppyy, math, sys std = cppyy.gbl.std mui = std.map(str, 'unsigned int')() mui['one'] = 1 assert mui['one'] == 1 raises(TypeError, mui.__setitem__, 'minus one', -1) # UInt_t is always 32b, maxvalue is sys.maxint/maxsize and follows system int maxint32 = int(math.pow(2, 31) - 1) mui['maxint'] = maxint32 + 3 assert mui['maxint'] == maxint32 + 3 mul = std.map(str, 'unsigned long')() mul['two'] = 2 assert mul['two'] == 2 mul['maxint'] = maxvalue + 3 assert mul['maxint'] == maxvalue + 3 raises(TypeError, mul.__setitem__, 'minus two', -2)