Skip to content

Commit

Permalink
🧪 updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akashchouhan16 committed Nov 3, 2023
1 parent 4b05cf7 commit 9f4e010
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 16 deletions.
8 changes: 4 additions & 4 deletions test/classical.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const BloomFilter = require('../build/classicalBloom/main');
describe('Classical bloom filter tests', () => {
let filter;

beforeEach(() => {
beforeAll(() => {
filter = new BloomFilter(1000, 0.01);
});

afterEach(() => {
afterAll(() => {
filter = null;
});

Expand Down Expand Up @@ -47,11 +47,11 @@ describe('Classical bloom filter tests', () => {
describe('Classical bloom instance with invalid inputs', () => {
let filter_2;

beforeEach(() => {
beforeAll(() => {
filter_2 = new BloomFilter(null, null);
});

afterEach(() => {
afterAll(() => {
filter_2 = null;
});

Expand Down
8 changes: 4 additions & 4 deletions test/counting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const CountingBloomFilter = require('../build/countingBloom/main');
describe('Counting bloom filter tests', () => {
let filter;

beforeEach(() => {
beforeAll(() => {
filter = new CountingBloomFilter(1000, 0.01);
});

afterEach(() => {
afterAll(() => {
filter = null;
});

Expand Down Expand Up @@ -47,11 +47,11 @@ describe('Counting bloom filter tests', () => {
describe('Counting bloom instance with invalid inputs', () => {
let filter_2;

beforeEach(() => {
beforeAll(() => {
filter_2 = new CountingBloomFilter(null, null);
});

afterEach(() => {
afterAll(() => {
filter_2 = null;
});

Expand Down
8 changes: 4 additions & 4 deletions test/cuckoo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const CuckooBloomFilter = require('../build/cuckooBloom/main');
describe('Cuckoo bloom filter tests', () => {
let filter;

beforeEach(() => {
beforeAll(() => {
filter = new CuckooBloomFilter(1000, 0.01);
});

afterEach(() => {
afterAll(() => {
filter = null;
});

Expand Down Expand Up @@ -47,11 +47,11 @@ describe('Cuckoo bloom filter tests', () => {
describe('Cuckoo bloom instance with invalid inputs', () => {
let filter_2;

beforeEach(() => {
beforeAll(() => {
filter_2 = new CuckooBloomFilter(null, null);
});

afterEach(() => {
afterAll(() => {
filter_2 = null;
});

Expand Down
8 changes: 4 additions & 4 deletions test/partitioned.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const PartitionedBloomFilter = require('../build/partitionedBloom/main');
describe('Partitioned bloom filter tests', () => {
let filter;

beforeEach(() => {
beforeAll(() => {
filter = new PartitionedBloomFilter(1000, 0.01);
});

afterEach(() => {
afterAll(() => {
filter = null;
});

Expand Down Expand Up @@ -47,11 +47,11 @@ describe('Partitioned bloom filter tests', () => {
describe('Partitioned bloom instance with invalid inputs', () => {
let filter_2;

beforeEach(() => {
beforeAll(() => {
filter_2 = new PartitionedBloomFilter(null, null);
});

afterEach(() => {
afterAll(() => {
filter_2 = null;
});

Expand Down
98 changes: 98 additions & 0 deletions test/scalable.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*******************************************
* copyright: @github.com/Blumea
* authors: @akashchouhan16
* *****************************************
*/

const ScalableBloomFilter = require('../build/scalableBloom/main');

describe('Scalable bloom filter tests', () => {
let filter;

beforeAll(() => {
filter = new ScalableBloomFilter(1000, 0.01);
});

afterAll(() => {
filter = null;
});

describe('Scalable bloom instance with valid inputs', () => {
test('Scalable bloom filter instance as not null', () => {
expect(filter).not.toBe(null);
});

test('Scalable bloom instance with valid item_count', () => {
expect(filter.expectedItems).toEqual(1000);
});

test('Scalable bloom instance with valid falsePositiveRate', () => {
expect(filter.falsePositiveRate).toEqual(0.01);
});

test('Scalable bloom instance logger as disabled by default', () => {
expect(filter.logger).toEqual(false);
});

test('Scalable bloom instance scaled by a factor of 2', () => {
const SIZE = filter.filterSize;
filter.scaleFilter();
expect(filter.filterSize).toEqual(SIZE * 2);
});

test('inserting and finding an item in Scalable bloom filter', () => {
filter.insert('foo');
expect(filter.find('foo')).toBe(true);
});

test('inserting and finding a numeric item in Scalable bloom filter (+ case)', () => {
filter.insert(12345);
expect(filter.find(12345)).toBe(true);
})

test('inserting and finding a numeric item in Scalable bloom filter (- case)', () => {
filter.insert(123);
expect(filter.find(1234)).toBe(false);
})
});

describe('Scalable bloom instance with no inputs', () => {
let filter_2;

beforeAll(() => {
filter_2 = new ScalableBloomFilter();
});

afterAll(() => {
filter_2 = null;
});

test('Scalable bloom filter instance as not null, using default values', () => {
expect(filter_2).not.toBe(null);
});

test('Scalable bloom instance with null item_count', () => {
expect(filter_2.expectedItems).toEqual(1000);
});

test('Scalable bloom instance with null falsePositiveRate', () => {
expect(filter_2.falsePositiveRate).toEqual(0.01);
});

// test('Scalable bloom invalid not-null falsePositiveRate', () => {
// expect(() => {
// new ScalableBloomFilter(-1, 0.005);
// }).toThrow(Error);
// });

test('Scalable bloom with very large item_count and fp rate', () => {
const filter_3 = new ScalableBloomFilter(7_000_001, 0.999);
expect(filter_3).not.toBe(null);
});

test('inserting and finding an item in invalid Scalable bloom filter', () => {
filter_2.insert('foo');
expect(filter_2.find('foo')).toBe(true);
});
});
});

0 comments on commit 9f4e010

Please sign in to comment.