//
//  EmbeddingServiceTests.swift
//  oAITests
//
// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
// Copyright (C) 2026 Rune Olsen

import Testing
@testable import Confab

@Suite("EmbeddingService serialization")
struct EmbeddingServiceTests {

    @Test("Serialize then deserialize round-trips an embedding exactly")
    func roundTrip() {
        let original: [Float] = [0.0, 1.0, -1.0, 3.14159, -0.0001, 1_000_000.5]
        let data = EmbeddingService.shared.serializeEmbedding(original)
        let restored = EmbeddingService.shared.deserializeEmbedding(data)
        #expect(restored == original)
    }

    @Test("Serialized data is exactly 4 bytes per float")
    func serializedSizeIsFourBytesPerFloat() {
        let embedding: [Float] = Array(repeating: 0.5, count: 10)
        let data = EmbeddingService.shared.serializeEmbedding(embedding)
        #expect(data.count == 40)
    }

    @Test("Empty embedding serializes to empty data and back")
    func emptyEmbedding() {
        let data = EmbeddingService.shared.serializeEmbedding([])
        #expect(data.isEmpty)
        #expect(EmbeddingService.shared.deserializeEmbedding(data).isEmpty)
    }
}
