コード例 #1
0
    def test_invalid_input(self):
        """Test error-handling upon invalid input."""
        # Invalid dimensions.
        with self.assertRaises(DissimilarityMatrixError):
            _ = randdm(0)

        # Invalid dimensions.
        with self.assertRaises(ValueError):
            _ = randdm(-1)

        # Invalid number of IDs.
        with self.assertRaises(DissimilarityMatrixError):
            _ = randdm(2, ids=['foo'])
コード例 #2
0
ファイル: test_distance.py プロジェクト: Jorge-C/bipy
    def test_invalid_input(self):
        """Test error-handling upon invalid input."""
        # Invalid dimensions.
        with self.assertRaises(DissimilarityMatrixError):
            _ = randdm(0)

        # Invalid dimensions.
        with self.assertRaises(ValueError):
            _ = randdm(-1)

        # Invalid number of IDs.
        with self.assertRaises(DissimilarityMatrixError):
            _ = randdm(2, ids=['foo'])
コード例 #3
0
    def test_default_usage(self):
        """Test generating random distance matrices."""
        exp = DistanceMatrix(np.asarray([[0.0]]), ['1'])
        obs = randdm(1)
        self.assertEqual(obs, exp)

        obs = randdm(2)
        self.assertEqual(obs.shape, (2, 2))
        self.assertEqual(obs.ids, ('1', '2'))

        obs1 = randdm(5)
        num_trials = 10
        found_diff = False
        for _ in range(num_trials):
            obs2 = randdm(5)

            if obs1 != obs2:
                found_diff = True
                break

        self.assertTrue(found_diff)
コード例 #4
0
    def test_random_fn(self):
        """Test passing a different random function than the default."""
        def myrand(num_rows, num_cols):
            # One dm to rule them all...
            data = np.empty((num_rows, num_cols))
            data.fill(42)
            return data

        exp = DistanceMatrix(np.asarray([[0, 42, 42], [42, 0, 42],
                                         [42, 42, 0]]), ['1', '2', '3'])
        obs = randdm(3, random_fn=myrand)
        self.assertEqual(obs, exp)
コード例 #5
0
    def test_default_usage(self):
        """Test generating random distance matrices."""
        exp = DistanceMatrix(np.asarray([[0.0]]), ['1'])
        obs = randdm(1)
        self.assertEqual(obs, exp)

        obs = randdm(2)
        self.assertEqual(obs.shape, (2, 2))
        self.assertEqual(obs.ids, ('1', '2'))

        obs1 = randdm(5)
        num_trials = 10
        found_diff = False
        for _ in range(num_trials):
            obs2 = randdm(5)

            if obs1 != obs2:
                found_diff = True
                break

        self.assertTrue(found_diff)
コード例 #6
0
    def test_random_fn(self):
        """Test passing a different random function than the default."""
        def myrand(num_rows, num_cols):
            # One dm to rule them all...
            data = np.empty((num_rows, num_cols))
            data.fill(42)
            return data

        exp = DistanceMatrix(
            np.asarray([[0, 42, 42], [42, 0, 42], [42, 42, 0]]),
            ['1', '2', '3'])
        obs = randdm(3, random_fn=myrand)
        self.assertEqual(obs, exp)
コード例 #7
0
 def test_constructor(self):
     """Test generating random dist mats with a specific constructor."""
     exp = DissimilarityMatrix(np.asarray([[0.0]]), ['1'])
     obs = randdm(1, constructor=DissimilarityMatrix)
     self.assertEqual(obs, exp)
     self.assertEqual(type(obs), DissimilarityMatrix)
コード例 #8
0
 def test_ids(self):
     """Test generating random distance matrices with specific IDs."""
     ids = ['foo', 'bar', 'baz']
     obs = randdm(3, ids=ids)
     self.assertEqual(obs.shape, (3, 3))
     self.assertEqual(obs.ids, tuple(ids))
コード例 #9
0
 def test_constructor(self):
     """Test generating random dist mats with a specific constructor."""
     exp = DissimilarityMatrix(np.asarray([[0.0]]), ['1'])
     obs = randdm(1, constructor=DissimilarityMatrix)
     self.assertEqual(obs, exp)
     self.assertEqual(type(obs), DissimilarityMatrix)
コード例 #10
0
 def test_ids(self):
     """Test generating random distance matrices with specific IDs."""
     ids = ['foo', 'bar', 'baz']
     obs = randdm(3, ids=ids)
     self.assertEqual(obs.shape, (3, 3))
     self.assertEqual(obs.ids, tuple(ids))