2011-07-08 02:16:46 -07:00
|
|
|
use std;
|
2011-12-13 16:25:51 -08:00
|
|
|
import vec;
|
2011-07-08 02:16:46 -07:00
|
|
|
|
2012-06-29 16:26:56 -07:00
|
|
|
fn vec_equal<T>(v: ~[T], u: ~[T],
|
2012-04-13 11:59:17 -07:00
|
|
|
element_equality_test: fn@(&&T, &&T) -> bool) ->
|
2011-09-12 11:27:30 +02:00
|
|
|
bool {
|
2011-08-15 16:38:23 -07:00
|
|
|
let Lv = vec::len(v);
|
|
|
|
if Lv != vec::len(u) { ret false; }
|
2011-07-27 14:19:39 +02:00
|
|
|
let i = 0u;
|
|
|
|
while i < Lv {
|
2011-08-19 15:16:48 -07:00
|
|
|
if !element_equality_test(v[i], u[i]) { ret false; }
|
2011-07-08 02:16:46 -07:00
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
ret true;
|
|
|
|
}
|
|
|
|
|
2012-01-06 22:06:32 -08:00
|
|
|
pure fn builtin_equal<T>(&&a: T, &&b: T) -> bool { ret a == b; }
|
|
|
|
pure fn builtin_equal_int(&&a: int, &&b: int) -> bool { ret a == b; }
|
2011-07-08 02:16:46 -07:00
|
|
|
|
|
|
|
fn main() {
|
2011-07-27 14:19:39 +02:00
|
|
|
assert (builtin_equal(5, 5));
|
|
|
|
assert (!builtin_equal(5, 4));
|
2012-06-29 16:26:56 -07:00
|
|
|
assert (!vec_equal(~[5, 5], ~[5], bind builtin_equal(_, _)));
|
|
|
|
assert (!vec_equal(~[5, 5], ~[5], builtin_equal_int));
|
|
|
|
assert (!vec_equal(~[5, 5], ~[5, 4], builtin_equal_int));
|
|
|
|
assert (!vec_equal(~[5, 5], ~[4, 5], builtin_equal_int));
|
|
|
|
assert (vec_equal(~[5, 5], ~[5, 5], builtin_equal_int));
|
2011-07-08 02:16:46 -07:00
|
|
|
|
2012-07-30 16:01:07 -07:00
|
|
|
error!{"Pass"};
|
2011-08-04 16:20:53 -07:00
|
|
|
}
|