def test_node_nd(self): n = 16 xadj, adjncy = make_cycle(n) perm, iperm = _metis.node_nd(xadj, adjncy) nose.tools.assert_equal(set(perm), set(range(n))) nose.tools.assert_equal(abs(perm[-1] - perm[-2]), n // 2) nose.tools.ok_(set(range(min(perm[-2:]) + 1, max(perm[-2:]))) in (set(perm[0:n // 2 - 1]), set(perm[n // 2 - 1:-2]))) nose.tools.ok_(all(i == perm[iperm[i]] for i in range(n)))
def test_selfloops(self): n = 16 xadj = list(range(0, 3 * n + 1, 3)) adjncy = list( itertools.chain.from_iterable( zip(itertools.chain([n - 1], range(n - 1)), range(n), itertools.chain(range(1, n), [0])))) perm, iperm = _metis.node_nd(xadj, adjncy) nose.tools.assert_equal(set(perm), set(range(n))) nose.tools.assert_equal(abs(perm[-1] - perm[-2]), n // 2) nose.tools.ok_(set(range(min(perm[-2:]) + 1, max(perm[-2:]))) in (set(perm[0:n // 2 - 1]), set(perm[n // 2 - 1:-2]))) nose.tools.ok_(all(i == perm[iperm[i]] for i in range(n)))