rust/src/fuzzer/ast_match.rs

28 lines
721 B
Rust
Raw Normal View History

2011-07-08 04:16:46 -05:00
use std;
import std::ivec;
fn ivec_equal[T](v: &[T], u: &[T], element_equality_test: fn(&T, &T) -> bool )
2011-07-27 07:19:39 -05:00
-> bool {
let Lv = ivec::len(v);
if Lv != ivec::len(u) { ret false; }
let i = 0u;
while i < Lv {
if !element_equality_test(v.(i), u.(i)) { ret false; }
2011-07-08 04:16:46 -05:00
i += 1u;
}
ret true;
}
2011-07-27 07:19:39 -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));
assert (!ivec_equal(~[5, 5], ~[5], builtin_equal));
assert (!ivec_equal(~[5, 5], ~[5, 4], builtin_equal));
assert (!ivec_equal(~[5, 5], ~[4, 5], builtin_equal));
assert (ivec_equal(~[5, 5], ~[5, 5], builtin_equal));
2011-07-08 04:16:46 -05:00
log_err "Pass";
}