Пример #1
0
 def test_bw_01(self):
     """Verify that an exception is raised if the new row is not a list."""
     mtrx = csr_matrix([[0, 1, 0],
                        [1, 0, 1],
                        [0, 1, 0]])
     new_row = -1
     with self.assertRaises(AssertionError):
         Utils.set_row_csr(mtrx, 2, new_row)
Пример #2
0
 def test_bw_02(self):
     """Verify that an exception is raised if the new row does not have enough elements."""
     mtrx = csr_matrix([[0, 1, 0],
                        [1, 0, 1],
                        [0, 1, 0]])
     new_row = [-1, -1]
     with self.assertRaises(AssertionError):
         Utils.set_row_csr(mtrx, 2, new_row)
Пример #3
0
 def test_bw_03(self):
     """Verify that an exception is raised if the row index larger than then number of rows in A."""
     mtrx = csr_matrix([[0, 1, 0],
                        [1, 0, 1],
                        [0, 1, 0]])
     new_row = [-1, -1, -1]
     with self.assertRaises(AssertionError):
         Utils.set_row_csr(mtrx, 3, new_row)
Пример #4
0
 def test_gw_03(self):
     mtrx = csr_matrix([[0, 1, 0],
                        [1, 0, 1],
                        [0, 1, 0]])
     new_row = np.array([-1, -1, -1], dtype=float)
     Utils.set_row_csr(mtrx, 2, new_row)
     e = csr_matrix([[0, 1, 0],
                     [1, 0, 1],
                     [-1, -1, -1]])
     TestUtils.equal_csr_matrix(self, mtrx, e, 'new_csr')
Пример #5
0
 def test_gw_04(self):
     mtrx = csr_matrix([[0, 1, 0],
                        [1, 0, 1],
                        [0, 1, 0]])
     new_row = [-1, -1, -1]
     Utils.set_row_csr(mtrx, 2, new_row)
     e = csr_matrix([[0, 1, 0],
                     [1, 0, 1],
                     [-1, -1, -1]])
     TestUtils.equal_csr_matrix(self, mtrx, e, 'new_csr')
Пример #6
0
 def test_gw_01(self):
     mtrx = csr_matrix([[0, 1, 0],
                        [1, 0, 1],
                        [0, 1, 0]])
     new_row = np.array([2, 3, 4])
     Utils.set_row_csr(mtrx, 0, new_row)
     e = csr_matrix([[2, 3, 4],
                     [1, 0, 1],
                     [0, 1, 0]])
     TestUtils.equal_csr_matrix(self, mtrx, e, 'new_csr')
Пример #7
0
 def test_gw_03(self):
     line = 'before_20141017'
     character = '_'
     r = Utils.substring_after_character(line, character,
                                         include_character=False)
     e = '20141017'
     TestUtils.equal_str(self, r, e, 'line')
Пример #8
0
 def test_gw_03(self):
     """Verify that empty lists do not raise an exception."""
     lst_a = []
     lst_b = []
     r = Utils.sort_list_by_another_list(lst_a, lst_b, reverse=False)
     e = []
     self.assertListEqual(r, e)
Пример #9
0
 def test_gw_02(self):
     mtrx = csr_matrix(np.identity(6), dtype=int)
     r = Utils.delete_rows_csr(mtrx, [0, 1, 2])
     e = csr_matrix([[0, 0, 0, 1, 0, 0],
                     [0, 0, 0, 0, 1, 0],
                     [0, 0, 0, 0, 0, 1]])
     TestUtils.equal_csr_matrix(self, r, e, 'removed row csr_matrix')
Пример #10
0
 def test_gw_01(self):
     mtrx = csr_matrix(np.identity(6), dtype=int)
     r = Utils.delete_rows_csr(mtrx, [1, 3])
     e = csr_matrix([[1, 0, 0, 0, 0, 0],
                     [0, 0, 1, 0, 0, 0],
                     [0, 0, 0, 0, 1, 0],
                     [0, 0, 0, 0, 0, 1]])
     TestUtils.equal_csr_matrix(self, r, e, 'removed row csr_matrix')
     orig = csr_matrix(np.identity(6), dtype=int)
     TestUtils.equal_csr_matrix(self, mtrx, orig, 'original csr_matrix')
Пример #11
0
 def test_gw_01(self):
     a = np.ones(shape=[4, 4]) + 3 * np.eye(4)
     a[0, 0] = 100
     a[3, 3] = 25
     a[0, 3] = 16
     r = Utils.normalize_overlap_matrix(a)
     e = np.matrix([[1., 0.05, 0.05, 0.32],
                    [0.05, 1., 0.25, 0.1],
                    [0.05, 0.25, 1., 0.1],
                    [0.02, 0.1, 0.1, 1.]])
     np.testing.assert_array_almost_equal(r, e)
