summaryrefslogtreecommitdiff
path: root/chapter31/src/test/java/com/seaofnodes
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-11-13 13:10:15 -0800
committerCliff Click <cliffc@acm.org>2026-11-13 13:10:15 -0800
commit299addd03094389bb622e0fe1d7ad585b51e146d (patch)
treefde1f3d0d440665428786c8bc35bd9d037034e2c /chapter31/src/test/java/com/seaofnodes
parentb7440c1e4c182ad977996d91bfb8125091ffae92 (diff)
downloadSimple-299addd03094389bb622e0fe1d7ad585b51e146d.tar.gz
Simple-299addd03094389bb622e0fe1d7ad585b51e146d.zip
Cleanp the new time & graphics APIs
Diffstat (limited to 'chapter31/src/test/java/com/seaofnodes')
-rw-r--r--chapter31/src/test/java/com/seaofnodes/simple/DrawTest.java22
-rw-r--r--chapter31/src/test/java/com/seaofnodes/simple/TimeTest.java33
2 files changed, 35 insertions, 20 deletions
diff --git a/chapter31/src/test/java/com/seaofnodes/simple/DrawTest.java b/chapter31/src/test/java/com/seaofnodes/simple/DrawTest.java
index 72e2cd9d..1ca161cf 100644
--- a/chapter31/src/test/java/com/seaofnodes/simple/DrawTest.java
+++ b/chapter31/src/test/java/com/seaofnodes/simple/DrawTest.java
@@ -15,7 +15,7 @@ public class DrawTest {
.replace("val main =","val _windowMain =");
StringBuilder source=new StringBuilder(clock+"""
val _check_noInline={ f64 turn, int expectedX, int expectedY ->
- int x=360+_sin_noInline(turn)*128, y=232-_sin_noInline(turn+0.25)*128;
+ int x=360+_sin(turn)*128, y=232-_sin(turn+0.25)*128;
if( x<expectedX-1 || x>expectedX+1 || y<expectedY-1 || y>expectedY+1 ) {
sys.io.p("turn %f(turn): %(x),%(y) expected %(expectedX),%(expectedY)\\n");
return 1;
@@ -48,7 +48,7 @@ public class DrawTest {
StringBuilder source=new StringBuilder(clock+"""
val _renderCheck_noInline={ int second, int millisecond, int expectedX, int expectedY ->
val c=new sys.draw.Canvas(720,540);
- _analog_noInline(c,3,20,second,millisecond);
+ _analog(c,3,20,second,millisecond);
var found=false;
for( int y=expectedY-2; y<=expectedY+2; y++ )
for( int x=expectedX-2; x<=expectedX+2; x++ )
@@ -106,15 +106,15 @@ public class DrawTest {
CodeGen code=new CodeGen(null,null,new Ary<>(new String[]{TestC.RELEASE_SYS_DIR}),"ClockRaster",clock+"""
val main={ ->
val c=new sys.draw.Canvas(720,540);
- _digit_noInline(c,10,10,8);
+ _digit(c,10,10,8);
if( c.pixels[10*720+40]!=GREEN || c.pixels[82*720+40]!=GREEN || c.pixels[154*720+40]!=GREEN ) return 1;
- _digit_noInline(c,10,10,1);
+ _digit(c,10,10,1);
if( c.pixels[10*720+40]!=DIM || c.pixels[40*720+78]!=GREEN || c.pixels[40*720+14]!=DIM ) return 2;
- c.clear(BACKGROUND); _digital_noInline(c,23,59,58);
+ c.clear(BACKGROUND); _digital(c,23,59,58);
if( c.pixels[214*720+254]!=GREEN || c.pixels[262*720+470]!=GREEN ) return 3;
- c.clear(BACKGROUND); _analog_noInline(c,3,0,0,0);
+ c.clear(BACKGROUND); _analog(c,3,0,0,0);
if( c.pixels[232*720+430]!=GREEN || c.pixels[160*720+360]!=0xc3ffcb || c.pixels[232*720+360]!=GREEN ) return 4;
- if( _sin_noInline(0.25)<0.999 || _sin_noInline(0.75)>-0.999 || _sin_noInline(1.0)!=0.0 ) return 5;
+ if( _sin(0.25)<0.999 || _sin(0.75)>-0.999 || _sin(1.0)!=0.0 ) return 5;
return 0;
};
return main();
@@ -174,6 +174,14 @@ public class DrawTest {
for( int y=0; y<5; y++ )
for( int x=0; x<3; x++ )
if( c.pixels[y*16+x]!=c.pixels[y*16+x+8] ) return 6;
+ c.clear(0).text(0,0,":/",2,6);
+ for( int y=0; y<10; y++ )
+ for( int x=0; x<16; x++ ) {
+ int row=y/2, col=x/2;
+ var colon=col==1 && (row==1 || row==3);
+ var slash=(row<2 && col==6) || (row==2 && col==5) || (row>2 && col==4);
+ if( c.pixels[y*16+x]!=((colon || slash) ? 6 : 0) ) return 9;
+ }
c.clear(0).fillCircle(-1,-1,2,7);
if( c.pixels[0]!=7 || c.pixels[2]!=0 ) return 7;
return 0;
diff --git a/chapter31/src/test/java/com/seaofnodes/simple/TimeTest.java b/chapter31/src/test/java/com/seaofnodes/simple/TimeTest.java
index c3cdc6cf..dfffc1b9 100644
--- a/chapter31/src/test/java/com/seaofnodes/simple/TimeTest.java
+++ b/chapter31/src/test/java/com/seaofnodes/simple/TimeTest.java
@@ -88,20 +88,27 @@ public class TimeTest extends TestC {
@Test public void timerOrderingAndMissedTicks() throws Exception {
checks("""
val q=new sys.time.Timers();
- if( q.poll(0)!=-1 || q.nextDeadline()!=-1 ) return 1;
- i64 a=q.afterAt(100,20), b=q.afterAt(100,10), c=q.afterAt(100,10);
- if( q.nextDeadline()!=110 || q.poll(109)!=-1 || q.poll(110)!=b || q.poll(110)!=c || q.poll(110)!=-1 ) return 2;
- if( !q.cancel(a) || q.cancel(a) || q.cancel(-1) || q.nextDeadline()!=-1 ) return 3;
- i64 repeat=q.everyAt(100,10);
- if( q.poll(135)!=repeat || q.nextDeadline()!=140 || q.poll(135)!=-1 ) return 4;
+ if( q.poll(0)!=0 || q.nextDeadline()!=-1 ) return 1;
+ u32 a=q.afterAt(100,20), b=q.afterAt(100,10), c=q.afterAt(100,10);
+ if( a==0 || b==0 || c==0 ) return 10;
+ if( q.nextDeadline()!=110 || q.poll(109)!=0 || q.poll(110)!=b || q.poll(110)!=c || q.poll(110)!=0 ) return 2;
+ if( !q.cancel(a) || q.cancel(a) || q.cancel(0) || q.nextDeadline()!=-1 ) return 3;
+ u32 repeat=q.everyAt(100,10);
+ if( q.poll(135)!=repeat || q.nextDeadline()!=140 || q.poll(135)!=0 ) return 4;
if( q.poll(140)!=repeat || q.nextDeadline()!=150 || !q.cancel(repeat) ) return 5;
- for( int i=0; i<20; i++ ) if( q.afterAt(200,i)<0 ) return 11;
- i64 prev=-1;
- for( int i=0; i<20; i++ ) { i64 id=q.poll(300); if( id<=prev ) return 6; prev=id; }
- if( q.nextDeadline()!=-1 || q.poll(1000)!=-1 ) return 7;
- if( q.afterAt(-1,1)!=-1 || q.afterAt(0,-1)!=-1 || q.everyAt(0,0)!=-1 || q.afterAt(9223372036854775807,1)!=-1 ) return 8;
- i64 last=q.everyAt(9223372036854775806,1);
- if( last<0 || q.poll(9223372036854775807)!=last || q.nextDeadline()!=-1 ) return 9;
+ for( int i=0; i<20; i++ ) if( q.afterAt(200,i)==0 ) return 11;
+ u32 prev=0;
+ for( int i=0; i<20; i++ ) { u32 id=q.poll(300); if( id<=prev ) return 6; prev=id; }
+ if( q.nextDeadline()!=-1 || q.poll(1000)!=0 ) return 7;
+ if( q.afterAt(-1,1)!=0 || q.afterAt(0,-1)!=0 || q.everyAt(0,0)!=0 || q.afterAt(9223372036854775807,1)!=0 ) return 8;
+ u32 last=q.everyAt(9223372036854775806,1);
+ if( last==0 || q.poll(9223372036854775807)!=last || q.nextDeadline()!=-1 ) return 9;
+ // Exhaust IDs without wrapping or letting an old ID cancel a new timer.
+ q._next=0xfffffffe;
+ u32 high=q.afterAt(0,10), max=q.afterAt(0,10);
+ if( high!=0xfffffffe || max!=0xffffffff || q.afterAt(0,0)!=0 ) return 12;
+ if( q.cancel(a) || q.poll(10)!=high || q.poll(10)!=max || q.poll(10)!=0 ) return 13;
+ if( q.afterAt(0,0)!=0 || q.nextDeadline()!=-1 ) return 14;
""","timeTimers");
}