def testInteractionsToNodes(): mca = MedeinaCumulativeApplication("dir") mca.interactionStore = [("S1", "S2"), ("S2", "S3"), ("S2", "S2")] unittest.TestCase().assertCountEqual(mca.interactionsToNodes(), ["S1", "S2", "S3"]) mca = MedeinaCumulativeApplication("dir") mca.interactionStore = [] unittest.TestCase().assertCountEqual(mca.interactionsToNodes(), []) mca = MedeinaCumulativeApplication("dir") mca.interactionStore = [("S2", "S2")] unittest.TestCase().assertCountEqual(mca.interactionsToNodes(), ["S2"])
def testOutputMatrix(): def orderTuples(itms): return list( map(lambda x: (x[0], x[1]) if x[0] < x[1] else (x[1], x[0]), itms)) def toHashable(listOfLists): return list(map(lambda x: tuple(x), listOfLists)) mca = MedeinaCumulativeApplication("dir") mca.interactionStore = [ ("Spec1", "Spec2"), ("Spec2", "Spec3"), ("Spec3", "Spec4"), ("Spec1", "Spec2"), ("Spec5", "Spec6"), ] expected = [ ("Spec5", "Spec6"), ("Spec4", "Spec3"), ("Spec3", "Spec2"), ("Spec2", "Spec1"), ] matrixOut, labelOrder = mca.to_matrix() crushed = [] matrixOut = matrixOut.tolist() for kr, row in enumerate(matrixOut): for kc, col in enumerate(row): if col == 1: crushed.append((labelOrder[kr], labelOrder[kc])) crushed = list(set(orderTuples(crushed))) unittest.TestCase().assertCountEqual( list(set(orderTuples(mca.interactionStore))), crushed)
def testOutputGraphOriginal(): def orderTuples(itms): return list( map(lambda x: (x[0], x[1]) if x[0] < x[1] else (x[1], x[0]), itms)) mca = MedeinaCumulativeApplication("dir") mca.interactionStore = [ ("Spec1", "Spec2"), ("Spec2", "Spec3"), ("Spec3", "Spec4"), ("Spec1", "Spec2"), ("Spec5", "Spec6"), ] mca.scientificToUser = { "Spec1": "USpec1", "Spec2": "USpec2", "Spec3": "USpec3", "Spec4": "USpec4", "Spec5": "USpec5", "Spec6": "USpec6", } expected = [ ("USpec1", "USpec2"), ("USpec2", "USpec3"), ("USpec3", "USpec4"), ("USpec5", "USpec6"), ] unittest.TestCase().assertCountEqual( orderTuples(mca.to_graph_original().edges), orderTuples(expected))
def testOutputListWithUserMapping(): mca = MedeinaCumulativeApplication("dir") mca.interactionStore = [ ("Spec1", "Spec2"), ("Spec2", "Spec3"), ("Spec3", "Spec4"), ("Spec1", "Spec2"), ("Spec5", "Spec6"), ] mca.scientificToUser = { "Spec1": "USpec1", "Spec2": "USpec2", "Spec3": "USpec3", "Spec4": "USpec4", "Spec5": "USpec5", "Spec6": "USpec6", } expectedOne = [ ("Spec1", "Spec2"), ("Spec2", "Spec3"), ("Spec3", "Spec4"), ("Spec5", "Spec6"), ] expectedTwo = [ ("USpec1", "USpec2"), ("USpec2", "USpec3"), ("USpec3", "USpec4"), ("USpec5", "USpec6"), ] expected = list(zip(expectedOne, expectedTwo)) unittest.TestCase().assertCountEqual(mca.to_list_original(), expected)
def testOutputList(): mca = MedeinaCumulativeApplication("dir") mca.interactionStore = [ ("Spec1", "Spec2"), ("Spec2", "Spec3"), ("Spec3", "Spec4"), ("Spec1", "Spec2"), ("Spec5", "Spec6"), ] expected = [ ("Spec1", "Spec2"), ("Spec2", "Spec3"), ("Spec3", "Spec4"), ("Spec5", "Spec6"), ] unittest.TestCase().assertCountEqual(mca.to_list(), expected)
def testOutputMatrixOriginal(): def orderTuples(itms): return list( map(lambda x: (x[0], x[1]) if x[0] < x[1] else (x[1], x[0]), itms)) mca = MedeinaCumulativeApplication("dir") mca.interactionStore = [ ("Spec1", "Spec2"), ("Spec2", "Spec3"), ("Spec3", "Spec4"), ("Spec1", "Spec2"), ("Spec5", "Spec6"), ] mca.scientificToUser = { "Spec1": "USpec1", "Spec2": "USpec2", "Spec3": "USpec3", "Spec4": "USpec4", "Spec5": "USpec5", "Spec6": "USpec6", } crushed = [] matrixOut, labelOrder = mca.to_matrix_original() matrixOut = matrixOut.tolist() for kr, row in enumerate(matrixOut): for kc, col in enumerate(row): if col == 1: crushed.append((labelOrder[kr], labelOrder[kc])) crushed = list(set(orderTuples(crushed))) expected = [ ("USpec1", "USpec2"), ("USpec2", "USpec3"), ("USpec3", "USpec4"), ("USpec5", "USpec6"), ] unittest.TestCase().assertCountEqual(orderTuples(expected), crushed)