Beispiel #1
0
 def test_erase(self):
     """make sure we can erase"""
     x = PySparseMatFloat(2,3)
     x.insert(1,2,10)
     self.assertEqual(x.get(1,2), 10.0)
     x.erase(1,2)
     self.assertEqual(x.get(1,2), 0.0)
     self.assertEqual(x.contains(1,2), 0)
Beispiel #2
0
 def test_items(self):
     """make sure we can get items"""
     x = PySparseMatFloat(3,4)
     self.assertEqual(x.items(), [])
     x.insert(1,2,10)
     x.insert(2,3,4)
     x.insert(2,3,4)
     x.insert(2,3,4)
     self.assertEqual(sorted(x.items()), [((1,2),10.0),((2,3),4.0)])
     x.erase(2,3)
     self.assertEqual(x.items(), [((1,2),10.0)])
Beispiel #3
0
 def test_keys(self):
     """make sure we can get keys"""
     x = PySparseMatFloat(3,4)
     self.assertEqual(x.keys(), [])
     x.insert(1,2,10)
     x.insert(2,3,4)
     x.insert(2,3,4)
     x.insert(2,3,4)
     self.assertEqual(sorted(x.keys()), [(1,2),(2,3)])
     x.erase(2,3)
     self.assertEqual(x.keys(), [(1,2)])
Beispiel #4
0
 def test_length(self):
     """make sure we can test length"""
     x = PySparseMatFloat(3,4)
     self.assertEqual(x.length(), 0)
     x.insert(1,2,10)
     self.assertEqual(x.length(), 1)
     x.insert(2,3,4)
     x.insert(2,3,4)
     x.insert(2,3,4)
     self.assertEqual(x.length(), 2)
     x.erase(2,3)
     self.assertEqual(x.length(), 1)
Beispiel #5
0
 def test_contains(self):
     """Make sure we can check if things are present"""
     x = PySparseMatFloat(2,3)
     self.assertEqual(x.contains(1,2), 0)
     x.insert(1,2,20)
     self.assertEqual(x.contains(1,2), 1)
     x.insert(1,2,10)
     self.assertEqual(x.contains(1,2), 1)
     x.erase(1,2)
     self.assertEqual(x.contains(1,2), 0)
     x.insert(1,2,0.0)
     self.assertEqual(x.contains(1,2), 0)