2018-08-30 00:57:22 +03:00
|
|
|
/+ *test
|
2018-08-28 01:25:33 +03:00
|
|
|
::
|
|
|
|
=, contain
|
|
|
|
::
|
2018-08-30 00:57:22 +03:00
|
|
|
|%
|
2018-08-28 01:25:33 +03:00
|
|
|
++ test-basic-capped-queue
|
|
|
|
::
|
|
|
|
=| q=(capped-queue @u)
|
|
|
|
=. max-size.q 3
|
|
|
|
:: specialize type
|
|
|
|
::
|
|
|
|
=+ to-capped-queue=(to-capped-queue @u)
|
|
|
|
:: push a single element
|
|
|
|
::
|
|
|
|
=^ maybe1 q (~(put to-capped-queue q) 5)
|
|
|
|
::
|
|
|
|
=/ results1
|
2018-08-29 21:09:37 +03:00
|
|
|
%+ expect-eq
|
2018-08-29 02:16:37 +03:00
|
|
|
!> ~
|
|
|
|
!> maybe1
|
2018-08-28 01:25:33 +03:00
|
|
|
=/ results2
|
2018-08-29 21:09:37 +03:00
|
|
|
%+ expect-eq
|
2018-08-29 02:16:37 +03:00
|
|
|
!> 1
|
|
|
|
!> size.q
|
2018-08-28 01:25:33 +03:00
|
|
|
=/ results3
|
2018-08-29 21:09:37 +03:00
|
|
|
%+ expect-eq
|
2018-08-29 02:16:37 +03:00
|
|
|
!> [~ 5]
|
|
|
|
!> ~(top to queue.q)
|
2018-08-28 01:25:33 +03:00
|
|
|
:: remove the single element
|
|
|
|
::
|
|
|
|
=^ maybe2 q ~(get to-capped-queue q)
|
|
|
|
::
|
|
|
|
=/ results4
|
2018-08-29 21:09:37 +03:00
|
|
|
%+ expect-eq
|
2018-08-29 02:16:37 +03:00
|
|
|
!> 5
|
|
|
|
!> maybe2
|
2018-08-28 01:25:33 +03:00
|
|
|
=/ results5
|
2018-08-29 21:09:37 +03:00
|
|
|
%+ expect-eq
|
2018-08-29 02:16:37 +03:00
|
|
|
!> 0
|
|
|
|
!> size.q
|
2018-08-28 01:25:33 +03:00
|
|
|
::
|
|
|
|
;: weld
|
|
|
|
results1
|
|
|
|
results2
|
|
|
|
results3
|
|
|
|
results4
|
|
|
|
results5
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ test-put-returns-evicted-value
|
|
|
|
::
|
|
|
|
=| q=(capped-queue @u)
|
|
|
|
=. max-size.q 2
|
|
|
|
:: specialize type
|
|
|
|
::
|
|
|
|
=+ to-capped-queue=(to-capped-queue @u)
|
|
|
|
:: push enough values to evict one
|
|
|
|
::
|
|
|
|
=^ maybe1 q (~(put to-capped-queue q) 5)
|
|
|
|
=/ results1
|
2018-08-29 21:09:37 +03:00
|
|
|
%+ expect-eq
|
2018-08-29 02:16:37 +03:00
|
|
|
!> ~
|
|
|
|
!> maybe1
|
2018-08-28 01:25:33 +03:00
|
|
|
=/ results2
|
2018-08-29 21:09:37 +03:00
|
|
|
%+ expect-eq
|
2018-08-29 02:16:37 +03:00
|
|
|
!> 1
|
|
|
|
!> size.q
|
2018-08-28 01:25:33 +03:00
|
|
|
::
|
|
|
|
=^ maybe2 q (~(put to-capped-queue q) 6)
|
|
|
|
=/ results3
|
2018-08-29 21:09:37 +03:00
|
|
|
%+ expect-eq
|
2018-08-29 02:16:37 +03:00
|
|
|
!> ~
|
|
|
|
!> maybe2
|
2018-08-28 01:25:33 +03:00
|
|
|
=/ results4
|
2018-08-29 21:09:37 +03:00
|
|
|
%+ expect-eq
|
2018-08-29 02:16:37 +03:00
|
|
|
!> 2
|
|
|
|
!> size.q
|
2018-08-28 01:25:33 +03:00
|
|
|
::
|
|
|
|
=^ maybe3 q (~(put to-capped-queue q) 7)
|
|
|
|
=/ results5
|
2018-08-29 21:09:37 +03:00
|
|
|
%+ expect-eq
|
2018-08-29 02:16:37 +03:00
|
|
|
!> [~ 5]
|
|
|
|
!> maybe3
|
2018-08-28 01:25:33 +03:00
|
|
|
=/ results6
|
2018-08-29 21:09:37 +03:00
|
|
|
%+ expect-eq
|
2018-08-29 02:16:37 +03:00
|
|
|
!> 2
|
|
|
|
!> size.q
|
2018-08-28 01:25:33 +03:00
|
|
|
::
|
|
|
|
;: weld
|
|
|
|
results1
|
|
|
|
results2
|
|
|
|
results3
|
|
|
|
results4
|
|
|
|
results5
|
|
|
|
results6
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ test-resize-evicts-on-shrink
|
|
|
|
::
|
|
|
|
=| q=(capped-queue @u)
|
|
|
|
=. max-size.q 5
|
|
|
|
:: specialize type
|
|
|
|
::
|
|
|
|
=+ to-capped-queue=(to-capped-queue @u)
|
|
|
|
::
|
|
|
|
=^ maybe1 q (~(put to-capped-queue q) 1)
|
|
|
|
=^ maybe2 q (~(put to-capped-queue q) 2)
|
|
|
|
=^ maybe3 q (~(put to-capped-queue q) 3)
|
|
|
|
=^ maybe4 q (~(put to-capped-queue q) 4)
|
|
|
|
=^ maybe5 q (~(put to-capped-queue q) 5)
|
|
|
|
:: resize the size to 3; this should pop two items
|
|
|
|
::
|
|
|
|
=^ pops q (~(resize to-capped-queue q) 3)
|
|
|
|
::
|
|
|
|
=/ results1
|
2018-08-29 21:09:37 +03:00
|
|
|
%+ expect-eq
|
2018-08-29 02:16:37 +03:00
|
|
|
!> [1 2 ~]
|
|
|
|
!> pops
|
2018-08-28 01:25:33 +03:00
|
|
|
=/ results2
|
2018-08-29 21:09:37 +03:00
|
|
|
%+ expect-eq
|
2018-08-29 02:16:37 +03:00
|
|
|
!> 3
|
|
|
|
!> size.q
|
2018-08-28 01:25:33 +03:00
|
|
|
::
|
|
|
|
;: weld
|
|
|
|
results1
|
|
|
|
results2
|
|
|
|
==
|
|
|
|
--
|