Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Tee-py committed Feb 21, 2025
1 parent 0dcf16d commit 4b30080
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions tests/core/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,86 +117,86 @@ describe('Transaction Parser Utils', () => {

describe('LRUCache Tests', () => {
let cache: LRUCache<number>;

beforeEach(() => {
cache = new LRUCache<number>(3);
});

test('should initialize with correct capacity', () => {
expect(cache.size).toBe(0);
const cache2 = new LRUCache<number>(5);
expect(cache2.size).toBe(0);
});

test('should set and get values correctly', () => {
cache.set('a', 1);
expect(cache.get('a')).toBe(1);
expect(cache.size).toBe(1);
});

test('should return null for non-existent keys', () => {
expect(cache.get('missing')).toBeNull();
});

test('should update existing keys', () => {
cache.set('a', 1);
cache.set('a', 2);
expect(cache.get('a')).toBe(2);
expect(cache.size).toBe(1);
});

test('should evict least recently used item when capacity is reached', () => {
cache.set('a', 1);
cache.set('b', 2);
cache.set('c', 3);
cache.set('d', 4);

expect(cache.get('a')).toBeNull();
expect(cache.get('b')).toBe(2);
expect(cache.get('c')).toBe(3);
expect(cache.get('d')).toBe(4);
expect(cache.size).toBe(3);
});

test('should maintain LRU order with gets', () => {
cache.set('a', 1);
cache.set('b', 2);
cache.set('c', 3);

cache.get('a');

cache.set('d', 4);

expect(cache.get('b')).toBeNull();
expect(cache.get('a')).toBe(1);
expect(cache.get('c')).toBe(3);
expect(cache.get('d')).toBe(4);
});

test('should clear the cache', () => {
cache.set('a', 1);
cache.set('b', 2);
cache.clear();

expect(cache.size).toBe(0);
expect(cache.get('a')).toBeNull();
expect(cache.get('b')).toBeNull();
});

// test('should handle complex sequence of operations', () => {
// cache.set('a', 1);
// cache.set('b', 2);
// cache.get('a');
// cache.get('a');
// cache.set('c', 3);
// cache.set('d', 4);

// expect(cache.get('b')).toBeNull();
// expect(cache.get('a')).toBe(1);
// expect(cache.get('c')).toBe(3);
// expect(cache.get('d')).toBe(4);

// cache.set('e', 5);

// expect(cache.get('c')).toBeNull();
// expect(cache.get('a')).toBe(1);
// expect(cache.get('d')).toBe(4);
Expand Down

0 comments on commit 4b30080

Please sign in to comment.