Exemplo n.º 1
0
    def test_parity(self):
        """
        test parity with random data
        """
        for n_col in range(1,7):
            for n_row in range(1,50):
                A = arange(n_col*n_row)
                random.shuffle(A)
                A = A.reshape((n_row,n_col))

                s_parity = simplex_array_parity(A)

                for n,row in enumerate(A):
                    assert_equal(s_parity[n],relative_parity(row,sorted(row)))
Exemplo n.º 2
0
    def test_simple(self):
        cases = []
        cases.append(([[0]],[0]))
        cases.append(([[1]],[0]))
        cases.append(([[0],[1]],[0,0]))
        cases.append(([[0,1]],[0]))
        cases.append(([[1,0]],[1]))
        cases.append(([[0,1],[1,0]],[0,1]))
        cases.append(([[53,2]],[1]))
        cases.append(([[117,235]],[0]))
        cases.append(([[0,1,4]],[0]))
        cases.append(([[0,4,1]],[1]))
        cases.append(([[4,0,1]],[0]))
        cases.append(([[0,1,4],[0,4,1],[4,0,1]],[0,1,0]))

        for s,p in cases:
            assert_equal(simplex_array_parity(array(s)),array(p))