From 2300311641778ae8f48d8e0b89c6bd7eff63ea36 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Tue, 28 Jan 2020 16:25:19 -0800 Subject: [PATCH] bittorrent: fix check-bitfield, add a test. --- extra/bittorrent/bittorrent-tests.factor | 7 ++++++- extra/bittorrent/bittorrent.factor | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/extra/bittorrent/bittorrent-tests.factor b/extra/bittorrent/bittorrent-tests.factor index 1c2e9585c6c..64079f7fbf0 100644 --- a/extra/bittorrent/bittorrent-tests.factor +++ b/extra/bittorrent/bittorrent-tests.factor @@ -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 [ B{ 0b10110101 } check-bitfield ] map +] unit-test { { diff --git a/extra/bittorrent/bittorrent.factor b/extra/bittorrent/bittorrent.factor index c831372b39f..d479e7338da 100644 --- a/extra/bittorrent/bittorrent.factor +++ b/extra/bittorrent/bittorrent.factor @@ -40,7 +40,7 @@ torrent-port [ 6881 ] initialize '[ _ _ [ set-bit ] [ clear-bit ] if ] change-nth ; : check-bitfield ( n bitfield -- ? ) - [ bitfield-index swap ] dip nth bit? ; + [ bitfield-index swap ] dip nth swap bit? ; ! http