needs tests/harness lib/psrs mem/timetbl testbegin : #bucket ( a "..." -- ) BUCKETCNT 2* 0 do @+ n< #eq loop drop ; \test create a single bucket table and hit it once 1 newtimetbl const mytbl 0 mytbl to TimeTable.ts \ it's easier for testing to have a zero reference. 0 1 mytbl hitbucketat \ hit at 1s 0 mytbl bucket #bucket 1 1 1 1 1 1 0 0 0 0 0 0 \test second hit in the same minute 0 32 mytbl hitbucketat \ hit at 32s 0 mytbl bucket #bucket 2 2 2 2 2 2 0 0 0 0 0 0 \test 3rd hit rolls over 0 60 mytbl hitbucketat 0 mytbl bucket #bucket 1 3 3 3 3 3 2 0 0 0 0 0 \test two rollovers at once 0 181 mytbl hitbucketat 0 mytbl bucket #bucket 1 4 4 4 4 4 0 0 0 0 0 0 \test 10 minutes rollover 0 602 mytbl hitbucketat 0 mytbl bucket #bucket 1 1 5 5 5 5 0 4 0 0 0 0 \test a no-roll hit there just to be sure 0 622 mytbl hitbucketat 0 mytbl bucket #bucket 2 2 6 6 6 6 0 4 0 0 0 0 \test hour rollover 0 60 60 * 4+ mytbl hitbucketat 0 mytbl bucket #bucket 1 1 1 7 7 7 0 0 6 0 0 0 \test day rollover 0 1440 60 * 8+ mytbl hitbucketat 0 mytbl bucket #bucket 1 1 1 1 8 8 0 0 0 7 0 0 \test week rollover 0 10080 60 * mytbl hitbucketat 0 mytbl bucket #bucket 1 1 1 1 1 9 0 0 0 0 8 0 \test now let's try with multiple buckets and values 3 newtimetbl const mytbl 0 mytbl to TimeTable.ts \test a few hits on a few buckets n"VAL1" 1 mytbl hitat \ VAL1 = idx0 n"VAL2" 2 mytbl hitat \ VAL2 = idx1 n"VAL1" 3 mytbl hitat n"VAL1" mytbl valbucket #bucket 2 2 2 2 2 2 0 0 0 0 0 0 n"VAL2" mytbl valbucket #bucket 1 1 1 1 1 1 0 0 0 0 0 0 \test rollover happens on all buckets at once n"VAL2" 57 mytbl hitat n"VAL2" 58 mytbl hitat n"VAL2" 59 mytbl hitat n"VAL1" 60 mytbl hitat n"VAL1" mytbl valbucket #bucket 1 3 3 3 3 3 2 0 0 0 0 0 n"VAL2" mytbl valbucket #bucket 0 4 4 4 4 4 4 0 0 0 0 0 \test sorttbl create expected map< , 0 2 3 0 4 1 5 mytbl sorttbl 6 expected 6 #[]= create expected map< , 0 1 0 2 1 0 0 mytbl sorttbl 6 expected 6 #[]= \test value replacement when table is full n"VAL3" 61 mytbl hitat \ last slot taken n"VAL3" mytbl validx #true 2 #eq n"VAL4" 62 mytbl hitat \ replace VAL3 n"VAL3" mytbl validx not #true n"VAL4" mytbl valbucket #bucket 1 1 1 1 1 1 0 0 0 0 0 0 n"VAL3" 63 mytbl hitat \ replace VAL4 n"VAL4" mytbl validx not #true n"VAL3" mytbl valbucket #bucket 1 1 1 1 1 1 0 0 0 0 0 0 \test prorate 20 30 60 prorate 10 #eq 20 10 60 prorate 3 #eq 20 10 60 retrorate 16 #eq \test progress n"VAL1" 2821 mytbl hitat \ 47 minutes 1 mytbl progress 10 #eq 7 #eq 2 mytbl progress 60 #eq 47 #eq \test .timetbl \ no assert, just print the thing 4 mytbl to fmtvalwidth create buf 4 allot :> buf be! buf 4 ; mytbl to fmtval -1 mytbl .timetbl 2 mytbl .timetbl testend