use crypto::kpke
use crypto::fieldq

fn main() {
    // Test 1: Does tensor_slice work?
    let mut t = t_zeros(10)
    let mut i = 0
    while i < 10 {
        t = t_index_set(t, i, (i + 1) * 10.0)
        i = i + 1
    }
    let s = tensor_slice(t, 3, 7)
    println("tensor_slice test: " + float_to_str(t_index_get(s, 0)) + " " + float_to_str(t_index_get(s, 1)) + " " + float_to_str(t_index_get(s, 2)) + " " + float_to_str(t_index_get(s, 3)))
    println("Expected: 40 50 60 70")

    // Test 2: Does poly_encode12 -> poly_decode12 round-trip?
    println("")
    let mut poly = t_zeros(256)
    poly = t_index_set(poly, 0, 100.0)
    poly = t_index_set(poly, 1, 2000.0)
    poly = t_index_set(poly, 2, 3328.0)
    poly = t_index_set(poly, 255, 1234.0)
    let encoded = poly_encode12(poly)
    println("encode12 size: " + int_to_str(tensor_len(encoded)) + " (expect 384)")
    let decoded = poly_decode12(encoded)
    println("decode12[0]=" + float_to_str(t_index_get(decoded, 0)) + " (expect 100)")
    println("decode12[1]=" + float_to_str(t_index_get(decoded, 1)) + " (expect 2000)")
    println("decode12[2]=" + float_to_str(t_index_get(decoded, 2)) + " (expect 3328)")
    println("decode12[255]=" + float_to_str(t_index_get(decoded, 255)) + " (expect 1234)")

    // Test 3: compress -> decompress round-trip
    println("")
    println("compress/decompress (du=10):")
    let mut j = 0
    while j < 5 {
        let x = j * 800
        let c = compress(x, 10)
        let d = decompress(c, 10)
        println("  " + int_to_str(x) + " -> " + int_to_str(c) + " -> " + int_to_str(d))
        j = j + 1
    }

    println("")
    println("compress/decompress (dv=4, message bit):")
    println("  0 -> " + int_to_str(compress(0, 1)) + " -> " + int_to_str(decompress(compress(0, 1), 1)))
    println("  1665 -> " + int_to_str(compress(1665, 1)) + " -> " + int_to_str(decompress(compress(1665, 1), 1)))
}
