clanker: test-veet (run)

This commit is contained in:
kubasync-clanker 2026-02-10 19:50:13 +00:00
parent c4d74aca3e
commit 684a9c5e3a
6 changed files with 253 additions and 0 deletions

View file

@ -0,0 +1,38 @@
"""
Group Anagrams
You're building a word game assistant that groups words which are
anagrams of each other. Two words are anagrams if they contain
the same letters in any order.
Given a list of strings, group the anagrams together. Each group
should be a sorted list of words, and the groups themselves should
be sorted by their first element.
Example 1:
Input: words = ["eat", "tea", "tan", "ate", "nat", "bat"]
Output: [["ate", "eat", "tea"], ["bat"], ["nat", "tan"]]
Explanation: "eat", "tea", and "ate" are all anagrams of each other
Example 2:
Input: words = ["hello", "world"]
Output: [["hello"], ["world"]]
Explanation: No words are anagrams of each other
Example 3:
Input: words = ["", ""]
Output: [["", ""]]
Explanation: Empty strings are anagrams of each other
Constraints:
- 0 <= len(words) <= 10^4
- 0 <= len(words[i]) <= 100
- Words consist of lowercase English letters
- Each group is sorted alphabetically
- Groups are sorted by their first element
"""
def group_anagrams(words: list[str]) -> list[list[str]]:
"""Return a list of anagram groups, each sorted, groups sorted by first element."""
pass # Your implementation here

View file

@ -0,0 +1,45 @@
"""Tests for group-anagrams."""
import pytest
from solution import group_anagrams
class TestBasicCases:
"""Test basic functionality with typical inputs."""
def test_example_one(self):
"""Test first example from problem description."""
assert group_anagrams(["eat", "tea", "tan", "ate", "nat", "bat"]) == [
["ate", "eat", "tea"], ["bat"], ["nat", "tan"]
]
def test_example_two(self):
"""Test second example with no anagrams."""
assert group_anagrams(["hello", "world"]) == [["hello"], ["world"]]
def test_example_three(self):
"""Test third example with empty strings."""
assert group_anagrams(["", ""]) == [["", ""]]
def test_single_word(self):
"""Test with a single word."""
assert group_anagrams(["abc"]) == [["abc"]]
class TestEdgeCases:
"""Test edge cases and boundary conditions."""
def test_empty_list(self):
"""Test with no words."""
assert group_anagrams([]) == []
def test_all_same_word(self):
"""Test with identical words."""
assert group_anagrams(["abc", "abc", "abc"]) == [["abc", "abc", "abc"]]
def test_single_character_words(self):
"""Test with single character strings."""
assert group_anagrams(["a", "b", "a"]) == [["a", "a"], ["b"]]
def test_different_lengths_not_grouped(self):
"""Test that words of different lengths are never grouped."""
assert group_anagrams(["ab", "abc", "ba"]) == [["ab", "ba"], ["abc"]]