def test_compare(self): row1 = [1, 1, 0] header1 = ["A", "B", "C"] transaction1 = Transaction(row1, header1, ("Class", 0)) item1 = Item("A", 1) item2 = Item("B", 1) item3 = Item("C", 0) item4 = Item("B", 5) ant1 = Antecedent([item1, item2]) ant2 = Antecedent([item2]) ant3 = Antecedent([item3]) ant4 = Antecedent([item4]) assert ant1 <= transaction1 assert ant2 <= transaction1 assert ant3 <= transaction1 self.assertFalse(ant4 <= transaction1) assert transaction1 >= ant1 assert transaction1 >= ant2 assert transaction1 >= ant3
def test_adding(self): item1 = Item("A", 1) item2 = Item("B", 1) item3 = Item("C", 0) item4 = Item("B", 5) appear1 = Appearance() appear1.add_to_LHS(item1) appear1.add_to_LHS(item2) assert appear1.lhs == [("A:=:1", "a"), ("B:=:1", "a")] appear1.add_to_RHS(item3) assert appear1.rhs == [("C:=:0", "c")] appear1.rhs = [("B:=:5", "c")] assert appear1.rhs == [("B:=:5", "c")] dictionary = appear1.dictionary assert dictionary == dict([("A:=:1", "a"), ("B:=:1", "a"), ("B:=:5", "c")]) appear1.lhs = [] dictionary2 = appear1.dictionary assert dictionary2 == dict([(None, "a"), ("B:=:5", "c")])
def test_init(self): item1 = Item("a", 3) item2 = Item("a", 3) item3 = Item("c", 2) ant1 = Antecedent([item1, item2, item3]) assert len(ant1.itemset) == 2
def test_getitem(self): row1 = [1, 1, 0] header1 = ["A", "B", "C"] transaction1 = Transaction(row1, header1, ("Class", 0)) assert transaction1[0] == Item("A", 1) assert transaction1[1] == Item("B", 1) assert transaction1[2] == Item("C", 0)
def test_getitem(self): item1 = Item("a", 3) item2 = Item("b", 3) item3 = Item("c", 2) ant1 = Antecedent([item1, item2, item3]) assert ant1[0] in [item1, item2, item3] assert ant1[1] in [item1, item2, item3] assert ant1[2] in [item1, item2, item3]
def test_getattr(self): item1 = Item("a", 3) item2 = Item("b", 3) item3 = Item("c", 2) ant1 = Antecedent([item1, item2, item3]) assert ant1.a == "3" assert ant1.b == "3" assert ant1.c == "2"
def test_hash(self): item1 = Item("a", 3) item2 = Item("b", 3) item3 = Item("c", 2) ant1 = Antecedent([item1, item2, item3]) ant2 = Antecedent([item1, item2, item3]) assert hash(ant1) == hash(ant2) assert ant1 == ant2
def test_len(self): item1 = Item("a", 3) item2 = Item("b", 3) item3 = Item("c", 2) item4 = Item("c", 4) ant1 = Antecedent([item1, item2, item3]) ant2 = Antecedent([item1, item2, item3, item4]) assert len(ant1) == 3 assert len(ant2) == 3
def test_len(self): item1 = Item("A", 1) item2 = Item("B", 1) ant1 = Antecedent([item1, item2]) cons1 = Consequent("Y", 1) car1 = ClassAssocationRule(ant1, cons1, 0.5, 0.9) assert len(car1) == 3
def test_init(self): rows1 = [[1, 1, 0, 0], [1, 1, 0, 1], [0, 0, 1, 1], [0, 1, 0, 1]] header1 = ["A", "B", "C", "Y"] transDB1 = TransactionDB(rows1, header1, unique_transactions=False) transaction1 = Transaction([1, 1, 0], "ABC", Item("Y", 0)) class_labels = [ Item("Y", 0), Item("Y", 1), Item("Y", 1), Item("Y", 1), ] assert transDB1.class_labels == class_labels assert transDB1.classes == ["0", "1", "1", "1"] assert transDB1.data[0] == transaction1
def test_compare(self): row1 = [1, 1, 0] header1 = ["A", "B", "C"] transaction1 = Transaction(row1, header1, ("Class", 0)) item1 = Item("A", 1) item2 = Item("B", 1) item3 = Item("C", 0) item4 = Item("B", 5) ant1 = Antecedent([item1, item2]) ant2 = Antecedent([item2]) ant3 = Antecedent([item3]) ant4 = Antecedent([item4]) cons1 = Consequent("Y", 1) cons2 = Consequent("Y", 2) cons3 = Consequent("Y", 3) # len: 2 car1 = ClassAssocationRule(ant1, cons1, 0.5, 0.9) # len: 1 car2 = ClassAssocationRule(ant2, cons2, 0.5, 0.9) car3 = ClassAssocationRule(ant3, cons3, 0.5, 0.9) car4 = ClassAssocationRule(ant4, cons3, 0.5, 1) sorted_cars = sorted([car1, car2, car3, car4], reverse=True) assert car1 < car2 assert car2 > car3 assert car3 < car2 assert car4 > car3 assert car1.antecedent <= transaction1 assert car2.antecedent <= transaction1 assert car3.antecedent <= transaction1 assert not car4.antecedent <= transaction1 assert sorted_cars[0] == car4
def test_createCARs(self): generated_rules = [('Y:=:1', (), 0.5, 0.5), ('Y:=:0', (), 0.5, 0.5), ('Y:=:1', ('A:=:1', ), 0.5, 1 / 3)] cars = createCARs(generated_rules) assert cars[0].consequent == Consequent("Y", 1) assert cars[0].confidence == 0.5 assert cars[0].support == 0.5 assert cars[1].consequent == Consequent("Y", 0) assert cars[1].confidence == 0.5 assert cars[1].support == 0.5 assert cars[2].consequent == Consequent("Y", 1) assert cars[2].antecedent == Antecedent([Item("A", 1)]) assert cars[2].confidence == 1 / 3 assert cars[2].support == 0.5
def test_inttostring(self): item = Item("a", 1) assert item[1] == "1"
def test_attributes(self): item = Item("a", "1") assert item.attribute == "a" assert item.value == "1"
def test_hash(self): item1 = Item("a", 1) item2 = Item("a", 1) assert hash(item1) == hash(item2)
def test_getitem(self): item = Item("a", "1") assert item[0] == "a" assert item[1] == "1"
def test_repr(self): item = Item("a", 1) string = "Item{('a', '1')}" assert repr(item) == string
def test_equals(self): item1 = Item("a", 1) item2 = Item("a", 1) assert item1 == item2