def test_exceptions(self): fvm = FeatureVectorMatrix() caught = False try: fvm.add_row(v3) except IndexError: caught = True self.assertTrue(caught, "You can't add a list to a fvm with no columns defined") fvm.set_column_names(c3) self.assertEquals(3, fvm.column_count()) fvm.add_row(v3) self.assertEquals(1, fvm.row_count()) caught = False try: print fvm.keys() except NotImplementedError: caught = True self.assertTrue(caught, "You can't get keys without all rows keyed") caught = False try: fvm.transpose() except NotImplementedError: caught = True self.assertTrue(caught, "You can't rotate a fvm without all rows keyed") caught = False try: fvm.add_row(v4) except IndexError: caught = True self.assertTrue(caught, "You can't add a list to a fvm with more columns than the given list") fvm.add_row(d4) self.assertEquals(len(fvm.column_names()), 4) # test that the already added row gets the extra 0 appended self.assertEquals(fvm.get_row_list(0), [1, 2, 3,0])
def test_len(self): fvm = FeatureVectorMatrix() fvm.add_row(d3, 'one') self.assertEquals(1, len(fvm)) self.assertEquals(fvm.keys(), ['one'])