File size: 3,586 Bytes
110eb15 5f6bdbf 110eb15 5f6bdbf 110eb15 5f6bdbf 110eb15 5f6bdbf 110eb15 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
"""Simple test script to verify backend installation and basic functionality."""
import sys
import traceback
def test_imports():
"""Test that all required packages can be imported."""
print("Testing imports...")
try:
import fastapi
import uvicorn
import pydantic
import numpy
import shapely
import matplotlib
import ortools
import deap
# Test new module imports
from core.optimization.grid_optimizer import GridOptimizer
from core.optimization.subdivision_solver import SubdivisionSolver
from pipeline.land_redistribution import LandRedistributionPipeline
print("β
All imports successful")
return True
except ImportError as e:
print(f"β Import failed: {e}")
return False
def test_algorithm():
"""Test basic algorithm functionality."""
print("\nTesting algorithm...")
try:
from shapely.geometry import Polygon
from core.optimization.grid_optimizer import GridOptimizer
from core.optimization.subdivision_solver import SubdivisionSolver
# Create simple test polygon
land_poly = Polygon([(0, 0), (100, 0), (100, 100), (0, 100)])
# Test grid optimizer
optimizer = GridOptimizer(land_poly)
blocks = optimizer.generate_grid_candidates(25.0, 0.0)
print(f" Generated {len(blocks)} grid blocks")
# Test subdivision solver
widths = SubdivisionSolver.solve_subdivision(50.0, 5.0, 8.0, 6.0, time_limit=5)
print(f" Subdivision result: {len(widths)} lots")
print("β
Algorithm tests passed")
return True
except Exception as e:
print(f"β Algorithm test failed: {e}")
traceback.print_exc()
return False
def test_api_models():
"""Test Pydantic models."""
print("\nTesting API models...")
try:
from api.schemas.request_schemas import AlgorithmConfig, LandPlot, OptimizationRequest
# Create test config
config = AlgorithmConfig()
print(f" Default config created: spacing={config.spacing_min}-{config.spacing_max}m")
# Create test land plot
land_plot = LandPlot(
type="Polygon",
coordinates=[[[0, 0], [100, 0], [100, 100], [0, 100], [0, 0]]]
)
print(f" Land plot created: {land_plot.type}")
# Create request
request = OptimizationRequest(config=config, land_plots=[land_plot])
print(f" Request created with {len(request.land_plots)} plots")
print("β
API models tests passed")
return True
except Exception as e:
print(f"β API models test failed: {e}")
traceback.print_exc()
return False
if __name__ == "__main__":
print("=" * 50)
print("Algorithm Backend Test Suite (Modular Architecture)")
print("=" * 50)
results = []
results.append(("Imports", test_imports()))
results.append(("API Models", test_api_models()))
results.append(("Algorithm", test_algorithm()))
print("\n" + "=" * 50)
print("Test Results:")
print("=" * 50)
for name, passed in results:
status = "β
PASS" if passed else "β FAIL"
print(f"{status} - {name}")
all_passed = all(r[1] for r in results)
print("\n" + "=" * 50)
if all_passed:
print("β
ALL TESTS PASSED")
sys.exit(0)
else:
print("β SOME TESTS FAILED")
sys.exit(1)
|