Exemple #1
0
 def test_double_free(self):
     s = FloatArray()
     s.free()
     s.free()
     v = SparseMap()
     v.free()
     v.free()
Exemple #2
0
 def test_double_free(self):
     s = FloatArray()
     s.free()
     s.free()
     v = SparseMap()
     v.free()
     v.free()
Exemple #3
0
 def test_map_map_from_dict(self):
     a = FloatArray([ 1, 2, 3, 4 ])
     b = FloatArray([ 2, 4, 6, 8 ])
     v = SparseMap({ 1: a, 3: b })
     self.assertDictEqual(dict(v.items()), { 1: [1, 2, 3, 4], 3: [2, 4, 6, 8] })
     v.free()
     a.free()
     b.free()
Exemple #4
0
 def test_map_buffer_offset(self):
     a = FloatArray([1])
     b = FloatArray([1, 2, 3])
     v = SparseMap({1: a, 3: b})
     buf = v.buffer(byte_offset=8)
     a.free()
     b.free()
     v.free()
     copy = SparseMap(buf, len(buf))
     self.assertDictEqual(dict(copy.items()), {3: [1, 2, 3]})
     copy.free()
Exemple #5
0
 def test_map_map_from_dict(self):
     a = FloatArray([1, 2, 3, 4])
     b = FloatArray([2, 4, 6, 8])
     v = SparseMap({1: a, 3: b})
     self.assertDictEqual(dict(v.items()), {
         1: [1, 2, 3, 4],
         3: [2, 4, 6, 8]
     })
     v.free()
     a.free()
     b.free()
Exemple #6
0
 def test_map_append(self):
     v = SparseMap()
     s = FloatArray([1, 2, 3])
     v.append(1, s)
     s.free()
     self.assertDictEqual(dict(v.items()), {1: [1, 2, 3]})
     v.free()
Exemple #7
0
 def test_map_repr(self):
     map = SparseMap()
     self.assertEqual(str(map), '')
     a = FloatArray([1, 2, 3])
     map.append(1, a)
     b = FloatArray([4])
     map.append(2, b)
     self.assertEqual(str(map), '[ 1 ] = [1.0, 2.0, 3.0]\n[ 2 ] = [4.0]')
     a.free()
     b.free()
     map.free()
Exemple #8
0
 def test_map_buffer_offset(self):
     a = FloatArray([1])
     b = FloatArray([1, 2, 3])
     v = SparseMap({1: a, 3: b})
     buf = v.buffer(byte_offset=8)
     a.free()
     b.free()
     v.free()
     copy = SparseMap(buf, len(buf))
     self.assertDictEqual(dict(copy.items()), {3: [1, 2, 3]})
     copy.free()
Exemple #9
0
 def test_context_manager_free(self):
     outside = None
     with FloatArray() as structure:
         outside = structure
         self.assertIsNot(structure.ptr, None)
     self.assertIs(outside._ptr, None)
     with SparseMap() as structure:
         outside = structure
         self.assertIsNot(structure.ptr, None)
     self.assertIs(outside._ptr, None)
Exemple #10
0
 def test_map_clear(self):
     a = FloatArray([1, 2, 3, 4])
     b = FloatArray([2, 4, 6, 8])
     v = SparseMap({1: a, 3: b})
     a.free()
     b.free()
     v.clear()
     self.assertEqual(v.byte_length(), 0)
     v.free()
Exemple #11
0
 def test_map_append(self):
     v = SparseMap()
     s = FloatArray([1, 2, 3])
     v.append(1, s)
     s.free()
     self.assertDictEqual(dict(v.items()), {1: [1, 2, 3]})
     v.free()
Exemple #12
0
 def test_map_repr(self):
     map = SparseMap()
     self.assertEqual(str(map), '')
     a = FloatArray([1, 2, 3])
     map.append(1, a)
     b = FloatArray([4])
     map.append(2, b)
     self.assertEqual(str(map), '[ 1 ] = [1.0, 2.0, 3.0]\n[ 2 ] = [4.0]')
     a.free()
     b.free()
     map.free()
