From b5e1cb84617307f9fbba9d9371af27c2c5e7f505 Mon Sep 17 00:00:00 2001 From: Scott Elliott Date: Tue, 14 Apr 2026 17:13:30 -0700 Subject: [PATCH] add assignment 2 files --- assignment-2/test-plan.md | 19 +++++++++++++++ assignment-2/test-report.md | 20 ++++++++++++++++ assignment-2/test-strategy.md | 18 ++++++++++++++ mock-project/Dockerfile | 6 +++++ mock-project/backend/.requirements.txt.swp | Bin 0 -> 12288 bytes mock-project/backend/app.py | 24 +++++++++++++++++++ mock-project/backend/requirements.txt | 1 + mock-project/docker-compose.yml | 5 ++++ mock-project/tests/test_colorblind.py | 26 +++++++++++++++++++++ 9 files changed, 119 insertions(+) create mode 100644 assignment-2/test-plan.md create mode 100644 assignment-2/test-report.md create mode 100644 assignment-2/test-strategy.md create mode 100644 mock-project/Dockerfile create mode 100644 mock-project/backend/.requirements.txt.swp create mode 100644 mock-project/backend/app.py create mode 100644 mock-project/backend/requirements.txt create mode 100644 mock-project/docker-compose.yml create mode 100644 mock-project/tests/test_colorblind.py diff --git a/assignment-2/test-plan.md b/assignment-2/test-plan.md new file mode 100644 index 0000000..5d4e2b7 --- /dev/null +++ b/assignment-2/test-plan.md @@ -0,0 +1,19 @@ +# Test Plan + +## Features to Test +- Valid hex color pairs +- Identical colors +- Red vs green (should fail) +- Red vs blue (should pass) +- Case insensitivity +- Invalid inputs (documented but not yet validated) + +## Test Cases +See `mock-project/tests/test_colorblind.py` + +## Setup Steps +1. Run `docker compose up -d` from the mock-project folder +2. Run `docker compose exec api pytest tests/ -v` + +## Expected Outcomes +All tests should pass. Tests for invalid inputs are placeholders until validation is added to the function. \ No newline at end of file diff --git a/assignment-2/test-report.md b/assignment-2/test-report.md new file mode 100644 index 0000000..1d5faa9 --- /dev/null +++ b/assignment-2/test-report.md @@ -0,0 +1,20 @@ +# Test Report + +## AI-Generated Tests +I asked an AI to generate pytest unit tests for the colorblindness function. The AI produced tests for red vs green, red vs blue, identical colors, and case sensitivity. + +## Validation Results +- Red vs green: PASS +- Red vs blue: PASS +- Identical colors: PASS +- Case insensitivity: PASS +- Invalid hex format: PLACEHOLDER + +## What I Changed +The AI assumed the function would validate hex format. It does not. I left that test as a placeholder to document the gap. + +## What I Added +I added tests for green vs green and case insensitivity. The AI missed those. + +## Assessment +AI-generated tests are a good starting point but miss edge cases and assume functionality that may not exist. Human review is essential. \ No newline at end of file diff --git a/assignment-2/test-strategy.md b/assignment-2/test-strategy.md new file mode 100644 index 0000000..615b381 --- /dev/null +++ b/assignment-2/test-strategy.md @@ -0,0 +1,18 @@ +# Test Strategy + +## Area Under Test +A function that takes two hex color codes and returns whether they are distinguishable for someone with red-green colorblindness. + +## Test Approach +Black-box unit testing. The function will be tested without knowledge of its internal implementation. + +## Tools +- pytest for test execution +- Docker for environment isolation + +## Quality Metrics +- Test pass/fail rate +- Coverage of valid inputs, invalid inputs, and edge cases + +## Risks +The function is simplified and does not implement true perceptual distance. Tests may pass but not reflect real-world colorblindness. \ No newline at end of file diff --git a/mock-project/Dockerfile b/mock-project/Dockerfile new file mode 100644 index 0000000..6aa95d1 --- /dev/null +++ b/mock-project/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.11-slim +WORKDIR /app +COPY backend/requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt +COPY backend/ . +CMD ["python", "app.py"] diff --git a/mock-project/backend/.requirements.txt.swp b/mock-project/backend/.requirements.txt.swp new file mode 100644 index 0000000000000000000000000000000000000000..c41886281cfbc79ad34ce1e595e8b8575da32a48 GIT binary patch literal 12288 zcmeI%F;2rU6vpvac0>giC@`mP%K}GWU~HL_*ez~J9FiAc<5H|#f&(yc5JVCI8-=yX z-;!n7e#85Io8@G(xV#!&jHl9!p~&;=n_tvJd5J`-G^n=ce~hj!x{V7B#kNwDIqPH7 zm78my+wf2s>+a3U>rI^)b(Q*jWwMZNqM{6Im#RtPbmMYsN_SWL(q%5!YOIg{>1$gr z+#%2_fm)Z*`TqQDHl4J&Pfw0VM~CxX5fByu1Q0*~0R#|00D-;>Xfcqd24U|DV(`n_ zcPH{AfB*srAbOXlDEW|NZ{&_PZR6-Vs0m0R#|0009IL NKmY**5J2EZ;1kdrG~ECI literal 0 HcmV?d00001 diff --git a/mock-project/backend/app.py b/mock-project/backend/app.py new file mode 100644 index 0000000..0a315e2 --- /dev/null +++ b/mock-project/backend/app.py @@ -0,0 +1,24 @@ +from flask import Flask, request, jsonify + +app = Flask(__name__) + +def is_distinguishable(color1, color2): + if color1 == color2: + return False + if (color1.lower() == "#ff0000" and color2.lower() == "#00ff00") or \ + (color1.lower() == "#00ff00" and color2.lower() == "#ff0000"): + return False + return True + +@app.route('/check', methods=['POST']) +def check(): + data = request.get_json() + color1 = data.get('color1') + color2 = data.get('color2') + if not color1 or not color2: + return jsonify({'error': 'Missing color parameters'}), 400 + result = is_distinguishable(color1, color2) + return jsonify({'distinguishable': result}) + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5000) \ No newline at end of file diff --git a/mock-project/backend/requirements.txt b/mock-project/backend/requirements.txt new file mode 100644 index 0000000..8ab6294 --- /dev/null +++ b/mock-project/backend/requirements.txt @@ -0,0 +1 @@ +flask \ No newline at end of file diff --git a/mock-project/docker-compose.yml b/mock-project/docker-compose.yml new file mode 100644 index 0000000..7e8fa42 --- /dev/null +++ b/mock-project/docker-compose.yml @@ -0,0 +1,5 @@ +services: + api: + build: . + ports: + - "5000:5000" diff --git a/mock-project/tests/test_colorblind.py b/mock-project/tests/test_colorblind.py new file mode 100644 index 0000000..05ff625 --- /dev/null +++ b/mock-project/tests/test_colorblind.py @@ -0,0 +1,26 @@ +import pytest +import sys +import os + +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../backend'))) +from app import is_distinguishable + +def test_red_vs_green(): + assert is_distinguishable("#FF0000", "#00FF00") == False + +def test_red_vs_blue(): + assert is_distinguishable("#FF0000", "#0000FF") == True + +def test_identical_colors(): + assert is_distinguishable("#FF0000", "#FF0000") == False + +def test_green_vs_green(): + assert is_distinguishable("#00FF00", "#00FF00") == False + +def test_case_insensitivity(): + assert is_distinguishable("#ff0000", "#00ff00") == False + +def test_invalid_hex_format(): + # Current function does not validate, but test documents the expectation + result = is_distinguishable("invalid", "#FF0000") + assert result in [True, False] # Placeholder until validation is added \ No newline at end of file