Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unit tests for lrucache #11

Closed
wants to merge 0 commits into from
Closed

Conversation

suja1956
Copy link

This PR contains unit tests for lrucache.go file.
Below are the unit tests that I have added:

  1. TestOverwriteValue: Tests that if a value is set for an existing key, the value is properly overwritten.
  2. TestEviction: Verifies that when the cache exceeds its capacity, the least recently used item is evicted. This test uses a cache of size 2 to simulate the eviction.
  3. TestMoveToFront: Ensures that when an item is accessed, it becomes the most recently used item. The least recently used item should be evicted after inserting a new one.
  4. TestLRUBehavior: Tests more advanced LRU behavior by accessing different items and confirming that the least recently accessed item is the one that gets evicted when the cache is full.

Fixes: #10

@yp969803
Copy link
Collaborator

@suja1956 run 'make format' before commiting, also the tests are failing

@yp969803 yp969803 self-requested a review September 24, 2024 22:25
@yp969803
Copy link
Collaborator

also you can remove

func TestGetSet(t *testing.T) {


val = cache.Get("key1")
if val != nil {
t.Errorf("Expected nil (key1 evicted), got %s", val)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test failing here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will try to resolve.

@yp969803
Copy link
Collaborator

@suja1956 can you pull the current main branch, i have done some changes in lrucache functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write unit tests for pkg/cache/lrucache.go
2 participants