update testing frame and ui

This commit is contained in:
Harivansh Rathi 2025-12-14 17:55:28 -05:00
parent fcb740f0c2
commit 205957c167
8 changed files with 173 additions and 101 deletions

View file

@ -6,6 +6,24 @@ from solution import LRUCache
class TestBasicCases:
"""Test basic functionality with typical inputs."""
def test_example_one(self):
"""Test first example from problem description."""
cache = LRUCache(2)
cache.put("a", 1)
cache.put("b", 2)
assert cache.get("a") == 1
cache.put("c", 3)
assert cache.get("b") == -1
assert cache.get("c") == 3
def test_example_two(self):
"""Test second example from problem description."""
cache = LRUCache(1)
cache.put("x", 10)
cache.put("y", 20)
assert cache.get("x") == -1
assert cache.get("y") == 20
def test_basic_put_get(self):
"""Test basic put and get operations."""
cache = LRUCache(2)
@ -14,24 +32,6 @@ class TestBasicCases:
assert cache.get("a") == 1
assert cache.get("b") == 2
def test_eviction_lru(self):
"""Test that least recently used is evicted."""
cache = LRUCache(2)
cache.put("a", 1)
cache.put("b", 2)
cache.get("a") # a is now most recent
cache.put("c", 3) # b should be evicted
assert cache.get("b") == -1
assert cache.get("a") == 1
assert cache.get("c") == 3
def test_update_existing_key(self):
"""Test updating an existing key."""
cache = LRUCache(2)
cache.put("a", 1)
cache.put("a", 10)
assert cache.get("a") == 10
class TestEdgeCases:
"""Test edge cases and boundary conditions."""

View file

@ -6,19 +6,22 @@ from solution import RateLimiter
class TestBasicCases:
"""Test basic functionality with typical inputs."""
def test_allow_within_limit(self):
"""Test requests within the limit are allowed."""
def test_example_one(self):
"""Test first example from problem description."""
limiter = RateLimiter(max_requests=3, window_seconds=60)
assert limiter.allow_request("user1", 0) == True
assert limiter.allow_request("user1", 30) == True
assert limiter.allow_request("user1", 45) == True
assert limiter.allow_request("user1", 50) == False
assert limiter.allow_request("user1", 61) == True
def test_block_over_limit(self):
"""Test requests over limit are blocked."""
limiter = RateLimiter(max_requests=2, window_seconds=60)
def test_example_two(self):
"""Test second example from problem description."""
limiter = RateLimiter(max_requests=2, window_seconds=10)
assert limiter.allow_request("user1", 0) == True
assert limiter.allow_request("user1", 30) == True
assert limiter.allow_request("user1", 45) == False
assert limiter.allow_request("user2", 0) == True
assert limiter.allow_request("user1", 5) == True
assert limiter.allow_request("user1", 8) == False
def test_multiple_users_independent(self):
"""Test each user has independent limits."""