diff --git a/problems/miniscoreboard/SPEC-v1.txt b/problems/miniscoreboard/SPEC-v1.txt index ae4a6cd6..da1182db 100644 --- a/problems/miniscoreboard/SPEC-v1.txt +++ b/problems/miniscoreboard/SPEC-v1.txt @@ -48,4 +48,4 @@ ERROR HANDLING - Inputs containing '|': print "Error: The '|' character is reserved." - Non-numeric scores: print "Error: Scores must be positive numbers." - Empty team names: print "Error: Team names cannot be empty." -- Team playing itself: print "Error: A team cannot play against itself." +- Team playing itself: print "Error: A team cannot play against itself." diff --git a/problems/miniscoreboard/SPEC-v2.txt b/problems/miniscoreboard/SPEC-v2.txt index 1aa54cf6..b735e934 100644 --- a/problems/miniscoreboard/SPEC-v2.txt +++ b/problems/miniscoreboard/SPEC-v2.txt @@ -8,58 +8,45 @@ OVERVIEW ======================================== miniscoreboard is a command-line sports match management tool. -It stores match records in a plain text file and supports -initializing the system, adding new match results, viewing -historical matches, and filtering by team. - -All data is persisted in a directory called .miniscore/ -in the current working directory. +This version improves the system by adding data retrieval, +filtering capabilities, and stronger validation rules. ======================================== -COMMANDS +NEW FEATURES (V2 IMPROVEMENTS) ======================================== ---- init --- -Usage: python miniscore.py init -Creates a .miniscore/ directory and an empty matches.dat file. -If .miniscore/ already exists, prints "Already initialized". +1. Match History Retrieval +2. Team-based Filtering +3. Input Validation Enhancements ---- add-match --- -Usage: python miniscore.py add-match -Appends a new match to matches.dat. -Each match has: id (auto-increment), league, week, date, teama, scorea, teamb, scoreb. -Prints "Added match #: [ - ] - on " +======================================== +COMMANDS +======================================== --- history --- Usage: python miniscore.py history -Reads the .miniscore/matches.dat file and prints all matches. -Format per line: [] - () +Lists all matches in the system. If no matches exist, prints "History is empty." --- team --- Usage: python miniscore.py team -Filters matches and prints only the ones where played -(either as TeamA or TeamB). -Format per line: [ - ] - () -If no matches are found, prints "No matches found for ." +Filters matches where the given team participated. +If no matches found, prints "No matches found for ." ======================================== -DATA FORMAT +VALIDATION RULES ======================================== -File: .miniscore/matches.dat -Format: One match per line, fields separated by | -Example: -1|SuperLig|W1|2026-04-01|GALATASARAY|2|FENERBAHCE|1 +- Input cannot contain '|' +- Scores must be numeric and positive +- Team names cannot be empty +- A team cannot play against itself ======================================== -ERROR HANDLING +IMPROVEMENT SUMMARY ======================================== -- Running any command before "init": print "Not initialized." -- Invalid command: print "Unknown command: " -- Missing arguments: print "Usage: python miniscore.py [args]" -- Inputs containing '|': print "Error: The '|' character is reserved." -- Non-numeric scores: print "Error: Scores must be positive numbers." -- Empty team names: print "Error: Team names cannot be empty." -- Team playing itself: print "Error: A team cannot play against itself." \ No newline at end of file +Compared to V1: +- System now supports reading stored data +- Users can filter matches by team +- Input errors are handled more strictly \ No newline at end of file diff --git a/problems/miniscoreboard/problem.json b/problems/miniscoreboard/problem.json index cef35dab..4b85047b 100644 --- a/problems/miniscoreboard/problem.json +++ b/problems/miniscoreboard/problem.json @@ -3,8 +3,8 @@ "binary_name": "miniscore", "v1_spec": "SPEC-v1.txt", "v1_test": "test-v1.sh", - "v1_prompt": "Implement {{binary_name}} as described in SPEC-v1.txt using {{language}}. The executable must be named '{{binary_name}}' and be runnable as ./{{binary_name}}. For compiled languages, include a Makefile or build script. For interpreted languages, ensure the {{binary_name}} file has a proper shebang line and is executable. Handle init and add-match commands. Verify your implementation passes all tests by running: bash test-v1.sh", + "v1_prompt": "Implement {{binary_name}} as described in SPEC-v1.txt. Use standard libraries. Verification: bash test-v1.sh", "v2_spec": "SPEC-v2.txt", "v2_test": "test-v2.sh", - "v2_prompt": "Read SPEC-v2.txt and extend the existing {{binary_name}} implementation with the history and team commands. Verify your implementation using bash test-v2.sh." -} + "v2_prompt": "Extend {{binary_name}} to support 'history' and 'team' commands according to SPEC-v2.txt. Verification: bash test-v2.sh" +} \ No newline at end of file diff --git a/problems/miniscoreboard/test-v1.sh b/problems/miniscoreboard/test-v1.sh index 014d2326..5d5be5a7 100644 --- a/problems/miniscoreboard/test-v1.sh +++ b/problems/miniscoreboard/test-v1.sh @@ -1,29 +1,19 @@ #!/bin/bash - -# miniscoreboard v1 test script +set -e rm -rf .miniscore -# Test 1: Init Command +# Test 1: Init INIT_OUT=$(python3 miniscore.py init) -if [[ "$INIT_OUT" != *"Initialized"* ]]; then - echo "FAIL: Init command did not work." - exit 1 -fi +echo "$INIT_OUT" | grep -E "Initialized|Created" >/dev/null || exit 1 -# Test 2: Add Match Command -ADD_OUT=$(python3 miniscore.py add-match SuperLig W1 2026-03-31 Galatasaray 2 Fenerbahce 1) -if [[ "$ADD_OUT" != *"Added match #1"* ]]; then - echo "FAIL: Add match command did not work correctly." - exit 1 -fi +# Test 2: Add Match +ADD_OUT=$(python3 miniscore.py add-match SuperLig W1 2026-03-31 GS 2 FB 1) +echo "$ADD_OUT" | grep "Added match #1" >/dev/null || exit 1 -# Test 3: Validation (Clone Match) +# Test 3: Validation (same team) CLONE_OUT=$(python3 miniscore.py add-match SuperLig W1 2026-03-31 GS 2 GS 1) -if [[ "$CLONE_OUT" != *"Error"* ]]; then - echo "FAIL: Security validation failed for clone teams." - exit 1 -fi +echo "$CLONE_OUT" | grep "Error" >/dev/null || exit 1 -echo "All V1 tests passed." -exit 0 +echo "All V1 tests passed" +exit 0 \ No newline at end of file diff --git a/problems/miniscoreboard/test-v2.sh b/problems/miniscoreboard/test-v2.sh index 120e3271..1913f7a3 100644 --- a/problems/miniscoreboard/test-v2.sh +++ b/problems/miniscoreboard/test-v2.sh @@ -1,50 +1,50 @@ #!/bin/bash - -# miniscoreboard v2 test script (Includes V1 + V2 capabilities) +set -e rm -rf .miniscore -# --- V1 COMMAND TESTS --- +# --- SETUP --- +python3 miniscore.py init -# Test 1: Init Command -INIT_OUT=$(python3 miniscore.py init) -if [[ "$INIT_OUT" != *"Initialized"* ]]; then - echo "FAIL: Init command did not work." - exit 1 -fi +python3 miniscore.py add-match SuperLig W1 2026-04-01 GS 2 FB 1 > /dev/null +python3 miniscore.py add-match SuperLig W2 2026-04-07 BJK 3 TS 0 > /dev/null +python3 miniscore.py add-match SuperLig W3 2026-04-10 FB 1 BJK 1 > /dev/null -# Test 2: Add Match Command -ADD_OUT=$(python3 miniscore.py add-match SuperLig W1 2026-04-01 Galatasaray 2 Fenerbahce 1) -if [[ "$ADD_OUT" != *"Added match #1"* ]]; then - echo "FAIL: Add match command did not work correctly." - exit 1 -fi +# --- V1 TESTS --- +ADD_CHECK=$(python3 miniscore.py add-match SuperLig W4 2026-04-11 TS 2 GS 0) +echo "$ADD_CHECK" | grep "Added match #4" >/dev/null || exit 1 -# Test 3: Validation (Clone Match) -CLONE_OUT=$(python3 miniscore.py add-match SuperLig W1 2026-04-01 GS 2 GS 1) -if [[ "$CLONE_OUT" != *"Error"* ]]; then - echo "FAIL: Security validation failed for clone teams." - exit 1 -fi +# --- V2 TESTS --- -# --- V2 COMMAND TESTS --- +# History +HIST=$(python3 miniscore.py history) +echo "$HIST" | grep "GS" >/dev/null || exit 1 +echo "$HIST" | grep "BJK" >/dev/null || exit 1 -# Add more data for V2 filtering tests -python3 miniscore.py add-match SuperLig W2 2026-04-07 BJK 3 TS 0 > /dev/null +# Team filter +TEAM=$(python3 miniscore.py team BJK) +echo "$TEAM" | grep "TS" >/dev/null || exit 1 + +# Validation +INVALID=$(python3 miniscore.py add-match SuperLig W5 2026-04-12 GS 2 GS 1) +echo "$INVALID" | grep "Error" >/dev/null || exit 1 + +# --- ADVANCED --- + +# Leaderboard +LB=$(python3 miniscore.py leaderboard) +echo "$LB" | grep "\[1\]" >/dev/null || exit 1 + +# Summary +SUM=$(python3 miniscore.py summary) +echo "$SUM" | grep "Total Matches" >/dev/null || exit 1 + +# Export +EXP=$(python3 miniscore.py export) +echo "$EXP" | grep "Exported" >/dev/null || exit 1 + +# File check +[ -f ".miniscore/matches.json" ] || exit 1 -# Test 4: History Command -HIST_OUT=$(python3 miniscore.py history) -if [[ "$HIST_OUT" != *"Galatasaray"* ]] || [[ "$HIST_OUT" != *"BJK"* ]]; then - echo "FAIL: History command did not list all matches." - exit 1 -fi - -# Test 5: Team Filter Command -TEAM_OUT=$(python3 miniscore.py team BJK) -if [[ "$TEAM_OUT" != *"TS"* ]] || [[ "$TEAM_OUT" == *"Galatasaray"* ]]; then - echo "FAIL: Team command filtering is broken." - exit 1 -fi - -echo "All V1 and V2 tests passed." +echo "All V1 + V2 (enhanced) tests passed" exit 0 \ No newline at end of file