diff --git a/problems/miniconverter/SPEC-v0.txt b/problems/miniconverter/SPEC-v0.txt new file mode 100644 index 0000000..769f2b7 --- /dev/null +++ b/problems/miniconverter/SPEC-v0.txt @@ -0,0 +1,48 @@ +PROJECT: miniconverter +AUTHOR: HASAN YILMAZ (250708022) +VERSION: v0 +DATE: 2026-03-15 + +======================================== +OVERVIEW +======================================== +mini-converter is a CLI tool for length unit conversions. +Supported units: meters (m), kilometers (km), centimeters (cm), millimeters (mm). +All data is stored in a directory called .miniconv/ in the current directory. + +======================================== +COMMANDS +======================================== + +--- init --- +Usage: python miniconverter.py init +Behavior: Creates .miniconv/ directory and history.dat file. +Output: "Conversion storage initialized." or "Already initialized." + +--- convert --- +Usage: python miniconverter.py convert +Behavior: Converts the value and logs it to .miniconv/history.dat. +Output: " is " + +--- history --- +Usage: python miniconverter.py history +Output: "Command 'history' will be implemented in future weeks." + +--- stats --- +Usage: python miniconverter.py stats +Output: "Command 'stats' will be implemented in future weeks." + +======================================== +DATA FORMAT +======================================== +File: .miniconv/history.dat +Format: value|from_unit|to_unit|result|date +Example: 10.0|m|cm|1000.0|2026-03-13 + +======================================== +ERROR HANDLING +======================================== +- Run before init: "Error: Not initialized. Run: python miniconverter.py init" +- Unsupported unit: "Error: Unsupported unit . Use m, km, cm, or mm." +- Missing arguments: "Usage: python miniconverter.py [args]" +- Unknown command: "Unknown command: " diff --git a/problems/miniconverter/SPEC-v1.txt b/problems/miniconverter/SPEC-v1.txt new file mode 100644 index 0000000..38774da --- /dev/null +++ b/problems/miniconverter/SPEC-v1.txt @@ -0,0 +1,66 @@ +PROJECT: miniconverter +AUTHOR: HASAN YILMAZ (250708022) +VERSION: V1 +DATE: 2026-03-27 + + +======================================== +OVERVIEW +======================================== +mini-converter is a CLI tool for length unit conversions. +Supported units: meters (m), kilometers (km), centimeters (cm), millimeters (mm). +All data is stored in a directory called .miniconv/ in the current directory. + + +======================================== +COMMANDS +======================================== + +--- init --- +Usage: python miniconverter.py init +Behavior: Creates .miniconv/ directory and history.dat file. +Output: "Conversion storage initialized." or "Already initialized." + +--- convert --- +Usage: python miniconverter.py convert +Behavior: Converts the value and logs it to .miniconv/history.dat. + +[V2 ENHANCEMENTS]: +- Case Insensitivity: Unit inputs (m, km, cm, mm) are accepted regardless of case (e.g., KM, m, Cm are all valid). +- Decimal Precision: Input values and results support decimal numbers and are processed with 2-decimal precision (e.g., 1.234 m is calculated as 123.40 cm). + +Output: " is " + +--- history --- +Usage: python miniconverter.py history +Output: "Command 'history' will be implemented in future weeks." + +--- stats --- +Usage: python miniconverter.py stats +Output: "Command 'stats' will be implemented in future weeks." + + +======================================== +V1 CHANGE LOG +======================================== +1. Added full support for mixed-case unit strings (Case Insensitivity). +2. Implemented 2-decimal place precision for all numeric calculations. +3. Maintained backward compatibility with v0 file structures and commands. +4. Updated error messages to provide better guidance for input units. + + +======================================== +DATA FORMAT +======================================== +File: .miniconv/history.dat +Format: value|from_unit|to_unit|result|date +Example: 10.0|m|cm|1000.00|2026-03-27 + + +======================================== +ERROR HANDLING +======================================== +- Run before init: "Error: Not initialized. Run: python miniconverter.py init" +- Unsupported unit: "Error: Unsupported unit . Use m, km, cm, or mm." +- Missing arguments: "Usage: python miniconverter.py [args]" +- Unknown command: "Unknown command: " \ No newline at end of file diff --git a/problems/miniconverter/SPEC-v2.txt b/problems/miniconverter/SPEC-v2.txt new file mode 100644 index 0000000..4ae9bf5 --- /dev/null +++ b/problems/miniconverter/SPEC-v2.txt @@ -0,0 +1,68 @@ +PROJECT: miniconverter +AUTHOR: HASAN YILMAZ (250708022) +VERSION: V2 +DATE: 2026-04-16 + +======================================== +OVERVIEW +======================================== +miniconverter is a CLI tool for length unit conversions. +Supported units: meters (m), kilometers (km), centimeters (cm), millimeters (mm). +All data is stored in a directory called .miniconv/ in the current directory. + +======================================== +COMMANDS +======================================== + +--- init --- +Usage: python miniconverter.py init +Behavior: Creates .miniconv/ directory and history.dat file. +Output: "Conversion storage initialized." or "Already initialized." + +--- convert --- +Usage: python miniconverter.py convert +Behavior: Converts the value and logs it to .miniconv/history.dat. + +[V1 ENHANCEMENTS]: +- Case Insensitivity: Unit inputs (m, km, cm, mm) are accepted regardless of case. +- Decimal Precision: Input values and results support decimal numbers. + +[V2 ENHANCEMENTS]: +- Value Validation: The system checks if the input is a valid number before processing to prevent crashes. +- Command Handling: The program identifies and reports unknown commands instead of failing silently. +- Output & Log Consistency: Standardizes 2-decimal format across all terminal outputs and history.dat entries. + +Output: " is " + +--- history --- +Usage: python miniconverter.py history +Output: "Command 'history' will be implemented in future weeks." + +--- stats --- +Usage: python miniconverter.py stats +Output: "Command 'stats' will be implemented in future weeks." + +======================================== +V2 CHANGE LOG +======================================== +1. Added full support for mixed-case unit strings (Inherited from V1). +2. Implemented 2-decimal place precision for all numeric calculations (Inherited from V1). +3. Added strict validation to catch non-numeric inputs for the argument. +4. Implemented explicit error messages for unknown CLI commands (e.g., Unknown command: ). +5. Standardized output and log file formatting for better data consistency. + +======================================== +DATA FORMAT +======================================== +File: .miniconv/history.dat +Format: value|from_unit|to_unit|result|date +Example: 10.0|m|cm|1000.00|2026-04-16 + +======================================== +ERROR HANDLING +======================================== +- Run before init: "Error: Not initialized. Run: python miniconverter.py init" +- Unsupported unit: "Error: Unsupported unit . Use m, km, cm, or mm." +- Invalid Value: "Error: is not a valid number." +- Unknown command: "Unknown command: " +- Missing arguments: "Usage: python miniconverter.py [args]" \ No newline at end of file diff --git a/problems/miniconverter/problem.json b/problems/miniconverter/problem.json new file mode 100644 index 0000000..dc718e5 --- /dev/null +++ b/problems/miniconverter/problem.json @@ -0,0 +1,16 @@ +{ + "name": "miniconverter", + "type": "cli", + "language": "python", + "adapter": "cli", + "binary_name": "solution_v2.py", + "v0_spec": "SPEC-v0.txt", + "v0_test": "test-v0.sh", + "v0_prompt": "Implement {{binary_name}} as described in SPEC-v0.txt using Python. The program must support 'init' and 'convert' commands. Verify your implementation passes all tests by running: bash test-v0.sh", + "v1_spec": "SPEC-v1.txt", + "v1_test": "test-v1.sh", + "v1_prompt": "Read SPEC-v1.txt and extend the existing {{binary_name}} implementation with case-insensitivity and decimal precision as described in SPEC-v1.txt. Verify your implementation passes all tests by running: 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 non-numeric value validation as described in SPEC-v2.txt. Verify your implementation passes all tests by running: bash test-v2.sh" +} diff --git a/problems/miniconverter/test-v0.sh b/problems/miniconverter/test-v0.sh new file mode 100644 index 0000000..e3609e0 --- /dev/null +++ b/problems/miniconverter/test-v0.sh @@ -0,0 +1,131 @@ +#!/usr/bin/env bash +# mini-converter v0 Bash Test Script +# Ogrenci: HASAN YILMAZ 250708022 +set -e + +PASS_COUNT=0 +FAIL_COUNT=0 + +# +fail() { + echo "FAIL: $1" + FAIL_COUNT=$((FAIL_COUNT+1)) +} + +pass() { + echo "PASS: $1" + PASS_COUNT=$((PASS_COUNT+1)) +} + +cleanup() { + # Her testten once klasoru temizle + rm -rf .miniconv +} + +# Calistirilacak ana komut +BIN="python3 solution_v0.py" + +###################################### +# Setup +###################################### +cleanup + +###################################### +# Test 1: init creates directory +###################################### +if $BIN init > /dev/null && [ -d .miniconv ]; then + pass "init creates .miniconv directory" +else + fail "init creates .miniconv directory" +fi + +###################################### +# Test 2: init already exists +###################################### +if $BIN init | grep -q "Already initialized"; then + pass "init already exists prints correct message" +else + fail "init already exists prints correct message" +fi + +###################################### +# Test 3: convert m to cm +###################################### +if $BIN convert 1 m cm | grep -q "1.0 m is 100.0 cm"; then + pass "convert 1 m to cm works" +else + fail "convert 1 m to cm works" +fi + +###################################### +# Test 4: convert km to m +###################################### +if $BIN convert 2 km m | grep -q "2000.0 m"; then + pass "convert 2 km to m works" +else + fail "convert 2 km to m works" +fi + +###################################### +# Test 5: unsupported unit +###################################### +if $BIN convert 5 m mile | grep -q "Error"; then + pass "unsupported unit returns Error" +else + fail "unsupported unit returns Error" +fi + +###################################### +# Test 6: future weeks commands (history/stats) +###################################### +if $BIN history | grep -q "future weeks" && $BIN stats | grep -q "future weeks"; then + pass "history/stats show future weeks message" +else + fail "history/stats show future weeks message" +fi + +###################################### +# Test 7: error no init +###################################### +cleanup +if $BIN convert 1 m cm | grep -q "Not initialized"; then + pass "error when running convert without init" +else + fail "error when running convert without init" +fi + +###################################### +# Test 8: unknown command +###################################### +$BIN init > /dev/null +if $BIN reset | grep -q "Unknown command"; then + pass "unknown command returns correct message" +else + fail "unknown command returns correct message" +fi + +###################################### +# Test 9: missing arguments +###################################### +if $BIN convert 10 m | grep -q "Usage"; then + pass "missing arguments shows Usage message" +else + fail "missing arguments shows Usage message" +fi + +###################################### +# Summary +###################################### +echo "" +echo "========================" +echo "PASSED: $PASS_COUNT" +echo "FAILED: $FAIL_COUNT" +echo "TOTAL: $((PASS_COUNT + FAIL_COUNT))" +echo "========================" + +if [ "$FAIL_COUNT" -eq 0 ]; then + echo "ALL V1 TESTS PASSED" + exit 0 +else + exit 1 +fi diff --git a/problems/miniconverter/test-v1.sh b/problems/miniconverter/test-v1.sh new file mode 100644 index 0000000..b140f1b --- /dev/null +++ b/problems/miniconverter/test-v1.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash +# mini-converter v1 Bash Test Script +# Ogrenci: HASAN YILMAZ (250708022) +set -e + +PASS_COUNT=0 +FAIL_COUNT=0 + +# +fail() { + echo "FAIL: $1" + FAIL_COUNT=$((FAIL_COUNT+1)) +} + +pass() { + echo "PASS: $1" + PASS_COUNT=$((PASS_COUNT+1)) +} + +cleanup() { + # Her testten once klasoru temizle [cite: 18] + rm -rf .miniconv +} + +# [DIKKAT] Artik solution_v1.py dosyasini test ediyoruz! [cite: 18] +BIN="python3 solution_v1.py" + +###################################### +# Setup +###################################### +cleanup + +###################################### +# Test 1: Case Insensitivity (KM to M) +###################################### +$BIN init > /dev/null +# Kullanici 'KM' ve 'M' yazsa da hata almamali ve dogru sonuc donmeli +if $BIN convert 1 KM M | tr '[:upper:]' '[:lower:]' | grep -q "1.0 km is 1000.0 m"; then + pass "v2: case insensitivity works (KM -> M)" +else + fail "v2: case insensitivity works (KM -> M)" +fi + +###################################### +# Test 2: Decimal Precision (2 digits) +###################################### +# 1.234 metre, 123.4 (veya 123.40) olarak yuvarlanmali +if $BIN convert 1.234 m cm | grep -q "123.4"; then + pass "v2: decimal precision (2 digits) works" +else + fail "v2: decimal precision (2 digits) works" +fi + +###################################### +# Test 3: init creates folder +###################################### +cleanup +if $BIN init > /dev/null && [ -d .miniconv ]; then + pass "init creates .miniconv directory" +else + fail "init creates .miniconv directory" +fi + +###################################### +# Test 4: convert m to cm +###################################### +if $BIN convert 1 m cm | grep -q "1.0 m is 100.0 cm"; then + pass "convert 1 m to cm works" +else + fail "convert 1 m to cm works" +fi + +###################################### +# Test 5: unsupported unit [cite: 20] +###################################### +if $BIN convert 5 m mile | grep -q "Error"; then + pass "unsupported unit returns Error" +else + fail "unsupported unit returns Error" +fi + +###################################### +# Test 6: error no init [cite: 20] +###################################### +cleanup +if $BIN convert 1 m cm | grep -q "Not initialized"; then + pass "error when running convert without init" +else + fail "error when running convert without init" +fi + +###################################### +# Summary +###################################### +echo "" +echo "========================" +echo "PASSED: $PASS_COUNT" +echo "FAILED: $FAIL_COUNT" +echo "TOTAL: $((PASS_COUNT + FAIL_COUNT))" +echo "========================" + +if [ "$FAIL_COUNT" -eq 0 ]; then + echo "ALL V2 TESTS PASSED" + exit 0 +else + exit 1 +fi \ No newline at end of file diff --git a/problems/miniconverter/test-v2.sh b/problems/miniconverter/test-v2.sh new file mode 100644 index 0000000..52047d1 --- /dev/null +++ b/problems/miniconverter/test-v2.sh @@ -0,0 +1,133 @@ +#!/usr/bin/env bash +# miniconverter v2 Full Regression Test Script +# Ogrenci: HASAN YILMAZ (250708022) +# Guncelleme: V0, V1 ve V2 ozelliklerinin tamamı denetlenmektedir. +set -e + +PASS_COUNT=0 +FAIL_COUNT=0 + +# Yardımcı Fonksiyonlar +fail() { + echo "FAIL: $1" + FAIL_COUNT=$((FAIL_COUNT+1)) +} + +pass() { + echo "PASS: $1" + PASS_COUNT=$((PASS_COUNT+1)) +} + +cleanup() { + # Her testten once klasoru temizleyerek izole bir ortam saglıyoruz + rm -rf .miniconv +} + +# [KRITIK] problem.json ile uyumlu ikili dosya ismi +BIN="python3 solution_v2.py" + +###################################### +# SETUP & INITIALIZATION +###################################### +cleanup + +###################################### +# TEST 1: V0 - Init Creates Directory +###################################### +# Program ilk kez calıstıgında dizin olusturmalı +if $BIN init > /dev/null && [ -d .miniconv ]; then + pass "v0: init creates .miniconv directory" +else + fail "v0: init creates .miniconv directory" +fi + +###################################### +# TEST 2: V0 - Basic Conversion (m to cm) +###################################### +# Temel donusum dogru calısmalı +if $BIN convert 10 m cm | grep -q "10.0 m is 1000.00 cm"; then + pass "v0: basic convert (10m to cm) works" +else + fail "v0: basic convert (10m to cm) works" +fi + +###################################### +# TEST 3: V1 - Case Insensitivity (KM to M) +###################################### +# Buyuk harf girisleri kucuk harf gibi islenmeli +if $BIN convert 1 KM M | tr '[:upper:]' '[:lower:]' | grep -q "1.0 km is 1000.00 m"; then + pass "v1: case insensitivity works (KM -> M)" +else + fail "v1: case insensitivity works (KM -> M)" +fi + +###################################### +# TEST 4: V1 - Decimal Precision (Float Support) +###################################### +# Ondalık sayılar 2 basamak hassasiyetle gosterilmeli +if $BIN convert 1.234 m cm | grep -q "123.40"; then + pass "v1: decimal precision (1.234m -> 123.40cm) works" +else + fail "v1: decimal precision (1.234m -> 123.40cm) works" +fi + +###################################### +# TEST 5: V2 - Invalid Value Validation +###################################### +# Sayı yerine metin girildiginde program cokmemeli +if $BIN convert elma m cm | grep -q "Error: elma is not a valid number."; then + pass "v2: non-numeric value error handling (elma test) works" +else + fail "v2: non-numeric value error handling (elma test) works" +fi + +###################################### +# TEST 6: V2 - Unknown Command Handling +###################################### +# Bilinmeyen bir komut girildiginde kullanıcı uyarılmalı +if $BIN reset | grep -q "Unknown command: reset"; then + pass "v2: unknown command handling works" +else + fail "v2: unknown command handling works" +fi + +###################################### +# TEST 7: Global - Unsupported Unit Error +###################################### +# Desteklenmeyen birimler hata dondurmeli +if $BIN convert 5 m mile | grep -q "Error"; then + pass "global: unsupported unit returns Error" +else + fail "global: unsupported unit returns Error" +fi + +###################################### +# TEST 8: Global - Error No Init +###################################### +cleanup +# Init yapılmadan islemlere izin verilmemeli +if $BIN convert 1 m cm | grep -q "Not initialized"; then + pass "global: error when running convert without init" +else + fail "global: error when running convert without init" +fi + +###################################### +# SUMMARY REPORT +###################################### +echo "" +echo "========================================" +echo " MINICONVERTER V2 TEST RESULTS " +echo "========================================" +echo "PASSED: $PASS_COUNT" +echo "FAILED: $FAIL_COUNT" +echo "TOTAL TESTS: $((PASS_COUNT + FAIL_COUNT))" +echo "========================================" + +if [ "$FAIL_COUNT" -eq 0 ]; then + echo ">>> ALL V0, V1 AND V2 TESTS PASSED <<<" + exit 0 +else + echo ">>> SOME TESTS FAILED <<<" + exit 1 +fi \ No newline at end of file