def test_estimate_cardinality_with_clip(self): base_sketch = VectorOfCounts(num_buckets=64, random_seed=3) base_sketch.add_ids(range(100)) sketch_list_a = [base_sketch] sketch_list_b = [base_sketch] for _ in range(3): empty_sketch = VectorOfCounts(num_buckets=64, random_seed=3) sketch_list_a.append(empty_sketch) # add empty sketch sketch_list_b.append(base_sketch) # add same sketch estimator = SequentialEstimator(clip=True) result_a = estimator(sketch_list_a) result_b = estimator(sketch_list_b) self.assertEqual(result_a, base_sketch.cardinality(), msg='Fail to detect the no-intersection case.') self.assertEqual(result_b, base_sketch.cardinality(), msg='Fail to detect the full-intersection case.')
def test_add_ids(self): sketch = VectorOfCounts(num_buckets=8, random_seed=0) sketch.add_ids([1]) self.assertEqual(sketch.cardinality(), 1)