mirror of
https://github.com/harivansh-afk/veet-code.git
synced 2026-04-15 16:04:06 +00:00
update testing frame and ui
This commit is contained in:
parent
fcb740f0c2
commit
205957c167
8 changed files with 173 additions and 101 deletions
|
|
@ -6,39 +6,31 @@ from solution import is_palindrome
|
|||
class TestBasicCases:
|
||||
"""Test basic functionality with typical inputs."""
|
||||
|
||||
def test_example_one(self):
|
||||
"""Test first example from problem description."""
|
||||
assert is_palindrome("A man, a plan, a canal: Panama") == True
|
||||
|
||||
def test_example_two(self):
|
||||
"""Test second example from problem description."""
|
||||
assert is_palindrome("race a car") == False
|
||||
|
||||
def test_simple_palindrome(self):
|
||||
"""Test basic palindrome word."""
|
||||
assert is_palindrome("racecar") == True
|
||||
|
||||
def test_sentence_palindrome(self):
|
||||
"""Test palindrome with spaces and punctuation."""
|
||||
assert is_palindrome("A man, a plan, a canal: Panama") == True
|
||||
|
||||
def test_not_palindrome(self):
|
||||
"""Test non-palindrome string."""
|
||||
assert is_palindrome("hello") == False
|
||||
|
||||
|
||||
class TestEdgeCases:
|
||||
"""Test edge cases and boundary conditions."""
|
||||
|
||||
def test_empty_string(self):
|
||||
"""Test with empty input."""
|
||||
def test_empty_input(self):
|
||||
"""Test with empty or minimal input."""
|
||||
assert is_palindrome("") == True
|
||||
|
||||
def test_single_character(self):
|
||||
"""Test with single character."""
|
||||
def test_single_element(self):
|
||||
"""Test with single element input."""
|
||||
assert is_palindrome("a") == True
|
||||
|
||||
def test_only_spaces(self):
|
||||
"""Test with only whitespace."""
|
||||
assert is_palindrome(" ") == True
|
||||
|
||||
def test_mixed_case(self):
|
||||
"""Test case insensitivity."""
|
||||
assert is_palindrome("RaceCar") == True
|
||||
|
||||
def test_numbers_in_string(self):
|
||||
"""Test with numbers."""
|
||||
assert is_palindrome("12321") == True
|
||||
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
|
|
@ -43,8 +43,7 @@ class TestEdgeCases:
|
|||
{"amount": 10, "category": "Food", "date": "2024-01-01"},
|
||||
{"amount": 20, "category": "food", "date": "2024-01-02"}
|
||||
]
|
||||
result = group_transactions(txns)
|
||||
assert result == {"Food": 10, "food": 20}
|
||||
assert group_transactions(txns) == {"Food": 10, "food": 20}
|
||||
|
||||
def test_many_categories(self):
|
||||
"""Test with many different categories."""
|
||||
|
|
|
|||
|
|
@ -6,47 +6,39 @@ from solution import top_words
|
|||
class TestBasicCases:
|
||||
"""Test basic functionality with typical inputs."""
|
||||
|
||||
def test_basic_frequency(self):
|
||||
"""Test basic word counting."""
|
||||
result = top_words("the quick brown fox jumps over the lazy dog the fox", 2)
|
||||
assert result == [("the", 3), ("fox", 2)]
|
||||
def test_example_one(self):
|
||||
"""Test first example from problem description."""
|
||||
assert top_words("the quick brown fox jumps over the lazy dog the fox", 2) == [("the", 3), ("fox", 2)]
|
||||
|
||||
def test_all_unique(self):
|
||||
"""Test when all words are unique."""
|
||||
result = top_words("one two three", 2)
|
||||
assert result == [("one", 1), ("three", 1)] or result == [("one", 1), ("two", 1)]
|
||||
def test_example_two(self):
|
||||
"""Test second example from problem description."""
|
||||
assert top_words("hello world hello", 5) == [("hello", 2), ("world", 1)]
|
||||
|
||||
def test_single_word_repeated(self):
|
||||
"""Test with one word repeated."""
|
||||
result = top_words("hello hello hello", 1)
|
||||
assert result == [("hello", 3)]
|
||||
assert top_words("hello hello hello", 1) == [("hello", 3)]
|
||||
|
||||
|
||||
class TestEdgeCases:
|
||||
"""Test edge cases and boundary conditions."""
|
||||
|
||||
def test_empty_string(self):
|
||||
"""Test with empty input."""
|
||||
result = top_words("", 5)
|
||||
assert result == []
|
||||
def test_empty_input(self):
|
||||
"""Test with empty or minimal input."""
|
||||
assert top_words("", 5) == []
|
||||
|
||||
def test_n_greater_than_unique_words(self):
|
||||
"""Test when n exceeds unique word count."""
|
||||
result = top_words("hello world", 10)
|
||||
assert len(result) == 2
|
||||
assert len(top_words("hello world", 10)) == 2
|
||||
|
||||
def test_case_insensitive(self):
|
||||
"""Test that counting is case-insensitive."""
|
||||
result = top_words("Hello HELLO hello", 1)
|
||||
assert result == [("hello", 3)]
|
||||
assert top_words("Hello HELLO hello", 1) == [("hello", 3)]
|
||||
|
||||
def test_punctuation_ignored(self):
|
||||
"""Test that punctuation is stripped."""
|
||||
result = top_words("hello, world! hello.", 1)
|
||||
assert result == [("hello", 2)]
|
||||
assert top_words("hello, world! hello.", 1) == [("hello", 2)]
|
||||
|
||||
def test_alphabetical_tiebreaker(self):
|
||||
"""Test alphabetical ordering for same frequency."""
|
||||
result = top_words("cat bat ant", 3)
|
||||
assert result == [("ant", 1), ("bat", 1), ("cat", 1)]
|
||||
assert top_words("cat bat ant", 3) == [("ant", 1), ("bat", 1), ("cat", 1)]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue