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)
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)])
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)])
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)
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)
def setUp(self): self.obj = PySparseMatFloat(11,21)
class PySparseMatFloatTests(TestCase): def setUp(self): self.obj = PySparseMatFloat(11,21) def test_get(self): """make sure we can get shibby""" self.obj.insert(10,20,30) self.assertEqual(self.obj.get(10,20), 30.0) # expect cast self.assertTrue(type(self.obj.get(10,20)), type(30.0)) self.assertEqual(self.obj.get(10,19), 0.0) self.assertRaises(KeyError, self.obj.get, -1, 10) self.assertRaises(KeyError, self.obj.get, 1, -10) def test_insert(self): """make sure we can insert""" self.obj.insert(10,20,30) self.assertEqual(self.obj.get(10,20), 30.0) # expect cast self.assertTrue(type(self.obj.get(10,20)), type(30.0)) self.obj.insert(10,20,-10.0) self.assertEqual(self.obj.get(10,20), -10.0) self.assertRaises(KeyError, self.obj.insert, -1, 10, 2.0) self.assertRaises(KeyError, self.obj.insert, 1, -10, 3.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) 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) 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) 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)]) 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)])