def test_negate_with_zero(self): vec = SparseVector.zero(4) expected = SparseVector.zero(4) result = -vec self.assertEqual(result, expected)
def test_add_with_zero_vector(self): a = SparseVector.from_list([1, 0, 2, 0, 3, 0, 4, 5]) b = SparseVector.zero(8) expected = SparseVector.zero(8) result = a + b self.assertEqual(expected, result)
def test_venn_with_zero(self): a = SparseVector.from_list([1, 0, 2, 0, 3, 4, 0, 5]) b = SparseVector.zero(8) expected0 = SparseVector.zero(8) expected1 = SparseVector.from_list([1, 0, 2, 0, 3, 4, 0, 5]) result0, result1 = a.venn(b) self.assertEqual(result0, expected0) self.assertEqual(result1, expected1)
def test_value_at_when_value_is_zero(self): vec = SparseVector.zero(7) expected = [0] * 7 result = [vec.value_at(i) for i in range(vec.size)] self.assertEqual(result, expected)
def test_to_dense_with_zero(self): vec = SparseVector.zero(7) expected = np.zeros(7, dtype=np.uint16) result = vec.to_dense() self.assertTrue(np.array_equal(result, expected))
def test_sum_with_zero(self): vec = SparseVector.zero(7) expected = 0 result = vec.sum() self.assertEqual(result, expected)
def test_multiply_with_zero_scalar(self): vec = SparseVector.from_list([1, 0, 2, 0, 3, 0, 4, 5]) scalar = 0 expected = SparseVector.zero(8) result = vec * scalar self.assertEqual(result, expected)
def test_compact_with_zero(self): vec = SparseVector(np.zeros(10, dtype=np.uint16), np.arange(10, dtype=np.uint32), 10) vec.compact() expected = SparseVector.zero(10) result = copy(vec) self.assertEqual(result, expected)