Ejemplo n.º 1
0
def findX(L, K):
    '''Algorithm 1 step 11'''
    X = Label()
    X.ind = [0, 0, 0, 0]
    h = len(K)

    for index in range(1, h):
        X.append(K[index - 1], findAttributeByKey(K[index - 1], L))
    X.append(K[h - 1], constant.PERPEN_SYM)
    return X
Ejemplo n.º 2
0
class LabelTest(unittest.TestCase):
    def setUp(self):
        self.label = Label()
        self.label.append(1, 9)
        self.label.append(-5, constant.PERPEN_SYM)

    def test_index_is_ok(self):
        self.assertEqual(self.label[1].attribute, 9)
        self.assertEqual(self.label[2].key, -5)
        with self.assertRaises(IndexError):
            self.label[0]
        self.assertEqual(self.label[-1].key, -5)
        self.assertEqual(self.label[-2].key, 1)

    def test_next_unlabled(self):
        nodes = [5, 4, 3, 2, 1, 0]
        labels = {5: Label(), 4: Label(), 3: None, 2: None, 1: None, 0: None}
        rt = RootedTree(nx.Graph(), 0, labels)
        self.assertEqual(copmanager.nextUnlabled(rt, nodes), 3)

    def test_findAttrByKey(self):
        SVs = [SV(1, constant.PERPEN_SYM), SV(2, 3), SV(3, 4), SV(3, 5)]
        self.assertEqual(copmanager.findAttributeByKey(2, SVs), 3)

    def test_findX(self):
        K = [9, 8, 6]
        L = [
            SV(9, 1),
            SV(8, 3),
            SV(6, 4),
            SV(4, 9),
            SV(4, constant.PERPEN_SYM)
        ]
        self.assertEqual(
            copmanager.findX(L, K),
            Label.make(9, 1).append(8, 3).append(6, constant.PERPEN_SYM))