2010-10-21 11:39:53 -07:00
|
|
|
use std;
|
2011-05-17 20:41:41 +02:00
|
|
|
import std::vec;
|
2011-05-12 17:24:54 +02:00
|
|
|
import std::bitv;
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
fn test_0_elements() {
|
|
|
|
auto act;
|
|
|
|
auto exp;
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
act = bitv::create(0u, false);
|
2011-05-17 20:41:41 +02:00
|
|
|
exp = vec::init_elt[uint](0u, 0u);
|
2010-10-21 11:39:53 -07:00
|
|
|
// FIXME: why can't I write vec[uint]()?
|
2011-05-12 17:24:54 +02:00
|
|
|
assert (bitv::eq_vec(act, exp));
|
2010-10-21 11:39:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_1_element() {
|
|
|
|
auto act;
|
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
act = bitv::create(1u, false);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [0u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
2011-05-12 17:24:54 +02:00
|
|
|
act = bitv::create(1u, true);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [1u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
}
|
|
|
|
|
2011-04-19 13:35:49 -07:00
|
|
|
fn test_10_elements() {
|
2010-10-21 11:39:53 -07:00
|
|
|
auto act;
|
|
|
|
|
|
|
|
// all 0
|
2011-05-12 17:24:54 +02:00
|
|
|
act = bitv::create(10u, false);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// all 1
|
2011-05-12 17:24:54 +02:00
|
|
|
act = bitv::create(10u, true);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// mixed
|
2011-05-12 17:24:54 +02:00
|
|
|
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);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [1u, 1u, 1u, 1u, 1u, 0u, 0u, 0u, 0u, 0u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// mixed
|
2011-05-12 17:24:54 +02:00
|
|
|
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);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [0u, 0u, 0u, 0u, 0u, 1u, 1u, 1u, 1u, 1u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// mixed
|
2011-05-12 17:24:54 +02:00
|
|
|
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);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [1u, 0u, 0u, 1u, 0u, 0u, 1u, 0u, 0u, 1u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
}
|
|
|
|
|
2011-04-19 13:35:49 -07:00
|
|
|
fn test_31_elements() {
|
2010-10-21 11:39:53 -07:00
|
|
|
auto act;
|
|
|
|
|
|
|
|
// all 0
|
2011-05-12 17:24:54 +02:00
|
|
|
act = bitv::create(31u, false);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2010-10-21 11:39:53 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2011-05-16 18:21:22 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// all 1
|
2011-05-12 17:24:54 +02:00
|
|
|
act = bitv::create(31u, true);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
2010-10-21 11:39:53 -07:00
|
|
|
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
|
|
|
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
2011-05-16 18:21:22 -07:00
|
|
|
1u, 1u, 1u, 1u, 1u, 1u, 1u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// mixed
|
2011-05-12 17:24:54 +02:00
|
|
|
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);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
2010-10-21 11:39:53 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2011-05-16 18:21:22 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// mixed
|
2011-05-12 17:24:54 +02:00
|
|
|
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);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2010-10-21 11:39:53 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
2011-05-16 18:21:22 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// mixed
|
2011-05-12 17:24:54 +02:00
|
|
|
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);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2010-10-21 11:39:53 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2011-05-16 18:21:22 -07:00
|
|
|
1u, 1u, 1u, 1u, 1u, 1u, 1u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// mixed
|
2011-05-12 17:24:54 +02:00
|
|
|
act = bitv::create(31u, false);
|
|
|
|
bitv::set(act, 3u, true);
|
|
|
|
bitv::set(act, 17u, true);
|
|
|
|
bitv::set(act, 30u, true);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u,
|
2010-10-21 11:39:53 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2011-05-16 18:21:22 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 1u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
}
|
|
|
|
|
2011-04-19 13:35:49 -07:00
|
|
|
fn test_32_elements() {
|
2010-10-21 11:39:53 -07:00
|
|
|
auto act;
|
|
|
|
|
|
|
|
// all 0
|
2011-05-12 17:24:54 +02:00
|
|
|
act = bitv::create(32u, false);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2010-10-21 11:39:53 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2011-05-16 18:21:22 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// all 1
|
2011-05-12 17:24:54 +02:00
|
|
|
act = bitv::create(32u, true);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
2010-10-21 11:39:53 -07:00
|
|
|
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
|
|
|
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
2011-05-16 18:21:22 -07:00
|
|
|
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// mixed
|
2011-05-12 17:24:54 +02:00
|
|
|
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);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
2010-10-21 11:39:53 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2011-05-16 18:21:22 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// mixed
|
2011-05-12 17:24:54 +02:00
|
|
|
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);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2010-10-21 11:39:53 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
2011-05-16 18:21:22 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// mixed
|
2011-05-12 17:24:54 +02:00
|
|
|
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);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2010-10-21 11:39:53 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2011-05-16 18:21:22 -07:00
|
|
|
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// mixed
|
2011-05-12 17:24:54 +02:00
|
|
|
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);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u,
|
2010-10-21 11:39:53 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2011-05-16 18:21:22 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
}
|
|
|
|
|
2011-04-19 13:35:49 -07:00
|
|
|
fn test_33_elements() {
|
2010-10-21 11:39:53 -07:00
|
|
|
auto act;
|
|
|
|
|
|
|
|
// all 0
|
2011-05-12 17:24:54 +02:00
|
|
|
act = bitv::create(33u, false);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2010-10-21 11:39:53 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2011-05-16 18:21:22 -07:00
|
|
|
0u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// all 1
|
2011-05-12 17:24:54 +02:00
|
|
|
act = bitv::create(33u, true);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
2010-10-21 11:39:53 -07:00
|
|
|
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
|
|
|
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
|
|
|
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
2011-05-16 18:21:22 -07:00
|
|
|
1u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// mixed
|
2011-05-12 17:24:54 +02:00
|
|
|
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);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
2010-10-21 11:39:53 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2011-05-16 18:21:22 -07:00
|
|
|
0u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// mixed
|
2011-05-12 17:24:54 +02:00
|
|
|
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);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2010-10-21 11:39:53 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2011-05-16 18:21:22 -07:00
|
|
|
0u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// mixed
|
2011-05-12 17:24:54 +02:00
|
|
|
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);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
2010-10-21 11:39:53 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
|
2011-05-16 18:21:22 -07:00
|
|
|
0u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
|
|
|
|
// mixed
|
2011-05-12 17:24:54 +02:00
|
|
|
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);
|
2011-05-16 18:21:22 -07:00
|
|
|
assert (bitv::eq_vec(act, [0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u,
|
2010-10-21 11:39:53 -07:00
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u,
|
|
|
|
0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u,
|
2011-05-16 18:21:22 -07:00
|
|
|
1u]));
|
2010-10-21 11:39:53 -07:00
|
|
|
}
|
|
|
|
|
2011-04-19 13:35:49 -07:00
|
|
|
fn main() {
|
2010-10-21 11:39:53 -07:00
|
|
|
test_0_elements();
|
|
|
|
test_1_element();
|
|
|
|
test_10_elements();
|
|
|
|
test_31_elements();
|
|
|
|
test_32_elements();
|
|
|
|
test_33_elements();
|
|
|
|
}
|