Exemple #1
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_dot_product(
         argument_one, argument_two)
     self.assertEqual(expected, actual)
Exemple #2
0
 def test_length_more_than_one_mixture(self):
     """Test two length one vectors with different properties of the elements"""
     argument_one = {0: 1, 1: -2, 2: -1, 3: -1, 'length': 3}
     argument_two = {0: 2, 2: -9, 3: 6, 'length': 3}
     expected = 5
     actual: dict = sparse_vector.sparse_dot_product(
         argument_one, argument_two)
     self.assertEqual(expected, actual)
Exemple #3
0
 def test_length_more_than_one_same_position_same_integer(self):
     """Test two length more than one sparse vector contain same integer elements at same position"""
     argument_one = {0: 1, 1: 2, 2: 1, 'length': 3}
     argument_two = {0: 1, 1: 2, 2: 1, 'length': 3}
     expected = 6
     actual: dict = sparse_vector.sparse_dot_product(
         argument_one, argument_two)
     self.assertEqual(expected, actual)
Exemple #4
0
 def test_length_more_than_one_different_position(self):
     """"Test two length more than one sparse vector contain different integer elements at different position"""
     argument_one = {1: 1, 2: 3, 'length': 3}
     argument_two = {0: 2, 'length': 3}
     expected = 0
     actual: dict = sparse_vector.sparse_dot_product(
         argument_one, argument_two)
     self.assertEqual(expected, actual)
Exemple #5
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 = 0
     actual: dict = sparse_vector.sparse_dot_product(
         argument_one, argument_two)
     self.assertEqual(expected, actual)
Exemple #6
0
 def test_length_one_integer_pos_neg(self):
     """Test two length one sparse vectors contain both positive and negative integers elements"""
     argument_one = {0: 1, 'length': 1}
     argument_two = {0: -1, 'length': 1}
     expected = -1
     actual: dict = sparse_vector.sparse_dot_product(
         argument_one, argument_two)
     self.assertEqual(expected, actual)
Exemple #7
0
 def test_sparse_dot_product_unordered_with_negatives(self):
     actual = sparse_vector.sparse_dot_product({
         4: -5,
         'length': 5,
         0: 4.3
     }, {
         'length': 5,
         2: 7.5,
         4: -6
     })
     expected = 30
     self.assertEqual(actual, expected)
Exemple #8
0
 def test_sparse_dot_product_same_length_one_all_zeroes(self):
     actual = sparse_vector.sparse_dot_product(
         {
             'length': 5,
             0: 0,
             1: 0,
             2: 0
         }, {
             'length': 5,
             0: 1,
             1: 2,
             2: 3
         })
     expected = 0
     self.assertEqual(actual, expected)
Exemple #9
0
 def test_sparse_dot_product_same_length(self):
     actual = sparse_vector.sparse_dot_product(
         {
             0: 1,
             5: 2,
             6: 1,
             'length': 8
         }, {
             1: 2,
             3: 2,
             6: 2,
             'length': 8
         })
     expected = 2
     self.assertEqual(actual, expected)
Exemple #10
0
 def test_sparse_dot_product_different_length(self):
     actual = sparse_vector.sparse_dot_product(
         {
             0: 1,
             5: 2,
             6: 1,
             'length': 7
         }, {
             1: 2,
             3: 2,
             6: 2,
             'length': 8
         })
     expected = None
     self.assertEqual(actual, expected)
Exemple #11
0
 def test_sparse_dot_product_length_zero(self):
     actual = sparse_vector.sparse_dot_product({'length': 0}, {'length': 0})
     expected = 0
     self.assertEqual(actual, expected)
 def test_sparse_dot_product_random_order_keys(self):
     actual = sparse_vector.sparse_dot_product({'length': 5, 2: 7.5, 4: -6}, {4: -5, 'length': 5, 0: 4.3})
     expected = 30
     self.assertEqual(actual, expected)
 def test_sparse_dot_product_one_all_zeroes(self):
     actual = sparse_vector.sparse_dot_product({'length': 3, 0: 2, 2: 7}, {'length': 3})
     expected = 0
     self.assertEqual(actual, expected)
 def test_sparse_dot_product_different_lengths(self):
     actual = sparse_vector.sparse_dot_product({'length': 1, 0: 7}, {'length': 2, 0: -2})
     expected = None
     self.assertEqual(actual, expected)
 def test_sparse_dot_product_length_one(self):
     actual = sparse_vector.sparse_dot_product({'length': 1, 0: 7}, {'length': 1, 0: -2})
     expected = -14
     self.assertEqual(actual, expected)
 def test_sparse_dot_product_only_zeroes(self):
     actual = sparse_vector.sparse_dot_product({'length': 5}, {'length': 5})
     expected = 0
     self.assertEqual(actual, expected)