Exemple #13
0
 def test_map_clear(self):
     a = FloatArray([1, 2, 3, 4])
     b = FloatArray([2, 4, 6, 8])
     v = SparseMap({1: a, 3: b})
     a.free()
     b.free()
     v.clear()
     self.assertEqual(v.byte_length(), 0)
     v.free()
Exemple #14
0
 def test_map_empty_map(self):
     v = SparseMap()
     self.assertDictEqual(dict(v.items()), {})
     self.assertEqual(v.byte_length(), 0)
     v.free()
Exemple #15
0
 def test_use_map_after_free_error(self):
     s = SparseMap()
     s.free()
     freed_array = FloatArray()
     freed_array.free()
     tmp_array = FloatArray()
     tmp = SparseMap()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.append(1, tmp_array)
     with self.assertRaises(GaugedUseAfterFreeError):
         tmp.append(1, freed_array)
     with self.assertRaises(GaugedUseAfterFreeError):
         s.slice()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.concat(tmp)
     with self.assertRaises(GaugedUseAfterFreeError):
         tmp.concat(s)
     with self.assertRaises(GaugedUseAfterFreeError):
         s.byte_length()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.buffer()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.clear()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.first()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.last()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.sum()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.min()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.max()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.mean()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.stddev()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.count()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.percentile(50)
     with self.assertRaises(GaugedUseAfterFreeError):
         list(s.iteritems())
     tmp_array.free()
     tmp.free()
Exemple #16
0
 def test_map_import_export(self):
     a = FloatArray([1, 2, 3, 4])
     b = FloatArray([2, 4, 6, 8])
     v = SparseMap({1: a, 3: b})
     buf = v.buffer()
     a.free()
     b.free()
     v.free()
     self.assertEqual(len(buf), 40)
     copy = SparseMap(buf, len(buf))
     self.assertDictEqual(
         dict(copy.items()), {1: [1, 2, 3, 4], 3: [2, 4, 6, 8]})
     copy.free()
     v = SparseMap()
     self.assertEqual(v.buffer(), None)
     v.free()
Exemple #17
0
 def test_map_import_export(self):
     a = FloatArray([1, 2, 3, 4])
     b = FloatArray([2, 4, 6, 8])
     v = SparseMap({1: a, 3: b})
     buf = v.buffer()
     a.free()
     b.free()
     v.free()
     self.assertEqual(len(buf), 40)
     copy = SparseMap(buf, len(buf))
     self.assertDictEqual(dict(copy.items()), {
         1: [1, 2, 3, 4],
         3: [2, 4, 6, 8]
     })
     copy.free()
     v = SparseMap()
     self.assertEqual(v.buffer(), None)
     v.free()
Exemple #18
0
 def test_map_empty_map(self):
     v = SparseMap()
     self.assertDictEqual(dict(v.items()), {})
     self.assertEqual(v.byte_length(), 0)
     v.free()
Exemple #19
0
 def test_use_map_after_free_error(self):
     s = SparseMap()
     s.free()
     freed_array = FloatArray()
     freed_array.free()
     tmp_array = FloatArray()
     tmp = SparseMap()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.append(1, tmp_array)
     with self.assertRaises(GaugedUseAfterFreeError):
         tmp.append(1, freed_array)
     with self.assertRaises(GaugedUseAfterFreeError):
         s.slice()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.concat(tmp)
     with self.assertRaises(GaugedUseAfterFreeError):
         tmp.concat(s)
     with self.assertRaises(GaugedUseAfterFreeError):
         s.byte_length()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.buffer()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.clear()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.first()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.last()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.sum()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.min()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.max()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.mean()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.stddev()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.count()
     with self.assertRaises(GaugedUseAfterFreeError):
         s.percentile(50)
     with self.assertRaises(GaugedUseAfterFreeError):
         list(s.iteritems())
     tmp_array.free()
     tmp.free()