Skip to content

Commit

Permalink
Even nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdalpino committed Oct 16, 2024
1 parent 60b120a commit a2f05ca
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions tests/test_bloom_filter.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import unittest
import random
import string

import okbloomer
from okbloomer import BloomFilter

class TestBloomFilter(unittest.TestCase):
from unittest import TestCase

class TestBloomFilter(TestCase):
def test_insert_and_exists(self):
filter = okbloomer.BloomFilter()
filter = BloomFilter()

self.assertEqual(filter.false_positive_rate, 0)

Expand All @@ -27,24 +28,21 @@ def test_insert_and_exists(self):
self.assertFalse(filter.exists('baz'))

def test_exists_or_insert(self):
filter = okbloomer.BloomFilter()
filter = BloomFilter()

self.assertFalse(filter.exists_or_insert('foo'))

self.assertTrue(filter.exists_or_insert('foo'))

self.assertFalse(filter.exists_or_insert('bar'))

self.assertTrue(filter.exists_or_insert('bar'))

self.assertFalse(filter.exists_or_insert('baz'))

self.assertTrue(filter.exists_or_insert('baz'))

def test_autoscaling(self):
random.seed(1)

filter = okbloomer.BloomFilter(
filter = BloomFilter(
max_false_positive_rate=0.001,
num_hashes=4,
layer_size=320000,
Expand All @@ -59,11 +57,11 @@ def test_autoscaling(self):

filter.insert('bar')

self.assertTrue(filter.exists('foo'))
self.assertTrue(filter.exists('bar'))
self.assertFalse(filter.exists('baz'))

self.assertEqual(filter.num_layers, 6)
self.assertLessEqual(filter.false_positive_rate, 0.001)
self.assertLessEqual(filter.utilization, 1.0)
self.assertGreater(filter.capacity, 0.0)

self.assertTrue(filter.exists('foo'))
self.assertTrue(filter.exists('bar'))
self.assertFalse(filter.exists('baz'))

0 comments on commit a2f05ca

Please sign in to comment.