test: Remove all remaining non-procedure uses of do.

This commit is contained in:
Patrick Walton 2013-11-21 19:20:48 -08:00
parent f571e46ddb
commit 38efa17bb8
34 changed files with 385 additions and 392 deletions

View file

@ -29,66 +29,65 @@ fn timed(label: &str, f: ||) {
fn ascending<M: MutableMap<uint, uint>>(map: &mut M, n_keys: uint) {
println(" Ascending integers:");
do timed("insert") {
timed("insert", || {
for i in range(0u, n_keys) {
map.insert(i, i + 1);
}
}
});
do timed("search") {
timed("search", || {
for i in range(0u, n_keys) {
assert_eq!(map.find(&i).unwrap(), &(i + 1));
}
}
});
do timed("remove") {
timed("remove", || {
for i in range(0, n_keys) {
assert!(map.remove(&i));
}
}
});
}
fn descending<M: MutableMap<uint, uint>>(map: &mut M, n_keys: uint) {
println(" Descending integers:");
do timed("insert") {
timed("insert", || {
for i in range(0, n_keys).invert() {
map.insert(i, i + 1);
}
}
});
do timed("search") {
timed("search", || {
for i in range(0, n_keys).invert() {
assert_eq!(map.find(&i).unwrap(), &(i + 1));
}
}
});
do timed("remove") {
timed("remove", || {
for i in range(0, n_keys) {
assert!(map.remove(&i));
}
}
});
}
fn vector<M: MutableMap<uint, uint>>(map: &mut M, n_keys: uint, dist: &[uint]) {
do timed("insert") {
timed("insert", || {
for i in range(0u, n_keys) {
map.insert(dist[i], i + 1);
}
}
});
do timed("search") {
timed("search", || {
for i in range(0u, n_keys) {
assert_eq!(map.find(&dist[i]).unwrap(), &(i + 1));
}
}
});
do timed("remove") {
timed("remove", || {
for i in range(0u, n_keys) {
assert!(map.remove(&dist[i]));
}
}
});
}
fn main() {

View file

@ -43,7 +43,7 @@ impl Results {
rand_cap: uint,
f: || -> T) { {
let mut set = f();
do timed(&mut self.sequential_ints) {
timed(&mut self.sequential_ints, || {
for i in range(0u, num_keys) {
set.insert(i);
}
@ -51,16 +51,16 @@ impl Results {
for i in range(0u, num_keys) {
assert!(set.contains(&i));
}
}
})
}
{
let mut set = f();
do timed(&mut self.random_ints) {
timed(&mut self.random_ints, || {
for _ in range(0, num_keys) {
set.insert(rng.gen::<uint>() % rand_cap);
}
}
})
}
{
@ -69,11 +69,11 @@ impl Results {
set.insert(i);
}
do timed(&mut self.delete_ints) {
timed(&mut self.delete_ints, || {
for i in range(0u, num_keys) {
assert!(set.remove(&i));
}
}
})
}
}
@ -85,7 +85,7 @@ impl Results {
f: || -> T) {
{
let mut set = f();
do timed(&mut self.sequential_strings) {
timed(&mut self.sequential_strings, || {
for i in range(0u, num_keys) {
set.insert(i.to_str());
}
@ -93,17 +93,17 @@ impl Results {
for i in range(0u, num_keys) {
assert!(set.contains(&i.to_str()));
}
}
})
}
{
let mut set = f();
do timed(&mut self.random_strings) {
timed(&mut self.random_strings, || {
for _ in range(0, num_keys) {
let s = rng.gen::<uint>().to_str();
set.insert(s);
}
}
})
}
{
@ -111,11 +111,11 @@ impl Results {
for i in range(0u, num_keys) {
set.insert(i.to_str());
}
do timed(&mut self.delete_strings) {
timed(&mut self.delete_strings, || {
for i in range(0u, num_keys) {
assert!(set.remove(&i.to_str()));
}
}
})
}
}
}

View file

@ -29,20 +29,20 @@ type pipe = arc::MutexArc<~[uint]>;
fn send(p: &pipe, msg: uint) {
unsafe {
do p.access_cond |state, cond| {
p.access_cond(|state, cond| {
state.push(msg);
cond.signal();
}
})
}
}
fn recv(p: &pipe) -> uint {
unsafe {
do p.access_cond |state, cond| {
p.access_cond(|state, cond| {
while state.is_empty() {
cond.wait();
}
state.pop()
}
})
}
}

View file

@ -28,18 +28,18 @@ use std::uint;
type pipe = arc::RWArc<~[uint]>;
fn send(p: &pipe, msg: uint) {
do p.write_cond |state, cond| {
p.write_cond(|state, cond| {
state.push(msg);
cond.signal();
}
})
}
fn recv(p: &pipe) -> uint {
do p.write_cond |state, cond| {
p.write_cond(|state, cond| {
while state.is_empty() {
cond.wait();
}
state.pop()
}
})
}
fn init() -> (pipe,pipe) {

View file

@ -37,26 +37,25 @@ fn ping_pong_bench(n: uint, m: uint) {
do spawntask_later() || {
let chan = ca.take();
let port = pb.take();
do n.times {
n.times(|| {
chan.send(());
port.recv();
}
})
}
do spawntask_later() || {
let chan = cb.take();
let port = pa.take();
do n.times {
n.times(|| {
port.recv();
chan.send(());
}
})
}
}
do m.times {
m.times(|| {
run_pair(n)
}
})
}

View file

@ -26,8 +26,8 @@ fn main() {
100000
};
do n.times {
n.times(|| {
do spawn || {};
}
})
}

View file

@ -28,11 +28,11 @@ fn item_check(t: &Tree) -> int {
fn bottom_up_tree<'r>(arena: &'r Arena, item: int, depth: int) -> &'r Tree<'r> {
if depth > 0 {
do arena.alloc {
arena.alloc(|| {
Node(bottom_up_tree(arena, 2 * item - 1, depth - 1),
bottom_up_tree(arena, 2 * item, depth - 1),
item)
}
})
} else {arena.alloc(|| Nil)}
}

View file

@ -169,7 +169,7 @@ fn main() {
let sizes = ~[1u,2,3,4,6,12,18];
let mut streams = vec::from_fn(sizes.len(), |_| Some(stream::<~str>()));
let mut from_child = ~[];
let to_child = do sizes.iter().zip(streams.mut_iter()).map |(sz, stream_ref)| {
let to_child = sizes.iter().zip(streams.mut_iter()).map(|(sz, stream_ref)| {
let sz = *sz;
let stream = util::replace(stream_ref, None);
let (from_child_, to_parent_) = stream.unwrap();
@ -183,7 +183,7 @@ fn main() {
}
to_child
}.collect::<~[Chan<~[u8]>]>();
}).collect::<~[Chan<~[u8]>]>();
// latch stores true after we've started

View file

@ -18,7 +18,7 @@ fn iterate<'a, T>(x: T, f: 'a |&T| -> T) -> Iterate<'a, T> {
Iterate {f: f, next: x}
}
struct Iterate<'self, T> {
priv f: &'self |&T| -> T,
priv f: 'self |&T| -> T,
priv next: T
}
impl<'self, T> Iterator<T> for Iterate<'self, T> {

View file

@ -51,9 +51,9 @@ impl Sudoku {
}
pub fn from_vec(vec: &[[u8, ..9], ..9]) -> Sudoku {
let g = do vec::from_fn(9u) |i| {
do vec::from_fn(9u) |j| { vec[i][j] }
};
let g = vec::from_fn(9u, |i| {
vec::from_fn(9u, |j| { vec[i][j] })
});
return Sudoku::new(g)
}

View file

@ -19,13 +19,13 @@ use std::vec;
fn calc(children: uint, parent_wait_chan: &Chan<Chan<Chan<int>>>) {
let wait_ports: ~[Port<Chan<Chan<int>>>] = do vec::from_fn(children) |_| {
let wait_ports: ~[Port<Chan<Chan<int>>>] = vec::from_fn(children, |_| {
let (wait_port, wait_chan) = stream::<Chan<Chan<int>>>();
do task::spawn {
calc(children / 2, &wait_chan);
}
wait_port
};
});
let child_start_chans: ~[Chan<Chan<int>>] =
wait_ports.move_iter().map(|port| port.recv()).collect();
@ -35,11 +35,11 @@ fn calc(children: uint, parent_wait_chan: &Chan<Chan<Chan<int>>>) {
let parent_result_chan: Chan<int> = start_port.recv();
let child_sum_ports: ~[Port<int>] =
do child_start_chans.move_iter().map |child_start_chan| {
child_start_chans.move_iter().map(|child_start_chan| {
let (child_sum_port, child_sum_chan) = stream::<int>();
child_start_chan.send(child_sum_chan);
child_sum_port
}.collect();
}).collect();
let sum = child_sum_ports.move_iter().fold(0, |sum, sum_port| sum + sum_port.recv() );