// Test tensor read-write consistency at scale
fn main() {
    let mut t = t_zeros(256)

    // Write values
    let mut i = 0
    while i < 256 {
        t = t_index_set(t, i, i + 0.0)
        i = i + 1
    }

    // Read them all back
    let mut errors = 0
    let mut j = 0
    while j < 256 {
        let v = t_index_get(t, j)
        if v != j + 0.0 {
            if errors < 5 {
                println("FAIL at " + int_to_str(j) + ": got " + float_to_str(v))
            }
            errors = errors + 1
        }
        j = j + 1
    }
    if errors == 0 {
        println("Tensor read/write: 256/256 OK")
    } else {
        println("Tensor read/write: " + int_to_str(errors) + " failures")
    }

    // Test: write A to pos 2, read pos 0 — does it get overwritten?
    let mut t2 = t_zeros(8)
    t2 = t_index_set(t2, 0, 100.0)
    t2 = t_index_set(t2, 2, 200.0)
    println("t2[0] = " + float_to_str(t_index_get(t2, 0)) + " (should be 100)")
    println("t2[2] = " + float_to_str(t_index_get(t2, 2)) + " (should be 200)")
}
