From e93b1ccb68079103120d9125c48a50b249ca9e79 Mon Sep 17 00:00:00 2001 From: robonen Date: Fri, 29 Nov 2024 05:42:50 +0700 Subject: [PATCH] refactor(packages/stdlib): add test case for BitVector --- packages/stdlib/src/bits/vector/index.test.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/stdlib/src/bits/vector/index.test.ts b/packages/stdlib/src/bits/vector/index.test.ts index 7940e71..2aca9b3 100644 --- a/packages/stdlib/src/bits/vector/index.test.ts +++ b/packages/stdlib/src/bits/vector/index.test.ts @@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest'; import { BitVector } from '.'; describe('BitVector', () => { - it('should initialize with the correct size', () => { + it('initialize with the correct size', () => { const size = 16; const expectedSize = Math.ceil(size / 8); const bitVector = new BitVector(size); @@ -10,7 +10,7 @@ describe('BitVector', () => { expect(bitVector.length).toBe(expectedSize); }); - it('should set and get bits correctly', () => { + it('set and get bits correctly', () => { const bitVector = new BitVector(16); bitVector.setBit(5); @@ -18,7 +18,13 @@ describe('BitVector', () => { expect(bitVector.getBit(4)).toBe(false); }); - it('should clear bits correctly', () => { + it('get out of bounds bits correctly', () => { + const bitVector = new BitVector(16); + + expect(bitVector.getBit(155)).toBe(false); + }); + + it('clear bits correctly', () => { const bitVector = new BitVector(16); bitVector.setBit(5); @@ -29,7 +35,7 @@ describe('BitVector', () => { expect(bitVector.getBit(5)).toBe(false); }); - it('should find the previous bit correctly', () => { + it('find the previous bit correctly', () => { const bitVector = new BitVector(100); const indices = [99, 88, 66, 65, 64, 63, 15, 14, 1, 0]; const result = []; @@ -42,13 +48,13 @@ describe('BitVector', () => { expect(result).toEqual(indices); }); - it('should return -1 when no previous bit is found', () => { + it('return -1 when no previous bit is found', () => { const bitVector = new BitVector(16); expect(bitVector.previousBit(0)).toBe(-1); }); - it('should throw RangeError when previousBit is called with an unreachable value', () => { + it('throw RangeError when previousBit is called with an unreachable value', () => { const bitVector = new BitVector(16); bitVector.setBit(5);