soroban-abacus-flashcards/tests
Thomas Hallock f28256dc60 feat: implement authentic adjacent bead spacing for realistic abacus appearance
This commit perfects the visual authenticity of the soroban abacus by implementing
proper spacing between beads that matches how a real abacus behaves.

Key improvements:
1. Adjacent Bead Spacing System:
   - Adjacent beads of same type (active-to-active, inactive-to-inactive): 0.5pt spacing (nearly touching)
   - Transition gaps (active-to-inactive): 8pt spacing (clear visual separation)
   - Bar-to-bead gaps: 1pt (active) or 8pt (inactive) as appropriate

2. Physical Abacus Authenticity:
   - Active beads cluster together near the reckoning bar
   - Inactive beads cluster together away from active beads
   - Clear visual distinction between active and inactive states
   - Matches the tactile grouping behavior of real soroban beads

3. Enhanced Visual Impact:
   - Numbers like 2,3,4: Active earth beads touch each other
   - Numbers like 6,7,8,9: Both active and inactive groups clearly defined
   - Number 0: All inactive beads form cohesive groups
   - Number 5: Clean separation between active heaven and inactive earth

Technical Implementation:
- New adjacent-spacing parameter (0.5pt) for same-type bead pairs
- Updated positioning calculations throughout earth bead logic
- Maintained rod bounds calculation compatibility
- Preserved all existing gap logic for different-type transitions

The result is a much more authentic and visually appealing representation that
accurately reflects how beads behave on a physical soroban abacus.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 09:25:24 -05:00
..
references feat: implement authentic adjacent bead spacing for realistic abacus appearance 2025-09-10 09:25:24 -05:00
README.md refactor: remove skipped test and unused reference update utility 2025-09-09 17:35:23 -05:00
__init__.py feat: add comprehensive test suite with visual regression testing 2025-09-09 17:29:09 -05:00
conftest.py refactor: remove skipped test and unused reference update utility 2025-09-09 17:35:23 -05:00
test_config.py fix: resolve test failures and improve test robustness 2025-09-09 17:33:44 -05:00
test_generation.py feat: add comprehensive test suite with visual regression testing 2025-09-09 17:29:09 -05:00
test_quiz_functionality.py test: add comprehensive quiz functionality tests 2025-09-09 20:51:59 -05:00
test_visual.py refactor: remove skipped test and unused reference update utility 2025-09-09 17:35:23 -05:00
test_web_generation.py feat: implement physical abacus logic and fix numeral coloring regression 2025-09-10 09:12:43 -05:00

README.md

Testing

This directory contains automated tests for the Soroban flashcard generator.

Test Structure

  • test_config.py - Configuration loading and parsing tests
  • test_generation.py - Core generation logic tests
  • test_visual.py - Visual regression tests using image comparison
  • conftest.py - Pytest fixtures and configuration
  • references/ - Reference images for visual regression tests

Running Tests

Quick Start

make pytest-fast    # Run unit tests (fast)
make pytest-visual  # Run visual regression tests
make pytest         # Run all tests
make pytest-cov     # Run with coverage report

Direct pytest usage

# All tests
python3 -m pytest tests/ -v

# Skip slow tests
python3 -m pytest tests/ -v -m "not slow" 

# Visual tests only
python3 -m pytest tests/test_visual.py -v

# With coverage
python3 -m pytest tests/ -v --cov=src

Visual Testing

The visual tests generate flashcard images and compare them against reference images using perceptual hashing. This catches visual regressions while allowing for minor differences.

Updating References

When you make intentional visual changes, manually delete the old reference images in tests/references/ and run the visual tests. They will automatically create new reference images on first run.

How Visual Tests Work

  1. Generate test images (PNG format, small size for speed)
  2. Compare against reference images using imagehash library
  3. Allow small differences (hash distance < 5) for anti-aliasing variations
  4. Fail if images differ significantly, indicating a regression

Test Philosophy

  • Fast unit tests for logic and configuration
  • Visual regression tests for output verification
  • Integration tests marked as @pytest.mark.slow
  • Meaningful failures with clear error messages
  • Easy maintenance when the app evolves

Adding Tests

When adding features:

  1. Add unit tests in relevant test_*.py file
  2. Add visual tests if output changes
  3. Update references if visual changes are intentional
  4. Use appropriate markers (@pytest.mark.slow, etc.)

CI Integration

Tests are designed to run in CI environments:

  • Skip tests requiring typst if not installed
  • Use smaller images and lower DPI for speed
  • Store reference images in version control
  • Clear pass/fail criteria