示例#1
0
 def test_length_one_integer_pos_neg_add_to_nonzero(self):
     """Test two length one sparse vectors contain positive and negative elements added to non-zero"""
     argument_one = {0: 2, 'length': 1}
     argument_two = {0: -1, 'length': 1}
     expected = {0: 1, 'length': 1}
     actual: dict = sparse_vector.sparse_add(argument_one, argument_two)
     self.assertEqual(expected, actual)
示例#2
0
 def test_length_more_than_one_different_integer_pos_and_neg(self):
     """Test two length more than one sparse vectors contain different positive and negative integer elements"""
     argument_one = {1: -2, 'length': 3}
     argument_two = {0: 1, 1: 1, 'length': 3}
     expected = {0: 1, 1: -1, 'length': 3}
     actual: dict = sparse_vector.sparse_add(argument_one, argument_two)
     self.assertEqual(expected, actual)
示例#3
0
 def test_length_one_zero_sparse_vector(self):
     """Test two length one sparse vectors contain zero"""
     argument_one = {'length': 1}
     argument_two = {'length': 1}
     expected = {'length': 1}
     actual: dict = sparse_vector.sparse_add(argument_one, argument_two)
     self.assertEqual(expected, actual)
示例#4
0
 def test_length_one_same_integer_negative(self):
     """Test two length one sparse vectors contain same negative integer elements"""
     argument_one = {0: -1, 'length': 1}
     argument_two = {0: -1, 'length': 1}
     expected = {0: -2, 'length': 1}
     actual: dict = sparse_vector.sparse_add(argument_one, argument_two)
     self.assertEqual(expected, actual)
示例#5
0
 def test_empty_sparse_vector(self):
     """Test two empty sparse vectors"""
     argument_one = {'length': 0}
     argument_two = {'length': 0}
     expected = None
     actual: dict = sparse_vector.sparse_add(argument_one, argument_two)
     self.assertEqual(expected, actual)
示例#6
0
 def test_length_more_than_one_mixture(self):
     """Test two length one vectors with different properties of the elements"""
     argument_one = {0: 8, 2: 1, 4: 2, 6: 1, 9: 1, 'length': 11}
     argument_two = {0: -8, 2: 2, 6: -3, 10: 4, 'length': 11}
     expected = {'length': 11, 2: 3, 4: 2, 6: -2, 9: 1, 10: 4}
     actual: dict = sparse_vector.sparse_add(argument_one, argument_two)
     self.assertEqual(expected, actual)
示例#7
0
 def test_length_more_than_one_same_position_different_integer(self):
     """Test two length more than one sparse vectors contain different positive integer elements at same position"""
     argument_one = {0: 1, 1: 2, 2: 3, 'length': 3}
     argument_two = {0: 4, 1: 5, 2: 6, 'length': 3}
     expected = {0: 5, 1: 7, 2: 9, 'length': 3}
     actual: dict = sparse_vector.sparse_add(argument_one, argument_two)
     self.assertEqual(expected, actual)
示例#8
0
 def test_sparse_add_unordered_with_negatives(self):
     actual = sparse_vector.sparse_add({
         4: -5,
         'length': 5,
         0: 4.3
     }, {
         'length': 5,
         2: 7.5,
         4: -6
     })
     expected = {'length': 5, 0: 4.3, 2: 7.5, 4: -11}
     self.assertEqual(actual, expected)
示例#9
0
 def test_sparse_add_different_length(self):
     actual = sparse_vector.sparse_add({
         0: 1,
         5: 2,
         6: 1,
         'length': 7
     }, {
         1: 2,
         3: 2,
         6: 2,
         'length': 8
     })
     expected = None
     self.assertEqual(actual, expected)
示例#10
0
 def test_sparse_add_ordered_dictionary(self):
     actual = sparse_vector.sparse_add({
         0: 1,
         5: 2,
         6: 1,
         'length': 8
     }, {
         1: 2,
         3: 2,
         6: 2,
         'length': 8
     })
     expected = {'length': 8, 0: 1, 1: 2, 3: 2, 5: 2, 6: 3}
     self.assertEqual(actual, expected)
示例#11
0
 def test_sparse_add_complementary_values(self):
     actual = sparse_vector.sparse_add({
         0: 1,
         1: 2,
         2: 3,
         'length': 8
     }, {
         0: -1,
         1: -2,
         2: -3,
         'length': 8
     })
     expected = {'length': 8}
     self.assertEqual(expected, actual)
示例#12
0
 def test_sparse_add_one_dict_all_zeroes(self):
     actual = sparse_vector.sparse_add({
         'length': 5,
         0: 0,
         1: 0,
         2: 0,
         3: 0
     }, {
         'length': 5,
         0: 1,
         1: 2,
         2: 3,
         3: 4
     })
     expected = {'length': 5, 0: 1, 1: 2, 2: 3, 3: 4}
     self.assertEqual(expected, actual)
示例#13
0
 def test_sparse_add_one_all_zeroes(self, _):
     actual = sparse_vector.sparse_add({0: 1, 1: 2, 2: 8, 'length': 3}, {'length': 3})
     expected = {0: 1, 1: 2, 2: 8, 'length': 3}
     self.assertEqual(actual, expected)
示例#14
0
 def test_sparse_add_dict_length_0(self):
     actual = sparse_vector.sparse_add({'length': 0}, {'length': 0})
     expected = {'length': 0}
     self.assertEqual(actual, expected)
示例#15
0
 def test_sparse_add_random_order_keys(self, _):
     actual = sparse_vector.sparse_add({'length': 5, 2: 7.5, 4: -6}, {4: -5, 'length': 5, 0: 4.3})
     expected = {0: 4.3, 2: 7.5, 4: -11, 'length': 5}
     self.assertEqual(actual, expected)
示例#16
0
 def test_sparse_add_length_one(self, _):
     actual = sparse_vector.sparse_add({'length': 1, 0: 2}, {0: 3, 'length': 1})
     expected = {0: 5, 'length': 1}
     self.assertEqual(actual, expected)
示例#17
0
 def test_sparse_add_complimentary_elements(self, _):
     actual = sparse_vector.sparse_add({'length': 2, 0: -1, 1: -2}, {0: 1, 'length': 2, 1: 2})
     expected = {'length': 2}
     self.assertEqual(actual, expected)
示例#18
0
 def test_sparse_add_different_lengths(self):
     actual = sparse_vector.sparse_add({'length': 2, 0: 2}, {0: 3, 'length': 1})
     expected = None
     self.assertEqual(actual, expected)
示例#19
0
 def test_sparse_add_only_zeroes(self, _):
     actual = sparse_vector.sparse_add({'length': 3}, {'length': 3})
     expected = {'length': 3}
     self.assertEqual(actual, expected)
示例#20
0
 def test_sparse_add_length_zero(self, _):
     actual = sparse_vector.sparse_add({'length': 0}, {'length': 0})
     expected = {'length': 0}
     self.assertEqual(actual, expected)