move Continuations and Coroutines tests to top-level test directory

This commit is contained in:
Joel Dice 2009-05-18 09:17:49 -06:00
parent e35047b056
commit db91c27441
2 changed files with 42 additions and 30 deletions

View File

@ -1,5 +1,3 @@
package extra;
import static avian.Continuations.callWithCurrentContinuation;
import avian.CallbackReceiver;

View File

@ -1,5 +1,3 @@
package extra;
import static avian.Continuations.callWithCurrentContinuation;
import avian.CallbackReceiver;
@ -11,15 +9,28 @@ public class Coroutines {
}
private static void produce(Consumer<Character> consumer) throws Exception {
System.out.println("produce \"a\"");
consumer.consume('a');
System.out.println("produce \"b\"");
consumer.consume('b');
System.out.println("produce \"c\"");
consumer.consume('c');
}
private static void consume(Producer<Character> producer) throws Exception {
expect(producer.produce() == 'a');
expect(producer.produce() == 'b');
expect(producer.produce() == 'c');
char v = producer.produce();
System.out.println("consume \"" + v + "\"");
expect(v == 'a');
v = producer.produce();
System.out.println("consume \"" + v + "\"");
expect(v == 'b');
v = producer.produce();
System.out.println("consume \"" + v + "\"");
expect(v == 'c');
}
public static void main(String[] args) throws Exception {
@ -40,8 +51,8 @@ public class Coroutines {
};
final Producer<Character> producer = new Producer<Character>() {
public Character produce() throws Exception {
return callWithCurrentContinuation(new CallbackReceiver<Character>() {
final CallbackReceiver<Character> receiver
= new CallbackReceiver<Character>() {
public Character receive(Callback<Character> continuation)
throws Exception
{
@ -55,7 +66,10 @@ public class Coroutines {
throw new AssertionError();
}
});
};
public Character produce() throws Exception {
return callWithCurrentContinuation(receiver);
}
};