// // PupilDetectorTests.swift // GazeTests // // Created by Mike Freno on 1/16/26. // import CoreVideo import Vision import XCTest @testable import Gaze final class PupilDetectorTests: XCTestCase { override func setUp() async throws { // Reset the detector state PupilDetector.cleanup() } func testCreateCGImageFromData() throws { // Test basic image creation let width = 50 let height = 50 var pixels = [UInt8](repeating: 128, count: width * height) // Add some dark pixels for a "pupil" for y in 20..<30 { for x in 20..<30 { pixels[y * width + x] = 10 // Very dark } } // Save test image to verify let pixelData = Data(pixels) guard let provider = CGDataProvider(data: pixelData as CFData) else { XCTFail("Failed to create CGDataProvider") return } let cgImage = CGImage( width: width, height: height, bitsPerComponent: 8, bitsPerPixel: 8, bytesPerRow: width, space: CGColorSpaceCreateDeviceGray(), bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.none.rawValue), provider: provider, decode: nil, shouldInterpolate: false, intent: .defaultIntent ) XCTAssertNotNil(cgImage, "Should create CGImage from pixel data") } func testImageProcessingWithDarkPixels() throws { // Test that imageProcessingOptimized produces dark pixels let width = 60 let height = 40 // Create input with a dark circle (simulating pupil) var input = [UInt8](repeating: 200, count: width * height) // Light background (like eye white) // Add a dark ellipse in center (pupil) let centerX = width / 2 let centerY = height / 2 for y in 0..