This repository contains a Python implementation of a package sorting system for Thoughtful's robotic automation factory. The system categorizes packages into different stacks based on their dimensions and mass.
The robotic arm needs to dispatch packages to the correct stack according to their volume and mass:
- Bulky Package: Volume ≥ 1,000,000 cm³ OR any dimension ≥ 150 cm
- Heavy Package: Mass ≥ 20 kg
- STANDARD: Packages that are neither bulky nor heavy
- SPECIAL: Packages that are either heavy OR bulky (but not both)
- REJECTED: Packages that are both heavy AND bulky
- Python 3.8 or higher
- pip (Python package installer)
- Clone or download this repository
- Navigate to the project directory
- Install development dependencies (optional, for linting and testing):
pip install -r requirements.txtRun the package sorting system with command-line arguments:
python solution.py --width <width> --height <height> --length <length> --mass <mass>Example:
python solution.py --width 100 --height 100 --length 100 --mass 10Output: SPECIAL
# Standard package (small and light) python solution.py --width 50 --height 50 --length 50 --mass 10 # Output: STANDARD # Heavy package (not bulky) python solution.py --width 50 --height 50 --length 50 --mass 25 # Output: SPECIAL # Bulky package by dimension (not heavy) python solution.py --width 200 --height 10 --length 10 --mass 5 # Output: SPECIAL # Rejected package (both bulky and heavy) python solution.py --width 200 --height 100 --length 50 --mass 30 # Output: REJECTEDExecute the comprehensive test suite:
python -m unittest test_solution.py -vIf you installed the development dependencies, you can use the following tools:
Format code:
python -m black solution.py test_solution.pyType checking:
python -m mypy solution.pyLinting:
python -m flake8 solution.py test_solution.py python -m pylint solution.py test_solution.pyRun tests with coverage:
python -m coverage run -m unittest test_solution.py python -m coverage report -mFor convenience, you can use the provided Makefile:
make test # Run tests make lint # Run all linting tools make format # Format code make run-example # Run the README example make all # Format, lint, and testfde-solution/ ├── solution.py # Main implementation ├── test_solution.py # Comprehensive test suite ├── requirements.txt # Development dependencies ├── pyproject.toml # Tool configurations ├── Makefile # Development shortcuts └── README.md # This file The solution follows Clean Code principles with:
- Modular Design: Logic split into focused functions
- Type Hints: Full type annotations for better code clarity
- Comprehensive Documentation: Detailed docstrings for all functions
- Input Validation: Proper error handling for invalid inputs
- Extensive Testing: 100% test coverage with edge cases
- Code Quality: Formatted with Black, linted with Flake8 and Pylint
sort(): Main function that categorizes packagesis_bulky(): Determines if a package is bulkyis_heavy(): Determines if a package is heavydetermine_stack_category(): Maps characteristics to stack categories
The test suite includes:
- Unit tests for all individual functions
- Integration tests for the complete system
- Edge case testing (zero dimensions, boundary values)
- Error condition testing (negative inputs)
- Command-line argument parsing tests
- Realistic package scenarios
- The implementation uses ternary operators as specified in the requirements
- All dimensions are in centimeters, mass in kilograms
- The solution handles both integer and float inputs
- Comprehensive error handling with meaningful error messages
- Code follows PEP 8 style guidelines
- Type hints provide clear interface contracts
To quickly verify the solution works correctly, run these commands:
# Test the main example python solution.py --width 100 --height 100 --length 100 --mass 10 # Run all tests python -m unittest test_solution.py -v # Test edge cases python solution.py --width 149 --height 10 --length 10 --mass 19.9 # Should output: STANDARD python solution.py --width 150 --height 10 --length 10 --mass 20 # Should output: REJECTED