Пример #12
0
 def disabled_test_gw_04(self):
     """
     Note: the function does not work for nested sublists,
     so this test will fail. That's why it is commented out.
     It does not make sense to check for failure, since it
     would be better if it did not fail. It's a fact of life.
     """
     a = np.array([[1], [2, [3, 4]], [], [2, 3, 4]])
     r = Utils.flatten_np_array(a)
     e = np.array([1, 2, 3, 4, 2, 3, 4])
     TestUtils.equal_np_matrix(self, r, e, 'flat array')
Пример #13
0
 def test_gw_02(self):
     lst_a = ['a', 'b', 'c', 'd', 'e']
     lst_b = [0, 0, 3, 2, 0]
     r = Utils.sort_list_by_another_list(lst_a, lst_b, reverse=True)
     e = ['c', 'd', 'a', 'b', 'e']
     self.assertListEqual(r, e)
Пример #14
0
 def gw(self, a, e):
     r = Utils.list2dict(a)
     self.assertDictEqual(r, e)
Пример #15
0
 def gw(self, a, e):
     r = Utils.filter_array(a)
     TestUtils.equal_list(self, r, e)
Пример #16
0
 def gw(self, a, e):
     r = Utils.flatten_np_array(a)
     TestUtils.equal_list(self, r, e)
Пример #17
0
 def gw(self, lst, dx, e):
     """Verify that the smallest element is incremented."""
     Utils.increment_smallest(lst, dx)
     TestUtils.equal_list(self, lst, e)
Пример #18
0
 def bw(self, a):
     with self.assertRaises(AssertionError):
         Utils.unique(a)
Пример #19
0
 def gw(self, a, e):
     """Verify that a frequency count can be converted into an occurrence list."""
     r = Utils.frequency_count2occurrence_list(a)
     TestUtils.equal_list(self, r, e)
Пример #20
0
 def test_bw_03(self):
     with self.assertRaisesRegex(AssertionError, 'list'):
         a = {1: 0, 2: 1, 3: 2}
         Utils.list2dict(a)
Пример #21
0
 def gw(self, hsb, e):
     """Verify that a hsb value is properly transformed into a rgb value"""
     r = Utils.hsb2rgb(hsb)
     TestUtils.equal_list(self, r, e)
Пример #22
0
 def test_bw_01(self):
     """Verify that an error is raised if there is a zero on the diagonal"""
     with self.assertRaisesRegex(AssertionError, 'diagonal'):
         a = np.reshape(np.arange(16), [4, 4])
         Utils.normalize_overlap_matrix(a)
Пример #23
0
 def test_gw_04(self):
     line = 'before_20141017'
     character = '.'
     r = Utils.substring_after_character(line, character,
                                         include_character=True)
     self.assertIs(r, None, 'If character not in line, None shall be returned.')
Пример #24
0
 def gw(self, a, e):
     """Verify that None rows are filtered out a frequency count."""
     r = Utils.filter_none_from_frequency_count(a)
     TestUtils.equal_list(self, r, e)
Пример #25
0
 def test_bw_02(self):
     """Verify that an error is raised if the overlap matrix is not square."""
     with self.assertRaisesRegex(AssertionError, 'square'):
         a = np.matrix(np.arange(1, 5))
         Utils.normalize_overlap_matrix(a)
Пример #26
0
 def test_gw_03(self):
     mtrx = csr_matrix(np.identity(6), dtype=int)
     r = Utils.delete_rows_csr(mtrx, range(6))
     e = (0, 6)
     TestUtils.equal_tuple_numbers(self, r.shape, e, 'shape of empty matrix')
Пример #27
0
 def test_bw_02(self):
     with self.assertRaisesRegex(AssertionError, 'list'):
         a = {1, 2, 3}
         Utils.list2dict(a)
Пример #28
0
 def test_bw_01(self):
     mtrx = csr_matrix(np.identity(6), dtype=int)
     with self.assertRaisesRegex(AssertionError, 'out of bounds'):
         # Index out of bounds
         Utils.delete_rows_csr(mtrx, [7])
Пример #29
0
 def gw(self, a, e, sep=None):
     if sep is None:
         r = Utils.list2string(a)
     else:
         r = Utils.list2string(a, sep)
     self.assertEqual(r, e)
Пример #30
0
 def gw(self, a, e):
     r = Utils.unique(a)
     self.assertListEqual(r, e)