init: company-haness 설계

This commit is contained in:
DongHyeonka
2026-07-23 17:49:00 +09:00
parent 57d1bab894
commit f668d6a158
962 changed files with 98989 additions and 1 deletions
+13
View File
@@ -0,0 +1,13 @@
"""Pagination helper — contains an off-by-one bug that drops the last item of a page.
The bug: `end = start + size - 1` and slicing `items[start:end]` excludes the last
element of each page. A correct implementation returns exactly `size` items per page
(and the remainder on the final page).
"""
def paginate(items, page, size):
"""Return the `page`-th (1-indexed) slice of `items` with `size` per page."""
start = (page - 1) * size
end = start + size - 1 # BUG: off-by-one — drops the last item of the page
return items[start:end]
+22
View File
@@ -0,0 +1,22 @@
"""Objective acceptance test for GT-01 (held as the verify command).
This test currently FAILS against the buggy paginate() (off-by-one drops the last
item). A correct fix makes it pass. The benchmark runner runs `pytest -q` after each
arm and grades first-pass-acceptance on the exit code.
"""
from paginate import paginate
def test_full_page_returns_size_items():
items = list(range(10))
assert paginate(items, 1, 5) == [0, 1, 2, 3, 4]
assert paginate(items, 2, 5) == [5, 6, 7, 8, 9]
def test_last_item_not_dropped():
assert paginate([1, 2, 3], 1, 3) == [1, 2, 3]
def test_partial_last_page():
assert paginate([1, 2, 3, 4, 5], 1, 2) == [1, 2]
assert paginate([1, 2, 3, 4, 5], 3, 2) == [5]
+16
View File
@@ -0,0 +1,16 @@
"""Running statistics — contains a bug in `median` for even-length inputs.
The bug: for an even number of elements, `median` returns the lower-middle element
instead of the average of the two middle elements. `mean` is correct.
"""
def mean(xs):
return sum(xs) / len(xs)
def median(xs):
s = sorted(xs)
n = len(s)
mid = n // 2
return s[mid] # BUG: even-length should average s[mid-1] and s[mid]
+14
View File
@@ -0,0 +1,14 @@
from stats import mean, median
def test_mean():
assert mean([2, 4, 6]) == 4
def test_median_odd():
assert median([3, 1, 2]) == 2
def test_median_even():
assert median([1, 2, 3, 4]) == 2.5 # average of the two middle elements
assert median([10, 20]) == 15