2011-06-15 14:46:30 -05:00
|
|
|
// xfail-stage0
|
|
|
|
|
|
|
|
use std;
|
|
|
|
import std::either::*;
|
2011-07-12 17:09:44 -05:00
|
|
|
import std::ivec::len;
|
2011-06-15 14:46:30 -05:00
|
|
|
|
|
|
|
fn test_either_left() {
|
|
|
|
auto val = left(10);
|
|
|
|
fn f_left(&int x) -> bool { x == 10 }
|
|
|
|
fn f_right(&uint x) -> bool { false }
|
|
|
|
assert (either(f_left, f_right, val));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_either_right() {
|
|
|
|
auto val = right(10u);
|
|
|
|
fn f_left(&int x) -> bool { false }
|
|
|
|
fn f_right(&uint x) -> bool { x == 10u }
|
|
|
|
assert (either(f_left, f_right, val));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_lefts() {
|
2011-07-12 17:09:44 -05:00
|
|
|
auto input = ~[left(10),
|
|
|
|
right(11),
|
|
|
|
left(12),
|
|
|
|
right(13),
|
|
|
|
left(14)];
|
2011-06-15 14:46:30 -05:00
|
|
|
auto result = lefts(input);
|
2011-07-12 17:09:44 -05:00
|
|
|
assert (result == ~[10, 12, 14]);
|
2011-06-15 14:46:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_lefts_none() {
|
2011-07-12 17:09:44 -05:00
|
|
|
let (t[int, int])[] input = ~[right(10),
|
2011-06-15 14:46:30 -05:00
|
|
|
right(10)];
|
|
|
|
auto result = lefts(input);
|
|
|
|
assert (len(result) == 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_lefts_empty() {
|
2011-07-12 17:09:44 -05:00
|
|
|
let (t[int, int])[] input = ~[];
|
2011-06-15 14:46:30 -05:00
|
|
|
auto result = lefts(input);
|
|
|
|
assert (len(result) == 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_rights() {
|
2011-07-12 17:09:44 -05:00
|
|
|
auto input = ~[left(10),
|
|
|
|
right(11),
|
|
|
|
left(12),
|
|
|
|
right(13),
|
|
|
|
left(14)];
|
2011-06-15 14:46:30 -05:00
|
|
|
auto result = rights(input);
|
2011-07-12 17:09:44 -05:00
|
|
|
assert (result == ~[11, 13]);
|
2011-06-15 14:46:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_rights_none() {
|
2011-07-12 17:09:44 -05:00
|
|
|
let (t[int, int])[] input = ~[left(10),
|
2011-06-15 14:46:30 -05:00
|
|
|
left(10)];
|
|
|
|
auto result = rights(input);
|
|
|
|
assert (len(result) == 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_rights_empty() {
|
2011-07-12 17:09:44 -05:00
|
|
|
let (t[int, int])[] input = ~[];
|
2011-06-15 14:46:30 -05:00
|
|
|
auto result = rights(input);
|
|
|
|
assert (len(result) == 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_partition() {
|
2011-07-12 17:09:44 -05:00
|
|
|
auto input = ~[left(10),
|
|
|
|
right(11),
|
|
|
|
left(12),
|
|
|
|
right(13),
|
|
|
|
left(14)];
|
2011-06-15 14:46:30 -05:00
|
|
|
auto result = partition(input);
|
|
|
|
assert (result._0.(0) == 10);
|
|
|
|
assert (result._0.(1) == 12);
|
|
|
|
assert (result._0.(2) == 14);
|
|
|
|
assert (result._1.(0) == 11);
|
|
|
|
assert (result._1.(1) == 13);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_partition_no_lefts() {
|
2011-07-12 17:09:44 -05:00
|
|
|
let (t[int, int])[] input = ~[right(10),
|
2011-06-15 14:46:30 -05:00
|
|
|
right(11)];
|
|
|
|
auto result = partition(input);
|
|
|
|
assert (len(result._0) == 0u);
|
|
|
|
assert (len(result._1) == 2u);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_partition_no_rights() {
|
2011-07-12 17:09:44 -05:00
|
|
|
let (t[int, int])[] input = ~[left(10),
|
2011-06-15 14:46:30 -05:00
|
|
|
left(11)];
|
|
|
|
auto result = partition(input);
|
|
|
|
assert (len(result._0) == 2u);
|
|
|
|
assert (len(result._1) == 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_partition_empty() {
|
2011-07-12 17:09:44 -05:00
|
|
|
let (t[int, int])[] input = ~[];
|
2011-06-15 14:46:30 -05:00
|
|
|
auto result = partition(input);
|
|
|
|
assert (len(result._0) == 0u);
|
|
|
|
assert (len(result._1) == 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
test_either_left();
|
|
|
|
test_either_right();
|
|
|
|
test_lefts();
|
|
|
|
test_lefts_none();
|
|
|
|
test_lefts_empty();
|
|
|
|
test_rights();
|
|
|
|
test_rights_none();
|
|
|
|
test_rights_empty();
|
|
|
|
test_partition();
|
|
|
|
test_partition_no_lefts();
|
|
|
|
test_partition_no_rights();
|
|
|
|
test_partition_empty();
|
2011-07-12 17:09:44 -05:00
|
|
|
}
|