Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions assignment-2/test-plan.md
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 20 additions & 0 deletions assignment-2/test-report.md
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 18 additions & 0 deletions assignment-2/test-strategy.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions mock-project/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
Binary file added mock-project/backend/.requirements.txt.swp
Binary file not shown.
24 changes: 24 additions & 0 deletions mock-project/backend/app.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions mock-project/backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask
5 changes: 5 additions & 0 deletions mock-project/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
api:
build: .
ports:
- "5000:5000"
26 changes: 26 additions & 0 deletions mock-project/tests/test_colorblind.py
Original file line number Diff line number Diff line change
@@ -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