2011-07-08 04:16:46 -05:00
|
|
|
use std;
|
2011-12-13 18:25:51 -06:00
|
|
|
import vec;
|
2011-07-08 04:16:46 -05:00
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn vec_equal<T>(v: [T], u: [T], element_equality_test: fn(T, T) -> bool) ->
|
|
|
|
bool {
|
2011-08-15 18:38:23 -05:00
|
|
|
let Lv = vec::len(v);
|
|
|
|
if Lv != vec::len(u) { ret false; }
|
2011-07-27 07:19:39 -05:00
|
|
|
let i = 0u;
|
|
|
|
while i < Lv {
|
2011-08-19 17:16:48 -05:00
|
|
|
if !element_equality_test(v[i], u[i]) { ret false; }
|
2011-07-08 04:16:46 -05:00
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
ret true;
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn builtin_equal<T>(a: T, b: T) -> bool { ret a == b; }
|
2011-07-08 04:16:46 -05:00
|
|
|
|
|
|
|
fn main() {
|
2011-07-27 07:19:39 -05:00
|
|
|
assert (builtin_equal(5, 5));
|
|
|
|
assert (!builtin_equal(5, 4));
|
2011-08-19 17:16:48 -05:00
|
|
|
assert (!vec_equal([5, 5], [5], builtin_equal));
|
|
|
|
assert (!vec_equal([5, 5], [5, 4], builtin_equal));
|
|
|
|
assert (!vec_equal([5, 5], [4, 5], builtin_equal));
|
|
|
|
assert (vec_equal([5, 5], [5, 5], builtin_equal));
|
2011-07-08 04:16:46 -05:00
|
|
|
|
2011-12-22 16:42:52 -06:00
|
|
|
#error("Pass");
|
2011-08-04 18:20:53 -05:00
|
|
|
}
|