Write some tests for swap.

This commit is contained in:
Michael Sullivan 2011-06-15 17:08:10 -07:00 committed by Graydon Hoare
parent 272c7e2e87
commit a9d62e5a90
3 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,7 @@
// error-pattern:Unsatisfied precondition
fn main() {
auto x = 3;
auto y;
x <-> y;
}

View File

@ -0,0 +1,7 @@
fn main() {
auto x = 3;
auto y = 7;
x <-> y;
assert (x == 7);
assert (y == 3);
}

View File

@ -0,0 +1,14 @@
fn swap[T](&vec[mutable T] v, int i, int j) {
v.(i) <-> v.(j);
}
fn main() {
let vec[mutable int] a = [mutable 0,1,2,3,4,5,6];
swap(a, 2, 4);
assert(a.(2) == 4);
assert(a.(4) == 2);
auto n = 42;
n <-> a.(0);
assert(a.(0) == 42);
assert(n == 0);
}