import XCTest
@testable import PoseCore

final class FeasibilityTests: XCTestCase {
    func testCropProjectionUsesTopLeftPixels() throws {
        let crop = PixelRect(x: 100, y: 20, width: 200, height: 100)
        XCTAssertEqual(crop.sourcePoint(normalizedX: 0.25, normalizedY: 0.8), Point2(x: 150, y: 40))
    }
    func testInvalidCropRejected() {
        XCTAssertThrowsError(try PixelRect(x: -1, y: 0, width: 10, height: 10).validate(imageWidth: 100, imageHeight: 100))
    }
    func testIncompleteCoverageCannotPass() {
        let result = Localization.evaluate(predicted: [:], annotations: [Landmark(name: "left_elbow", point: Point2(x: 20, y: 30), uncertaintyPixels: 1)], torsoLength: 40)
        XCTAssertEqual(result.assessedCount, 1)
        XCTAssertEqual(result.withinToleranceCount, 0)
        XCTAssertFalse(result.passes)
    }
    func testLocalizationPreservesPixelErrorAndUncertainty() {
        let result = Localization.evaluate(predicted: ["left_elbow": Point2(x: 24, y: 30)], annotations: [Landmark(name: "left_elbow", point: Point2(x: 20, y: 30), uncertaintyPixels: 1)], torsoLength: 40)
        XCTAssertEqual(result.errors.first?.pixels, 4)
        XCTAssertFalse(result.passes)
    }
    func testMalformedImageFailsWithoutFabricatingPose() {
        XCTAssertThrowsError(try ImageInput.load(url: URL(fileURLWithPath: "/nonexistent/image.png")))
    }
}
