Skip to content

0622-1114405001-楊能安 - #1320

Open
hosiyaluna wants to merge 4 commits into
DevSecOpsLab-CSIE-NPU:mainfrom
hosiyaluna:feature-week18-1114405001
Open

hosiyaluna wants to merge 4 commits into
DevSecOpsLab-CSIE-NPU:mainfrom
hosiyaluna:feature-week18-1114405001

Conversation

@hosiyaluna

Copy link
Copy Markdown

This pull request implements and documents a comprehensive solution for comparing binary search and linear search, including code, test cases, and detailed documentation. The main focus is on correctness, performance measurement, and thorough edge case handling. The most important changes are summarized below:


Implementation of Search Algorithms:

  • Added linear_search and binary_search functions in search.py, both returning a unified SearchResult dataclass that tracks whether the target was found, its index, and the number of comparisons performed.

  • Added a format_output function to standardize result output for both search algorithms.


Testing and Validation:

  • Added test_search.py with 12 pytest-based unit tests, covering small and large arrays, performance comparisons, and a variety of edge cases (target at start/end, single-element arrays, target not present, etc.), ensuring both correctness and performance differences between the algorithms.

Documentation and Design Rationale:

  • Added TASK_SUMMARY.md documenting the three main testing tasks, test results, file structure, and next steps for PR submission.

  • Added AI_LOG.md detailing design decisions, function signatures, exception handling, edge cases, TDD process, and acceptance criteria for the solution.


These changes together provide a robust, well-tested, and well-documented solution for comparing binary search and linear search, following best practices in software engineering.

- Task 1: Small array with target found (middle position)
- Task 2: Large array with target found (performance comparison)
- Task 3: Edge case - target not found

Total 12 test cases covering:
- Basic correctness (linear vs binary)
- Performance comparison (O(n) vs O(log n))
- Edge cases (not found, boundary conditions)
- Implemented linear_search: O(n) time complexity
- Implemented binary_search: O(log n) time complexity
- Added SearchResult dataclass for structured output
- Added format_output helper for display
- All 12 tests passing

Performance metrics:
- Binary search ~7x faster on 10,000 elements
- Correct handling of edge cases (not found, boundaries)
- 開工前必答 5 個問題詳細說明
- 12 個 test case 的設計流程
- 重點設計決策(為什麼分 3 個 Task)
- AI 協作原則和自我檢查清單
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.

1 participant