// Test Z_3329 field arithmetic for Kyber-768
use crypto::fieldq

fn main() {
    println("=== Z_3329 Field Arithmetic Test ===")
    let result = fq_self_test()
    if result == 0 {
        println("ALL TESTS PASSED")
    } else {
        println("FAILED at test " + int_to_str(result))
    }

    // Additional: verify Montgomery round-trip with several values
    println("")
    println("Montgomery round-trips:")
    let mut i = 0
    while i < 10 {
        let x = i * 337
        let m = fq_to_mont(x)
        let back = fq_from_mont(m)
        let ok = ""
        if back == x { ok = "OK" } else { ok = "FAIL" }
        println("  " + int_to_str(x) + " -> mont " + int_to_str(m) + " -> " + int_to_str(back) + " " + ok)
        i = i + 1
    }

    // Verify Barrett matches modulo for a range
    println("")
    println("Barrett vs modulo:")
    let mut j = 0
    let mut pass = 0
    while j < 20 {
        let x = j * 500 + 3000
        let b = fq_barrett(x)
        let m = x % fq_q()
        if b == m { pass = pass + 1 }
        j = j + 1
    }
    println("  " + int_to_str(pass) + "/20 Barrett matches (should be 20)")

    // Verify zeta is a primitive 256th root of unity
    println("")
    let z256 = fq_pow(fq_zeta_base(), 256)
    let z128 = fq_pow(fq_zeta_base(), 128)
    println("zeta^256 mod q = " + int_to_str(z256) + " (should be 1)")
    println("zeta^128 mod q = " + int_to_str(z128) + " (should be " + int_to_str(fq_q() - 1) + ")")
}
