def test_projectPathBestCost(self, numPaths=100): for _ in range(numPaths): childrenDict, startNode = getDtwDag(randint(1, 10), randint(1, 10)) path = getRandomDagPath(childrenDict, startNode) pathCosts = randn(len(path)) yIndexSeq = dtw.projectPathBestCost(path, pathCosts) # (FIXME : code below is not very transparent) yIndicesSeq = dtw.projectPathAll(path) assert len(yIndexSeq) == len(yIndicesSeq) costsSeq = dtw.projectPathAll([ (i, cost) for (i, j), cost in zip(path, pathCosts) ]) assert len(costsSeq) == len(yIndicesSeq) for j, js, costs in zip(yIndexSeq, yIndicesSeq, costsSeq): minCost = min(costs) assert j in [ j2 for j2, cost in zip(js, costs) if cost == minCost ]
def test_projectPathAll(self, numPaths=100): for _ in range(numPaths): path = [] for i in range(randint(1, 6)): for _ in range(randint(1, 4)): path.append((i, randint(20))) yIndicesSeq = dtw.projectPathAll(path) pathAgain = [(i, j) for i, yIndices in enumerate(yIndicesSeq) for j in yIndices] assert pathAgain == path
def test_projectPathAll(self, numPaths=100): for _ in range(numPaths): path = [] for i in range(randint(1, 6)): for _ in range(randint(1, 4)): path.append((i, randint(20))) yIndicesSeq = dtw.projectPathAll(path) pathAgain = [ (i, j) for i, yIndices in enumerate(yIndicesSeq) for j in yIndices ] assert pathAgain == path