This commit includes two major improvements: 1. Physical Abacus Logic for Bead Positioning: - Rewrote bead positioning to accurately model physical soroban behavior - Active beads positioned close to reckoning bar in sequence - Inactive beads positioned after active beads + gap, or after bar + gap if no active beads - Consistent 5pt gaps maintain proper visual separation - Fixes PDF/SVG positioning inconsistencies 2. Individual Digit Coloring for Place-Value Scheme: - Fixed regression where numerals showed single color instead of per-digit colors - Added get_colored_numeral_html() for proper multi-color numeral rendering - Place-value scheme now colors each digit by its place value (ones=blue, tens=magenta, etc.) - Other schemes (heaven-earth, alternating) use single color spans - Maintains backwards compatibility with existing tests Technical Changes: - templates/flashcards.typ: Complete rewrite of bead positioning logic - src/web_generator.py: New HTML generation for colored numerals - tests/test_web_generation.py: Updated tests for new coloring behavior - tests/references/: Updated visual regression baseline 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Testing
This directory contains automated tests for the Soroban flashcard generator.
Test Structure
test_config.py- Configuration loading and parsing teststest_generation.py- Core generation logic teststest_visual.py- Visual regression tests using image comparisonconftest.py- Pytest fixtures and configurationreferences/- 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
- Generate test images (PNG format, small size for speed)
- Compare against reference images using
imagehashlibrary - Allow small differences (hash distance < 5) for anti-aliasing variations
- 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:
- Add unit tests in relevant
test_*.pyfile - Add visual tests if output changes
- Update references if visual changes are intentional
- 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