def test_grow_rule_1(self): df = pd.read_csv('tests/test_files/testfile_4.csv', encoding='utf-8', delimiter=';') ds = DictDataset(0, df) rule = ds.grow_rule() self.assertEqual("Age < 8 and Sex in ['Female']", rule.to_string())
def test_split_into_growset_pruneset_1(self): df = pd.read_csv('tests/test_files/testfile_8.csv', encoding='utf-8', delimiter=';') ds = DictDataset(1, df) grow, prune = ds.split_into_growset_pruneset() self.assertEqual(21, grow.length()) self.assertEqual(11, prune.length())
def test_find_best_num_literal_3(self): df = pd.read_csv('tests/test_files/testfile_3.csv', encoding='utf-8', delimiter=';') ds = DictDataset(1, df) best_l, best_foil = ds.find_best_literal(0, 0, df['Age'].unique(), 'Age') self.assertEqual(10, round(best_foil, 5)) self.assertEqual('Age > 88', best_l.to_string())
def test_grow_rule_2(self): df = pd.read_csv('tests/test_files/mushroom.csv', encoding='utf-8', delimiter=';') ds = DictDataset(0, df) rule = ds.grow_rule() rule = ds.make_rule(rule) self.assertEqual("a5 in ['c', 'f', 'm', 'p', 's', 'y']", rule.to_string())
def test_literal_count_p_n2(self): df = pd.read_csv('tests/test_files/testfile_8.csv', encoding='utf-8', delimiter=';') l = Literal('ClassOfSeat', 'in', ['xab', 'asdas']) ds = DictDataset(1, df) p, n = ds.count_p_n_literal(l) self.assertEqual(0, p) self.assertEqual(0, n)
def test_literal_count_p_n3(self): df = pd.read_csv('tests/test_files/testfile_8.csv', encoding='utf-8', delimiter=';') l = Literal('Age', '>', 1000) ds = DictDataset(1, df) p, n = ds.count_p_n_literal(l) self.assertEqual(0, p) self.assertEqual(4, n)
def test_literal_count_p_n4(self): df = pd.read_csv('tests/test_files/testfile_8.csv', encoding='utf-8', delimiter=';') l = Literal('Sex', 'in', 'Male') ds = DictDataset(1, df) p, n = ds.count_p_n_literal(l) self.assertEqual(8, p) self.assertEqual(8, n)
def test_find_best_char_literal_3(self): df = pd.read_csv('tests/test_files/testfile_3.csv', encoding='utf-8', delimiter=';') ds = DictDataset(1, df) best_l, best_foil = ds.find_best_literal(0, 0, df['Sex'].unique(), 'Sex') self.assertEqual(9.38889, round(best_foil, 5)) self.assertEqual("Sex in ['Female']", best_l.to_string())
def test_rule_count_p_n4(self): df = pd.read_csv('tests/test_files/testfile_8.csv', encoding='utf-8', delimiter=';') rule = Rule() ds = DictDataset(1, df) p, n = ds.count_p_n_rule(rule) self.assertEqual(16, p) self.assertEqual(16, n)
def test_find_best_char_literal_2(self): df = pd.read_csv('tests/test_files/testfile_2.csv', encoding='utf-8', delimiter=';') ds = DictDataset(1, df) best_l, best_foil = ds.find_best_literal(0, 0, df['ClassOfSeat'].unique(), 'ClassOfSeat') self.assertEqual(9, round(best_foil, 5)) self.assertEqual("ClassOfSeat in ['1st', '3rd', 'Crew']", best_l.to_string())
def test_prune_rule_2(self): df = pd.read_csv('tests/test_files/mushroom.csv', encoding='utf-8', delimiter=';') ds = DictDataset(0, df) l = Literal('a5', 'in', ['c', 'f', 'm', 'p', 's', 'y']) rule = Rule() rule.add_literal(l) rule = ds.prune_rule(rule) self.assertEqual("a5 in ['c', 'f', 'm', 'p', 's', 'y']", rule.to_string())
def test_prune_rule_1(self): df = pd.read_csv('tests/test_files/testfile_3.csv', encoding='utf-8', delimiter=';') l = Literal('Sex', 'in', 'Female') l2 = Literal('Sex', 'in', 'Male') rule = Rule() rule.add_literal(l) rule.add_literal(l2) ds = DictDataset(1, df) rule = ds.prune_rule(rule) self.assertEqual("Sex in Female", rule.to_string())
def test_rule_count_p_n1(self): df = pd.read_csv('tests/test_files/testfile_8.csv', encoding='utf-8', delimiter=';') l = Literal('ClassOfSeat', 'in', '1st') l2 = Literal('Age', '<', 20) rule = Rule() rule.add_literal(l) rule.add_literal(l2) ds = DictDataset(1, df) p, n = ds.count_p_n_rule(rule) self.assertEqual(1, p) self.assertEqual(1, n)
def test_delete_not_covered_1(self): df = pd.read_csv('tests/test_files/testfile_8.csv', encoding='utf-8', delimiter=';') rule = Rule() ds = DictDataset(1, df) len_before = ds.length() ds.delete_not_covered(rule) len_after = ds.length() self.assertEqual(0, len_after)
def test_delete_not_covered_3(self): df = pd.read_csv('tests/test_files/testfile_8.csv', encoding='utf-8', delimiter=';') l = Literal('ClassOfSeat', 'in', '1st') l2 = Literal('Age', '<', 20) rule = Rule() rule.add_literal(l) rule.add_literal(l2) ds = DictDataset(1, df) len_before = ds.length() ds.delete_not_covered(rule) len_after = ds.length() self.assertEqual(len_before - 30, len_after)
def test_is_any_pos_example_false_all_n(self): df = pd.read_csv('tests/test_files/testfile_6_all_n.csv', encoding='utf-8', delimiter=';') ds = DictDataset(1, df) self.assertEqual(False, ds.is_any_pos_example())
def test_length_dataset_2_no_rows(self): df = pd.read_csv('tests/test_files/testfile_11_no_rows.csv', encoding='utf-8', delimiter=';') ds = DictDataset(1, df) self.assertEqual(0, ds.length())
def test_is_any_pos_example_true_all_p(self): df = pd.read_csv('tests/test_files/testfile_10_all_p.csv', encoding='utf-8', delimiter=';') ds = DictDataset(1, df) self.assertEqual(True, ds.is_any_pos_example())
def test_length_dataset_4_all_n(self): df = pd.read_csv('tests/test_files/testfile_6_all_n.csv', encoding='utf-8', delimiter=';') ds = DictDataset(1, df) self.assertEqual(32, ds.length())