rust/src/fuzzer/ast_match.rs

28 lines
713 B
Rust
Raw Normal View History

2011-07-08 04:16:46 -05:00
use std;
2011-08-15 18:38:23 -05:00
import std::vec;
2011-07-08 04:16:46 -05:00
2011-08-18 16:32:25 -05:00
fn vec_equal<T>(v: &[T], u: &[T], element_equality_test: fn(&T, &T) -> bool )
2011-07-27 07:19:39 -05:00
-> 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 {
if !element_equality_test(v.(i), u.(i)) { ret false; }
2011-07-08 04:16:46 -05:00
i += 1u;
}
ret true;
}
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-18 16:32:25 -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
log_err "Pass";
}