feat: implement core auction logic and env loader

- Add auction.py with add_bid and find_winner functions
- Add env.py with stdlib-based .env loader (no python-dotenv)
- Add tests/test_auction.py with test cases for auction functions
- Remove .env.example (tokens not meant to be committed)
- Update docs/plan.md to mark Milestone 2 as complete
This commit is contained in:
2026-10-04 14:03:22 +08:00
parent bcea547c8b
commit d2cf059337
5 changed files with 101 additions and 7 deletions
+33
View File
@@ -0,0 +1,33 @@
import pytest
from secret_auction.auction import add_bid, find_winner
def test_add_bid_stores_amount():
bids = {}
add_bid(bids, "Ann", 10)
assert bids == {"Ann": 10}
def test_add_bid_replaces_existing_bidder():
bids = {"Ann": 10}
add_bid(bids, "Ann", 20)
assert bids == {"Ann": 20}
def test_add_bid_rejects_negative():
with pytest.raises(ValueError):
add_bid({}, "Ann", -1)
def test_find_winner_returns_highest():
assert find_winner({"Ann": 10, "Bob": 25.5, "Cy": 3}) == ("Bob", 25.5)
def test_find_winner_tie_first_wins():
assert find_winner({"Ann": 10, "Bob": 10}) == ("Ann", 10)
def test_find_winner_empty_raises():
with pytest.raises(ValueError):
find_winner({})