bittorrent: fix check-bitfield, add a test.

master
John Benediktsson 2020-01-28 16:25:19 -08:00
parent 6aa8f640c8
commit 2300311641
2 changed files with 7 additions and 2 deletions

View File

@ -1,4 +1,9 @@
USING: bittorrent io.sockets tools.test ; USING: bittorrent sequences io.sockets tools.test ;
{ { t f t t f t f t } } [
8 <iota> [ B{ 0b10110101 } check-bitfield ] map
] unit-test
{ {
{ {

View File

@ -40,7 +40,7 @@ torrent-port [ 6881 ] initialize
'[ _ _ [ set-bit ] [ clear-bit ] if ] change-nth ; '[ _ _ [ set-bit ] [ clear-bit ] if ] change-nth ;
: check-bitfield ( n bitfield -- ? ) : check-bitfield ( n bitfield -- ? )
[ bitfield-index swap ] dip nth bit? ; [ bitfield-index swap ] dip nth swap bit? ;
! http ! http