2012-12-03 16:48:01 -08:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2011-07-08 02:16:46 -07:00
|
|
|
use std;
|
2012-09-05 11:38:37 -07:00
|
|
|
use vec;
|
2011-07-08 02:16:46 -07:00
|
|
|
|
2013-03-01 16:02:22 -08:00
|
|
|
fn vec_equal<T>(v: ~[T],
|
|
|
|
u: ~[T],
|
|
|
|
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);
|
2012-08-01 17:30:05 -07:00
|
|
|
if Lv != vec::len(u) { return false; }
|
2011-07-27 14:19:39 +02:00
|
|
|
let i = 0u;
|
|
|
|
while i < Lv {
|
2012-08-01 17:30:05 -07:00
|
|
|
if !element_equality_test(v[i], u[i]) { return false; }
|
2011-07-08 02:16:46 -07:00
|
|
|
i += 1u;
|
|
|
|
}
|
2012-08-01 17:30:05 -07:00
|
|
|
return true;
|
2011-07-08 02:16:46 -07:00
|
|
|
}
|
|
|
|
|
2012-08-01 17:30:05 -07:00
|
|
|
pure fn builtin_equal<T>(&&a: T, &&b: T) -> bool { return a == b; }
|
|
|
|
pure fn builtin_equal_int(&&a: int, &&b: int) -> bool { return 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-08-22 17:24:52 -07:00
|
|
|
error!("Pass");
|
2011-08-04 16:20:53 -07:00
|
|
|
}
|