import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) import urllib.request import numpy as np import cv2 from detector import PotholeDetector def test_singleton(): """Assert singleton prevents memory bloat by persisting strict memory addresses""" det1 = PotholeDetector.get_instance("yolov8n.pt") det2 = PotholeDetector.get_instance("yolov8n.pt") assert det1 is det2, "Singleton instantiation routing failed structurally." print("test_singleton passed.") def test_inference_shape_and_bgr(): """Assert dictionary structures natively mapping BGR and asserting BGR performs distinct from RGB natively.""" det = PotholeDetector.get_instance("yolov8n.pt") url = "https://ultralytics.com/images/zidane.jpg" req = urllib.request.urlopen(url) arr = np.asarray(bytearray(req.read()), dtype=np.uint8) img_bgr = cv2.imdecode(arr, -1) # BGR natively read img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB) # Process dynamically natively evaluating constraints natively results_bgr = det.predict(img_bgr, conf_thresh=0.25) results_rgb = det.predict(img_rgb, conf_thresh=0.25) assert isinstance(results_bgr, list), "Output casting payload failed structurally natively." if len(results_bgr) > 0: keys = list(results_bgr[0].keys()) assert 'xyxy' in keys and 'confidence' in keys and 'class_id' in keys, "Dictionary boundary keys mismatch." conf_bgr = results_bgr[0]['confidence'] if results_bgr else 0.0 conf_rgb = results_rgb[0]['confidence'] if results_rgb else 0.0 # Assuming BGR provides exact precision vs RGB variant physically evaluating bounds natively assert conf_bgr != conf_rgb, "Color space translation did not structurally impact physical YOLO tensor bindings (BGR vs RGB)." print("test_inference_shape_and_bgr passed.") if __name__ == "__main__": test_singleton() test_inference_shape_and_bgr() print("ALL DETECTOR TESTS PASSED")