Skip to content

Conversation

Copy link

Copilot AI commented Sep 10, 2025

This PR addresses the need for adequate unit test coverage before refactoring by implementing a comprehensive test suite for the supermarket receipt kata Python implementation.

What was added

25 comprehensive test cases covering all existing functionality:

  • All discount types: THREE_FOR_TWO, TEN_PERCENT_DISCOUNT, TWO_FOR_AMOUNT, FIVE_FOR_AMOUNT
  • Receipt printing functionality (previously untested)
  • Edge cases: empty cart, zero prices, large quantities, fractional quantities
  • Product unit handling (EACH vs KILO)
  • Multiple discount scenarios

Coverage improvements

Before: 53% overall coverage with only 1 test
After: 99% coverage (171/173 lines covered)

Module Before After
receipt_printer.py 0% 100%
shopping_cart.py 41% 100%
model_objects.py 89% 100%
receipt.py 93% 100%
teller.py 100% 100%

Test quality features

  • Clear, descriptive test names explaining exact scenarios
  • Comprehensive assertions validating totals, discounts, and individual items
  • Edge case coverage including boundary conditions
  • Mixed discount scenarios with multiple products
  • Complete documentation with README and automated test runner

Files added

  • python/tests/test_supermarket.py - Main test suite
  • python/run_tests.py - Automated test runner with coverage reporting
  • python/tests/README.md - Complete test documentation

Usage

Run tests with coverage:

cd python
python run_tests.py

The test suite now provides a solid safety net for future refactoring, ensuring that any changes maintain existing functionality while enabling confident code improvements.

Note: During testing, documented a potential calculation issue in TWO_FOR_AMOUNT discount logic, but preserved current behavior as requested.

Fixes #5.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/sebastianbergmann/exporter/zipball/78c00df8f170e02473b682df15bfcdacc3d32d72
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/XUewwL /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/global-state/zipball/b6781316bdcd28260904e7cc18ec983d0d2ef4f6
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/XUewwL /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/5c9eeac41b290a3712d88851518825ad78f45c71
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/XUewwL /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/b4f479ebdbf63ac605d183ece17d8d7fe49c15c7
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/XUewwL /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/539c6691e0623af6dc6f9c20384c120f963465a0
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/CTp97h /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/XUewwL /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/CTp97h /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/XUewwL /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/CTp97h /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/XUewwL /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/XUewwL /usr/bin/composer install --no-interaction (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Write unit tests to cover current functionality Add comprehensive unit tests for supermarket receipt functionality Sep 10, 2025
Copilot AI requested a review from nstubbe September 10, 2025 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write unit tests to cover current functionality

2 participants