/
nv-lang
/
nova
Обзор
Документация
Войти
/
nv-lang
/
nova
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
std/src/collections/vec/restructure_test.nv
86 строк
2 KB
Evgeniy Golovin
195: std/ -> std/src/ (git mv, module-path без изменений)
13 июл 2026, 01:13
13 июл 2026, 01:13
be4fcab
Код
Авторство
О чём код?
// SPDX-License-Identifier: MIT OR Apache-2.0 // std.collections.vec (restructure tests) — concat/flatten/rotate/drain/insert_slice. #prelude(core, runtime, collections, protocols) module collections.vec test "concat / operator + does not mutate operands" { ro a = Vec[int].of(1, 2, 3) ro b = Vec[int].of(4, 5) ro c = a.concat(b) assert(c.equal(Vec[int].of(1, 2, 3, 4, 5))) assert(a.len() == 3) assert(b.len() == 2) ro d = a + b assert(d.equal(Vec[int].of(1, 2, 3, 4, 5))) assert(a.len() == 3) assert(b.len() == 2) } test "operator += appends" { mut a = Vec[int].of(1, 2) a += Vec[int].of(3, 4) assert(a.equal(Vec[int].of(1, 2, 3, 4))) } test "flatten concatenates inner vecs" { mut nested = Vec[Vec[int]].new() nested.push(Vec[int].of(1, 2)) nested.push(Vec[int].of(3)) nested.push(Vec[int].of(4, 5)) ro flat = nested.flatten() assert(flat.equal(Vec[int].of(1, 2, 3, 4, 5))) // operands untouched (flatten copies, never moves) assert(nested.len() == 3) // empty inner rows contribute nothing mut holes = Vec[Vec[int]].new() holes.push(Vec[int].of(7)) holes.push(Vec[int].new()) holes.push(Vec[int].of(8, 9)) assert(holes.flatten().equal(Vec[int].of(7, 8, 9))) // empty outer → empty mut none = Vec[Vec[int]].new() assert(none.flatten().len() == 0) } test "rotate_left / rotate_right" { mut v = Vec[int].of(1, 2, 3, 4, 5) v.rotate_left(2) assert(v.equal(Vec[int].of(3, 4, 5, 1, 2))) v.rotate_right(2) assert(v.equal(Vec[int].of(1, 2, 3, 4, 5))) // n % len == 0 is identity mut w = Vec[int].of(1, 2, 3) w.rotate_left(3) assert(w.equal(Vec[int].of(1, 2, 3))) w.rotate_left(6) assert(w.equal(Vec[int].of(1, 2, 3))) } test "drain returns cut + shortens receiver" { mut v = Vec[int].of(1, 2, 3, 4, 5) ro cut = v.drain(1..4) assert(cut.equal(Vec[int].of(2, 3, 4))) assert(v.equal(Vec[int].of(1, 5))) // empty range drains nothing mut u = Vec[int].of(7, 8, 9) ro none = u.drain(1..1) assert(none.len() == 0) assert(u.equal(Vec[int].of(7, 8, 9))) } test "insert_slice" { mut v = Vec[int].of(1, 2, 5, 6) v.insert_slice(2, Vec[int].of(3, 4)) assert(v.equal(Vec[int].of(1, 2, 3, 4, 5, 6))) // insert at end == append mut w = Vec[int].of(1, 2) w.insert_slice(2, Vec[int].of(3, 4)) assert(w.equal(Vec[int].of(1, 2, 3, 4))) }