2010-07-11 16:08:46 -05:00
|
|
|
use std;
|
|
|
|
|
|
|
|
fn test_init_elt() {
|
2010-07-26 17:20:13 -05:00
|
|
|
let vec[uint] v = std._vec.init_elt[uint](5 as uint, 3 as uint);
|
|
|
|
check (std._vec.len[uint](v) == (3 as uint));
|
|
|
|
check (v.(0) == (5 as uint));
|
|
|
|
check (v.(1) == (5 as uint));
|
|
|
|
check (v.(2) == (5 as uint));
|
2010-07-11 16:08:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn id(uint x) -> uint {
|
|
|
|
ret x;
|
|
|
|
}
|
|
|
|
fn test_init_fn() {
|
|
|
|
let fn(uint)->uint op = id;
|
2010-07-26 17:20:13 -05:00
|
|
|
let vec[uint] v = std._vec.init_fn[uint](op, (5 as uint));
|
|
|
|
check (std._vec.len[uint](v) == (5 as uint));
|
|
|
|
check (v.(0) == (0 as uint));
|
|
|
|
check (v.(1) == (1 as uint));
|
|
|
|
check (v.(2) == (2 as uint));
|
|
|
|
check (v.(3) == (3 as uint));
|
|
|
|
check (v.(4) == (4 as uint));
|
2010-07-11 16:08:46 -05:00
|
|
|
}
|
|
|
|
|
2010-07-11 16:51:02 -05:00
|
|
|
fn test_slice() {
|
|
|
|
let vec[int] v = vec(1,2,3,4,5);
|
|
|
|
auto v2 = std._vec.slice[int](v, 2, 4);
|
2010-07-26 17:20:13 -05:00
|
|
|
check (std._vec.len[int](v2) == (2 as uint));
|
2010-07-11 16:51:02 -05:00
|
|
|
check (v2.(0) == 3);
|
|
|
|
check (v2.(1) == 4);
|
|
|
|
}
|
|
|
|
|
2010-07-11 16:08:46 -05:00
|
|
|
fn main() {
|
|
|
|
test_init_elt();
|
|
|
|
//XFAIL: test_init_fn(); // Segfaults.
|
2010-07-11 16:51:02 -05:00
|
|
|
test_slice();
|
|
|
|
}
|