示例#1
0
    def test_condensed_indices_scalar_and_list(self):
        """Test input where i is a scalar and j is a list."""
        for fixed_i in range(self.n):
            # pick out the cases with i as the first index
            tests = zip(self.test_cases, self.expected)

            j_i = []
            expected_i = []
            for (i, j), expected in tests:
                if i == fixed_i:
                    j_i.append(j)
                    expected_i.append(expected)

            # test with scalar input
            actual = phdlib.condensed_indices(self.n, fixed_i, j_i)
            np.testing.assert_equal(actual, expected_i)

            # now test with length-1 list
            actual = phdlib.condensed_indices(self.n, [fixed_i], j_i)
            np.testing.assert_equal(actual, expected_i)
示例#2
0
 def test_condensed_indices_scalars(self):
     for case, expected in zip(self.test_cases, self.expected):
         actual = phdlib.condensed_indices(self.n, *case)
         self.assertEqual(actual, expected)
         self.assertIsInstance(actual, np.integer)
示例#3
0
 def test_condensed_indices_lists(self):
     i, j = zip(*self.test_cases)
     actual = phdlib.condensed_indices(self.n, i, j)
     np.testing.assert_equal(actual, self.expected)
示例#4
0
 def test_condensed_indices_checks(self):
     # don't allow on-diagonal indices or out-of-bounds indices
     with self.assertRaises(ValueError):
         phdlib.condensed_indices(self.n, 0, 0, check=True)
         phdlib.condensed_indices(self.n, -1, 0, check=True)
         phdlib.condensed_indices(self.n, 42, 0, check=True)