Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .amazonq/rules/development-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@
- Test all: `make test`
- Beautiful logging with loguru

### Multiple Solution Classes Pattern

When implementing multiple approaches (e.g., Solution, SolutionMath), use parametrized testing:

```python
@pytest.mark.parametrize("solution_class", [Solution, SolutionMath])
@pytest.mark.parametrize("input_params, expected", test_cases)
def test_method(self, solution_class, input_params, expected):
result = run_helper(solution_class, *input_params)
assert_helper(result, expected)
```

This pattern tests all solution approaches with the same test cases, ensuring consistency across implementations.

## File Structure

Each problem has:
Expand Down
16 changes: 15 additions & 1 deletion .amazonq/rules/test-case-enhancement.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Simple Enhancement Workflow

When user requests test case enhancement:
When user requests test case enhancement or **test reproducibility verification**:

### 1. Problem Resolution

Expand Down Expand Up @@ -69,10 +69,24 @@ make p-gen PROBLEM={problem_name} FORCE=1
make p-lint PROBLEM={problem_name}
```

## Test Reproducibility Verification

Use this same workflow when CI tests fail due to reproducibility issues:

**Process Name**: Test Reproducibility Verification

**When to Use**:

- CI test failures in reproducibility checks
- Inconsistent test results between environments
- Missing edge cases causing coverage gaps
- Need to ensure 100% code coverage

## Success Criteria

- All tests pass with enhanced test cases
- Minimum 12 comprehensive test cases per problem
- Original solution code preserved
- **Enhanced test cases in final test_solution.py**
- JSON template updated for future regeneration
- **100% code coverage including edge cases**
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
- repo: local
hooks:
- id: sync-submodules
name: Sync git submodules
name: sync git submodules
entry: bash -c 'output=$(git submodule update --init --recursive --remote 2>&1); [ -z "$output" ]'
language: system
always_run: true
Expand Down
71 changes: 42 additions & 29 deletions .templates/leetcode/json/accounts_merge.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,60 @@
"problem_title": "Accounts Merge",
"difficulty": "Medium",
"topics": "Array, Hash Table, String, Depth-First Search, Breadth-First Search, Union Find, Sorting",
"tags": ["grind-75"],
"readme_description": "Given a list of `accounts` where each element `accounts[i]` is a list of strings, where the first element `accounts[i][0]` is a name, and the rest of the elements are **emails** representing emails of the account.\n\nNow, we would like to merge these accounts. Two accounts definitely belong to the same person if there is some common email to both accounts. Note that even if two accounts have the same name, they may belong to different people as people could have the same name. A person can have any number of accounts initially, but all of their accounts definitely have the same name.\n\nAfter merging the accounts, return the accounts in the following format: the first element of each account is the name, and the rest of the elements are emails **in sorted order**. The accounts themselves can be returned in **any order**.",
"readme_examples": [
{
"content": "```\nInput: accounts = [[\"John\",\"[email protected]\",\"[email protected]\"],[\"John\",\"[email protected]\",\"[email protected]\"],[\"Mary\",\"[email protected]\"],[\"John\",\"[email protected]\"]]\nOutput: [[\"John\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Mary\",\"[email protected]\"],[\"John\",\"[email protected]\"]]\n```\n**Explanation:** The first and second John's are the same person as they have the common email \"[email protected]\". The third John and Mary are different people as none of their email addresses are used by other accounts."
},
{
"content": "```\nInput: accounts = [[\"Gabe\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Kevin\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Ethan\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Hanzo\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Fern\",\"[email protected]\",\"[email protected]\",\"[email protected]\"]]\nOutput: [[\"Ethan\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Gabe\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Hanzo\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Kevin\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Fern\",\"[email protected]\",\"[email protected]\",\"[email protected]\"]]\n```"
}
],
"readme_constraints": "- `1 <= accounts.length <= 1000`\n- `2 <= accounts[i].length <= 10`\n- `1 <= accounts[i][j].length <= 30`\n- `accounts[i][0]` consists of English letters.\n- `accounts[i][j] (for j > 0)` is a valid email.",
"_tags": { "list": ["grind-75"] },
"readme_description": "Given a list of `accounts` where each element `accounts[i]` is a list of strings, where the first element `accounts[i][0]` is a name, and the rest of the elements are emails representing emails of the account.\n\nNow, we would like to merge these accounts. Two accounts definitely belong to the same person if there is some common email to both accounts. Note that even if two accounts have the same name, they may belong to different people as people could have the same name. A person can have any number of accounts initially, but all of their accounts definitely have the same name.\n\nAfter merging the accounts, return the accounts in the following format: the first element of each account is the name, and the rest of the elements are emails in sorted order. The accounts themselves can be returned in any order.",
"_readme_examples": {
"list": [
{
"content": "```\nInput: accounts = [[\"John\",\"[email protected]\",\"[email protected]\"],[\"John\",\"[email protected]\",\"[email protected]\"],[\"Mary\",\"[email protected]\"],[\"John\",\"[email protected]\"]]\nOutput: [[\"John\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Mary\",\"[email protected]\"],[\"John\",\"[email protected]\"]]\n```\n**Explanation:** The first and second John's are the same person as they have the common email \"[email protected]\". The third John and Mary are different people as none of their email addresses are used by other accounts."
},
{
"content": "```\nInput: accounts = [[\"Gabe\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Kevin\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Ethan\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Hanzo\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Fern\",\"[email protected]\",\"[email protected]\",\"[email protected]\"]]\nOutput: [[\"Ethan\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Gabe\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Hanzo\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Kevin\",\"[email protected]\",\"[email protected]\",\"[email protected]\"],[\"Fern\",\"[email protected]\",\"[email protected]\",\"[email protected]\"]]\n```"
}
]
},
"readme_constraints": "- 1 <= accounts.length <= 1000\n- 2 <= accounts[i].length <= 10\n- 1 <= accounts[i][j].length <= 30\n- accounts[i][0] consists of English letters.\n- accounts[i][j] (for j > 0) is a valid email.",
"readme_additional": "",
"helpers_imports": "",
"helpers_content": "",
"helpers_run_name": "accounts_merge",
"helpers_run_signature": "(solution_class: type, accounts: list[list[str]])",
"helpers_run_body": " implementation = solution_class()\n return implementation.accounts_merge(accounts)",
"helpers_assert_name": "accounts_merge",
"helpers_assert_signature": "(result: list[list[str]], expected: list[list[str]]) -> bool",
"helpers_assert_body": " # Sort both result and expected for comparison since order doesn't matter\n result_sorted = [sorted(account) for account in sorted(result)]\n expected_sorted = [sorted(account) for account in sorted(expected)]\n assert result_sorted == expected_sorted\n return True",
"solution_methods": [
{
"name": "accounts_merge",
"signature": "(self, accounts: list[list[str]]) -> list[list[str]]",
"body": " # TODO: Implement accounts_merge\n return []"
}
],
"solution_imports": "",
"solution_contents": "",
"solution_class_content": "",
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .helpers import assert_accounts_merge, run_accounts_merge\nfrom .solution import Solution",
"test_content": "",
"test_class_name": "AccountsMerge",
"test_class_content": " def setup_method(self):\n self.solution = Solution()",
"test_helper_methods": [],
"test_methods": [
{
"name": "test_accounts_merge",
"signature": "(self, accounts: list[list[str]], expected: list[list[str]])",
"parametrize": "accounts, expected",
"test_cases": "[([[\"John\", \"[email protected]\", \"[email protected]\"], [\"John\", \"[email protected]\", \"[email protected]\"], [\"Mary\", \"[email protected]\"], [\"John\", \"[email protected]\"]], [[\"John\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Mary\", \"[email protected]\"], [\"John\", \"[email protected]\"]]), ([[\"Gabe\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Kevin\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Ethan\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Hanzo\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Fern\", \"[email protected]\", \"[email protected]\", \"[email protected]\"]], [[\"Ethan\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Gabe\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Hanzo\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Kevin\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Fern\", \"[email protected]\", \"[email protected]\", \"[email protected]\"]]), ([[\"John\", \"[email protected]\"]], [[\"John\", \"[email protected]\"]]), ([[\"John\", \"[email protected]\"], [\"John\", \"[email protected]\"], [\"John\", \"[email protected]\"]], [[\"John\", \"[email protected]\"], [\"John\", \"[email protected]\"], [\"John\", \"[email protected]\"]]), ([[\"John\", \"[email protected]\", \"[email protected]\"], [\"John\", \"[email protected]\", \"[email protected]\"], [\"John\", \"[email protected]\"]], [[\"John\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"John\", \"[email protected]\"]]), ([[\"Alice\", \"[email protected]\", \"[email protected]\"], [\"Alice\", \"[email protected]\", \"[email protected]\"], [\"Alice\", \"[email protected]\", \"[email protected]\"]], [[\"Alice\", \"[email protected]\", \"[email protected]\", \"[email protected]\", \"[email protected]\"]]), ([[\"Bob\", \"[email protected]\"], [\"Bob\", \"[email protected]\"]], [[\"Bob\", \"[email protected]\"]]), ([[\"David\", \"[email protected]\", \"[email protected]\"], [\"David\", \"[email protected]\"], [\"David\", \"[email protected]\", \"[email protected]\"]], [[\"David\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"David\", \"[email protected]\"]]), ([[\"Alex\", \"[email protected]\"], [\"Alex\", \"[email protected]\", \"[email protected]\"], [\"Alex\", \"[email protected]\"]], [[\"Alex\", \"[email protected]\", \"[email protected]\"], [\"Alex\", \"[email protected]\"]]), ([[\"Tom\", \"[email protected]\"], [\"Tom\", \"[email protected]\"], [\"Tom\", \"[email protected]\"], [\"Tom\", \"[email protected]\"]], [[\"Tom\", \"[email protected]\"], [\"Tom\", \"[email protected]\"], [\"Tom\", \"[email protected]\"], [\"Tom\", \"[email protected]\"]]), ([[\"Sam\", \"[email protected]\", \"[email protected]\", \"[email protected]\"]], [[\"Sam\", \"[email protected]\", \"[email protected]\", \"[email protected]\"]])]",
"body": " result = run_accounts_merge(Solution, accounts)\n assert_accounts_merge(result, expected)"
}
],
"_solution_methods": {
"list": [
{
"name": "accounts_merge",
"signature": "(self, accounts: list[list[str]]) -> list[list[str]]",
"body": " # TODO: Implement accounts_merge\n return []"
}
]
},
"_test_helper_methods": {
"list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }]
},
"_test_methods": {
"list": [
{
"name": "test_accounts_merge",
"signature": "(self, accounts: list[list[str]], expected: list[list[str]])",
"parametrize": "accounts, expected",
"test_cases": "[([['John', '[email protected]', '[email protected]'], ['John', '[email protected]', '[email protected]'], ['Mary', '[email protected]'], ['John', '[email protected]']], [['John', '[email protected]', '[email protected]', '[email protected]'], ['Mary', '[email protected]'], ['John', '[email protected]']]), ([['Gabe', '[email protected]', '[email protected]', '[email protected]'], ['Kevin', '[email protected]', '[email protected]', '[email protected]'], ['Ethan', '[email protected]', '[email protected]', '[email protected]'], ['Hanzo', '[email protected]', '[email protected]', '[email protected]'], ['Fern', '[email protected]', '[email protected]', '[email protected]']], [['Ethan', '[email protected]', '[email protected]', '[email protected]'], ['Gabe', '[email protected]', '[email protected]', '[email protected]'], ['Hanzo', '[email protected]', '[email protected]', '[email protected]'], ['Kevin', '[email protected]', '[email protected]', '[email protected]'], ['Fern', '[email protected]', '[email protected]', '[email protected]']]), ([['Alice', '[email protected]']], [['Alice', '[email protected]']]), ([['Bob', '[email protected]'], ['Bob', '[email protected]']], [['Bob', '[email protected]'], ['Bob', '[email protected]']]), ([['Alice', '[email protected]', '[email protected]'], ['Alice', '[email protected]', '[email protected]']], [['Alice', '[email protected]', '[email protected]', '[email protected]']]), ([['A', '[email protected]', '[email protected]'], ['B', '[email protected]', '[email protected]'], ['C', '[email protected]', '[email protected]']], [['A', '[email protected]', '[email protected]', '[email protected]', '[email protected]']]), ([['David', '[email protected]'], ['David', '[email protected]']], [['David', '[email protected]']]), ([['Alex', '[email protected]'], ['Bob', '[email protected]'], ['Charlie', '[email protected]']], [['Alex', '[email protected]'], ['Bob', '[email protected]'], ['Charlie', '[email protected]']]), ([['John', '[email protected]', '[email protected]'], ['John', '[email protected]'], ['Jane', '[email protected]']], [['John', '[email protected]', '[email protected]'], ['John', '[email protected]'], ['Jane', '[email protected]']]), ([['User', '[email protected]', '[email protected]'], ['User', '[email protected]', '[email protected]'], ['User', '[email protected]', '[email protected]']], [['User', '[email protected]', '[email protected]', '[email protected]', '[email protected]']]), ([['Test', '[email protected]'], ['Test', '[email protected]'], ['Test', '[email protected]', '[email protected]']], [['Test', '[email protected]'], ['Test', '[email protected]', '[email protected]']]), ([['Name', '[email protected]', '[email protected]', '[email protected]'], ['Name', '[email protected]', '[email protected]'], ['Name', '[email protected]', '[email protected]']], [['Name', '[email protected]', '[email protected]'], ['Name', '[email protected]', '[email protected]', '[email protected]', '[email protected]']])]",
"body": " result = run_accounts_merge(Solution, accounts)\n assert_accounts_merge(result, expected)"
}
]
},
"playground_imports": "from helpers import run_accounts_merge, assert_accounts_merge\nfrom solution import Solution",
"playground_setup": "# Example test case\naccounts = [[\"John\", \"[email protected]\", \"[email protected]\"], [\"John\", \"[email protected]\", \"[email protected]\"], [\"Mary\", \"[email protected]\"], [\"John\", \"[email protected]\"]]\nexpected = [[\"John\", \"[email protected]\", \"[email protected]\", \"[email protected]\"], [\"Mary\", \"[email protected]\"], [\"John\", \"[email protected]\"]]",
"playground_setup": "# Example test case\naccounts = [['John', '[email protected]', '[email protected]'], ['John', '[email protected]', '[email protected]'], ['Mary', '[email protected]'], ['John', '[email protected]']]\nexpected = [['John', '[email protected]', '[email protected]', '[email protected]'], ['Mary', '[email protected]'], ['John', '[email protected]']]",
"playground_run": "result = run_accounts_merge(Solution, accounts)\nresult",
"playground_assert": "assert_accounts_merge(result, expected)"
}
Loading