rust/src/test/run-pass/lib-bitv.rs

299 lines
9.3 KiB
Rust
Raw Normal View History

2011-03-29 22:58:50 -07:00
// xfail-stage0
use std;
import std._vec;
import std.bitv;
fn test_0_elements() {
auto act;
auto exp;
act = bitv.create(0u, false);
exp = _vec.init_elt[uint](0u, 0u);
// FIXME: why can't I write vec[uint]()?
check (bitv.eq_vec(act, exp));
}
fn test_1_element() {
auto act;
act = bitv.create(1u, false);
check (bitv.eq_vec(act, vec(0u)));
act = bitv.create(1u, true);
check (bitv.eq_vec(act, vec(1u)));
}
impure fn test_10_elements() {
auto act;
// all 0
act = bitv.create(10u, false);
check (bitv.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u)));
// all 1
act = bitv.create(10u, true);
check (bitv.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u)));
// mixed
act = bitv.create(10u, false);
bitv.set(act, 0u, true);
bitv.set(act, 1u, true);
bitv.set(act, 2u, true);
bitv.set(act, 3u, true);
bitv.set(act, 4u, true);
check (bitv.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 0u, 0u, 0u, 0u, 0u)));
// mixed
act = bitv.create(10u, false);
bitv.set(act, 5u, true);
bitv.set(act, 6u, true);
bitv.set(act, 7u, true);
bitv.set(act, 8u, true);
bitv.set(act, 9u, true);
check (bitv.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 1u, 1u, 1u, 1u, 1u)));
// mixed
act = bitv.create(10u, false);
bitv.set(act, 0u, true);
bitv.set(act, 3u, true);
bitv.set(act, 6u, true);
bitv.set(act, 9u, true);
check (bitv.eq_vec(act, vec(1u, 0u, 0u, 1u, 0u, 0u, 1u, 0u, 0u, 1u)));
}
impure fn test_31_elements() {
auto act;
// all 0
act = bitv.create(31u, false);
check (bitv.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u)));
// all 1
act = bitv.create(31u, true);
check (bitv.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u)));
// mixed
act = bitv.create(31u, false);
bitv.set(act, 0u, true);
bitv.set(act, 1u, true);
bitv.set(act, 2u, true);
bitv.set(act, 3u, true);
bitv.set(act, 4u, true);
bitv.set(act, 5u, true);
bitv.set(act, 6u, true);
bitv.set(act, 7u, true);
check (bitv.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u)));
// mixed
act = bitv.create(31u, false);
bitv.set(act, 16u, true);
bitv.set(act, 17u, true);
bitv.set(act, 18u, true);
bitv.set(act, 19u, true);
bitv.set(act, 20u, true);
bitv.set(act, 21u, true);
bitv.set(act, 22u, true);
bitv.set(act, 23u, true);
check (bitv.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
0u, 0u, 0u, 0u, 0u, 0u, 0u)));
// mixed
act = bitv.create(31u, false);
bitv.set(act, 24u, true);
bitv.set(act, 25u, true);
bitv.set(act, 26u, true);
bitv.set(act, 27u, true);
bitv.set(act, 28u, true);
bitv.set(act, 29u, true);
bitv.set(act, 30u, true);
check (bitv.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
1u, 1u, 1u, 1u, 1u, 1u, 1u)));
// mixed
act = bitv.create(31u, false);
bitv.set(act, 3u, true);
bitv.set(act, 17u, true);
bitv.set(act, 30u, true);
check (bitv.eq_vec(act, vec(0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 1u)));
}
impure fn test_32_elements() {
auto act;
// all 0
act = bitv.create(32u, false);
check (bitv.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u)));
// all 1
act = bitv.create(32u, true);
check (bitv.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u)));
// mixed
act = bitv.create(32u, false);
bitv.set(act, 0u, true);
bitv.set(act, 1u, true);
bitv.set(act, 2u, true);
bitv.set(act, 3u, true);
bitv.set(act, 4u, true);
bitv.set(act, 5u, true);
bitv.set(act, 6u, true);
bitv.set(act, 7u, true);
check (bitv.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u)));
// mixed
act = bitv.create(32u, false);
bitv.set(act, 16u, true);
bitv.set(act, 17u, true);
bitv.set(act, 18u, true);
bitv.set(act, 19u, true);
bitv.set(act, 20u, true);
bitv.set(act, 21u, true);
bitv.set(act, 22u, true);
bitv.set(act, 23u, true);
check (bitv.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u)));
// mixed
act = bitv.create(32u, false);
bitv.set(act, 24u, true);
bitv.set(act, 25u, true);
bitv.set(act, 26u, true);
bitv.set(act, 27u, true);
bitv.set(act, 28u, true);
bitv.set(act, 29u, true);
bitv.set(act, 30u, true);
bitv.set(act, 31u, true);
check (bitv.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u)));
// mixed
act = bitv.create(32u, false);
bitv.set(act, 3u, true);
bitv.set(act, 17u, true);
bitv.set(act, 30u, true);
bitv.set(act, 31u, true);
check (bitv.eq_vec(act, vec(0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u)));
}
impure fn test_33_elements() {
auto act;
// all 0
act = bitv.create(33u, false);
check (bitv.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u)));
// all 1
act = bitv.create(33u, true);
check (bitv.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
1u)));
// mixed
act = bitv.create(33u, false);
bitv.set(act, 0u, true);
bitv.set(act, 1u, true);
bitv.set(act, 2u, true);
bitv.set(act, 3u, true);
bitv.set(act, 4u, true);
bitv.set(act, 5u, true);
bitv.set(act, 6u, true);
bitv.set(act, 7u, true);
check (bitv.eq_vec(act, vec(1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u)));
// mixed
act = bitv.create(33u, false);
bitv.set(act, 16u, true);
bitv.set(act, 17u, true);
bitv.set(act, 18u, true);
bitv.set(act, 19u, true);
bitv.set(act, 20u, true);
bitv.set(act, 21u, true);
bitv.set(act, 22u, true);
bitv.set(act, 23u, true);
check (bitv.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u)));
// mixed
act = bitv.create(33u, false);
bitv.set(act, 24u, true);
bitv.set(act, 25u, true);
bitv.set(act, 26u, true);
bitv.set(act, 27u, true);
bitv.set(act, 28u, true);
bitv.set(act, 29u, true);
bitv.set(act, 30u, true);
bitv.set(act, 31u, true);
check (bitv.eq_vec(act, vec(0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
0u)));
// mixed
act = bitv.create(33u, false);
bitv.set(act, 3u, true);
bitv.set(act, 17u, true);
bitv.set(act, 30u, true);
bitv.set(act, 31u, true);
bitv.set(act, 32u, true);
check (bitv.eq_vec(act, vec(0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u,
0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u,
1u)));
}
impure fn main() {
test_0_elements();
test_1_element();
test_10_elements();
test_31_elements();
test_32_elements();
test_33_elements();
}