Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Bitwise module tests #165

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

scoreboard players set $bitwise.bit_count bs.out 0
scoreboard players operation #bitwise.bit_count bs.data = $bitwise.bit_count.n bs.in
execute if score #bitwise.bit_count bs.data matches ..-1 run scoreboard players add $bitwise.bit_count bs.out 1
execute if score #bitwise.bit_count bs.data matches ..-1 run scoreboard players operation #bitwise.bit_count bs.data *= -1 bs.const
scoreboard players operation #bitwise.bit_count bs.data *= 2 bs.const
execute if score #bitwise.bit_count bs.data matches ..-1 run scoreboard players add $bitwise.bit_count bs.out 1
scoreboard players operation #bitwise.bit_count bs.data *= 2 bs.const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

# CODE ------------------------------------------------------------------------

execute if score $bitwise.bit_length.n bs.in matches 0..127 run return run function bs.bitwise:bit_length/group_1
execute if score $bitwise.bit_length.n bs.in matches 128..32767 run return run function bs.bitwise:bit_length/group_2
execute if score $bitwise.bit_length.n bs.in matches 32768..8388607 run return run function bs.bitwise:bit_length/group_3
execute if score $bitwise.bit_length.n bs.in matches 8388608..2147483647 run return run function bs.bitwise:bit_length/group_4
execute if score $bitwise.bit_length.n bs.in matches ..-1 run return run scoreboard players set $bitwise.bit_length bs.out 32
scoreboard players operation #bitwise.bit_length bs.data = $bitwise.bit_length.n bs.in
execute if score #bitwise.bit_length bs.data matches ..-1 run scoreboard players operation #bitwise.bit_length bs.data *= -1 bs.const
execute if score #bitwise.bit_length bs.data matches 0..127 run return run function bs.bitwise:bit_length/group_1
execute if score #bitwise.bit_length bs.data matches 128..32767 run return run function bs.bitwise:bit_length/group_2
execute if score #bitwise.bit_length bs.data matches 32768..8388607 run return run function bs.bitwise:bit_length/group_3
execute if score #bitwise.bit_length bs.data matches 8388608..2147483647 run return run function bs.bitwise:bit_length/group_4
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
execute if score $bitwise.bit_length.n bs.in matches 0 run return run scoreboard players set $bitwise.bit_length bs.out 0
execute if score $bitwise.bit_length.n bs.in matches 1 run return run scoreboard players set $bitwise.bit_length bs.out 1
execute if score $bitwise.bit_length.n bs.in matches 2..3 run return run scoreboard players set $bitwise.bit_length bs.out 2
execute if score $bitwise.bit_length.n bs.in matches 4..7 run return run scoreboard players set $bitwise.bit_length bs.out 3
execute if score $bitwise.bit_length.n bs.in matches 8..15 run return run scoreboard players set $bitwise.bit_length bs.out 4
execute if score $bitwise.bit_length.n bs.in matches 16..31 run return run scoreboard players set $bitwise.bit_length bs.out 5
execute if score $bitwise.bit_length.n bs.in matches 32..63 run return run scoreboard players set $bitwise.bit_length bs.out 6
execute if score $bitwise.bit_length.n bs.in matches 64..127 run return run scoreboard players set $bitwise.bit_length bs.out 7
execute if score #bitwise.bit_length bs.data matches 0 run return run scoreboard players set $bitwise.bit_length bs.out 0
execute if score #bitwise.bit_length bs.data matches 1 run return run scoreboard players set $bitwise.bit_length bs.out 1
execute if score #bitwise.bit_length bs.data matches 2..3 run return run scoreboard players set $bitwise.bit_length bs.out 2
execute if score #bitwise.bit_length bs.data matches 4..7 run return run scoreboard players set $bitwise.bit_length bs.out 3
execute if score #bitwise.bit_length bs.data matches 8..15 run return run scoreboard players set $bitwise.bit_length bs.out 4
execute if score #bitwise.bit_length bs.data matches 16..31 run return run scoreboard players set $bitwise.bit_length bs.out 5
execute if score #bitwise.bit_length bs.data matches 32..63 run return run scoreboard players set $bitwise.bit_length bs.out 6
execute if score #bitwise.bit_length bs.data matches 64..127 run return run scoreboard players set $bitwise.bit_length bs.out 7
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
execute if score $bitwise.bit_length.n bs.in matches 128..255 run return run scoreboard players set $bitwise.bit_length bs.out 8
execute if score $bitwise.bit_length.n bs.in matches 256..511 run return run scoreboard players set $bitwise.bit_length bs.out 9
execute if score $bitwise.bit_length.n bs.in matches 512..1023 run return run scoreboard players set $bitwise.bit_length bs.out 10
execute if score $bitwise.bit_length.n bs.in matches 1024..2047 run return run scoreboard players set $bitwise.bit_length bs.out 11
execute if score $bitwise.bit_length.n bs.in matches 2048..4095 run return run scoreboard players set $bitwise.bit_length bs.out 12
execute if score $bitwise.bit_length.n bs.in matches 4096..8191 run return run scoreboard players set $bitwise.bit_length bs.out 13
execute if score $bitwise.bit_length.n bs.in matches 8192..16383 run return run scoreboard players set $bitwise.bit_length bs.out 14
execute if score $bitwise.bit_length.n bs.in matches 16384..32767 run return run scoreboard players set $bitwise.bit_length bs.out 15
execute if score #bitwise.bit_length bs.data matches 128..255 run return run scoreboard players set $bitwise.bit_length bs.out 8
execute if score #bitwise.bit_length bs.data matches 256..511 run return run scoreboard players set $bitwise.bit_length bs.out 9
execute if score #bitwise.bit_length bs.data matches 512..1023 run return run scoreboard players set $bitwise.bit_length bs.out 10
execute if score #bitwise.bit_length bs.data matches 1024..2047 run return run scoreboard players set $bitwise.bit_length bs.out 11
execute if score #bitwise.bit_length bs.data matches 2048..4095 run return run scoreboard players set $bitwise.bit_length bs.out 12
execute if score #bitwise.bit_length bs.data matches 4096..8191 run return run scoreboard players set $bitwise.bit_length bs.out 13
execute if score #bitwise.bit_length bs.data matches 8192..16383 run return run scoreboard players set $bitwise.bit_length bs.out 14
execute if score #bitwise.bit_length bs.data matches 16384..32767 run return run scoreboard players set $bitwise.bit_length bs.out 15
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
execute if score $bitwise.bit_length.n bs.in matches 32768..65535 run return run scoreboard players set $bitwise.bit_length bs.out 16
execute if score $bitwise.bit_length.n bs.in matches 65536..131071 run return run scoreboard players set $bitwise.bit_length bs.out 17
execute if score $bitwise.bit_length.n bs.in matches 131072..262143 run return run scoreboard players set $bitwise.bit_length bs.out 18
execute if score $bitwise.bit_length.n bs.in matches 262144..524287 run return run scoreboard players set $bitwise.bit_length bs.out 19
execute if score $bitwise.bit_length.n bs.in matches 524288..1048575 run return run scoreboard players set $bitwise.bit_length bs.out 20
execute if score $bitwise.bit_length.n bs.in matches 1048576..2097151 run return run scoreboard players set $bitwise.bit_length bs.out 21
execute if score $bitwise.bit_length.n bs.in matches 2097152..4194303 run return run scoreboard players set $bitwise.bit_length bs.out 22
execute if score $bitwise.bit_length.n bs.in matches 4194304..8388607 run return run scoreboard players set $bitwise.bit_length bs.out 23
execute if score #bitwise.bit_length bs.data matches 32768..65535 run return run scoreboard players set $bitwise.bit_length bs.out 16
execute if score #bitwise.bit_length bs.data matches 65536..131071 run return run scoreboard players set $bitwise.bit_length bs.out 17
execute if score #bitwise.bit_length bs.data matches 131072..262143 run return run scoreboard players set $bitwise.bit_length bs.out 18
execute if score #bitwise.bit_length bs.data matches 262144..524287 run return run scoreboard players set $bitwise.bit_length bs.out 19
execute if score #bitwise.bit_length bs.data matches 524288..1048575 run return run scoreboard players set $bitwise.bit_length bs.out 20
execute if score #bitwise.bit_length bs.data matches 1048576..2097151 run return run scoreboard players set $bitwise.bit_length bs.out 21
execute if score #bitwise.bit_length bs.data matches 2097152..4194303 run return run scoreboard players set $bitwise.bit_length bs.out 22
execute if score #bitwise.bit_length bs.data matches 4194304..8388607 run return run scoreboard players set $bitwise.bit_length bs.out 23
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
execute if score $bitwise.bit_length.n bs.in matches 8388608..16777215 run return run scoreboard players set $bitwise.bit_length bs.out 24
execute if score $bitwise.bit_length.n bs.in matches 16777216..33554431 run return run scoreboard players set $bitwise.bit_length bs.out 25
execute if score $bitwise.bit_length.n bs.in matches 33554432..67108863 run return run scoreboard players set $bitwise.bit_length bs.out 26
execute if score $bitwise.bit_length.n bs.in matches 67108864..134217727 run return run scoreboard players set $bitwise.bit_length bs.out 27
execute if score $bitwise.bit_length.n bs.in matches 134217728..268435455 run return run scoreboard players set $bitwise.bit_length bs.out 28
execute if score $bitwise.bit_length.n bs.in matches 268435456..536870911 run return run scoreboard players set $bitwise.bit_length bs.out 29
execute if score $bitwise.bit_length.n bs.in matches 536870912..1073741823 run return run scoreboard players set $bitwise.bit_length bs.out 30
execute if score $bitwise.bit_length.n bs.in matches 1073741824.. run return run scoreboard players set $bitwise.bit_length bs.out 31
execute if score #bitwise.bit_length bs.data matches 8388608..16777215 run return run scoreboard players set $bitwise.bit_length bs.out 24
execute if score #bitwise.bit_length bs.data matches 16777216..33554431 run return run scoreboard players set $bitwise.bit_length bs.out 25
execute if score #bitwise.bit_length bs.data matches 33554432..67108863 run return run scoreboard players set $bitwise.bit_length bs.out 26
execute if score #bitwise.bit_length bs.data matches 67108864..134217727 run return run scoreboard players set $bitwise.bit_length bs.out 27
execute if score #bitwise.bit_length bs.data matches 134217728..268435455 run return run scoreboard players set $bitwise.bit_length bs.out 28
execute if score #bitwise.bit_length bs.data matches 268435456..536870911 run return run scoreboard players set $bitwise.bit_length bs.out 29
execute if score #bitwise.bit_length bs.data matches 536870912..1073741823 run return run scoreboard players set $bitwise.bit_length bs.out 30
execute if score #bitwise.bit_length bs.data matches 1073741824.. run return run scoreboard players set $bitwise.bit_length bs.out 31

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

27 changes: 0 additions & 27 deletions datapacks/Bookshelf/data/bs.bitwise/functions/msb/msb.mcfunction

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# CODE ------------------------------------------------------------------------

scoreboard players operation $bitwise.not bs.out = $bitwise.not.value bs.in
scoreboard players operation $bitwise.not bs.out = $bitwise.not.n bs.in
scoreboard players operation $bitwise.not bs.out *= -1 bs.const

return run scoreboard players remove $bitwise.not bs.out 1
5 changes: 0 additions & 5 deletions datapacks/Bookshelf/data/bs.bitwise/tags/functions/msb.json

This file was deleted.

12 changes: 12 additions & 0 deletions datapacks/Bookshelf/data/bs.bitwise/tests/and.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# And operator returns correct values
# @batch bs.bitwise

scoreboard players set $bitwise.and.a bs.in -9
scoreboard players set $bitwise.and.b bs.in 57
function #bs.bitwise:and
assert score $bitwise.and bs.out matches 49

scoreboard players set $bitwise.and.a bs.in 1234567890
scoreboard players set $bitwise.and.b bs.in 123456
function #bs.bitwise:and
assert score $bitwise.and bs.out matches 576
10 changes: 10 additions & 0 deletions datapacks/Bookshelf/data/bs.bitwise/tests/bit_count.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Bit count returns correct values
# @batch bs.bitwise

scoreboard players set $bitwise.bit_count.n bs.in -1568
function #bs.bitwise:bit_count
assert score $bitwise.bit_count bs.out matches 3

scoreboard players set $bitwise.bit_count.n bs.in 174653179
function #bs.bitwise:bit_count
assert score $bitwise.bit_count bs.out matches 19
10 changes: 10 additions & 0 deletions datapacks/Bookshelf/data/bs.bitwise/tests/bit_length.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Bit length returns correct values
# @batch bs.bitwise

scoreboard players set $bitwise.bit_length.n bs.in -1568
function #bs.bitwise:bit_length
assert score $bitwise.bit_length bs.out matches 11

scoreboard players set $bitwise.bit_length.n bs.in 174653179
function #bs.bitwise:bit_length
assert score $bitwise.bit_length bs.out matches 28
10 changes: 10 additions & 0 deletions datapacks/Bookshelf/data/bs.bitwise/tests/not.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Not operator returns correct values
# @batch bs.bitwise

scoreboard players set $bitwise.not.n bs.in 123456
function #bs.bitwise:not
assert score $bitwise.not bs.out matches -123457

scoreboard players set $bitwise.not.n bs.in -197364158
function #bs.bitwise:not
assert score $bitwise.not bs.out matches 197364157
12 changes: 12 additions & 0 deletions datapacks/Bookshelf/data/bs.bitwise/tests/or.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Or operator returns correct values
# @batch bs.bitwise

scoreboard players set $bitwise.or.a bs.in -9
scoreboard players set $bitwise.or.b bs.in 57
function #bs.bitwise:or
assert score $bitwise.or bs.out matches -1

scoreboard players set $bitwise.or.a bs.in 1234567890
scoreboard players set $bitwise.or.b bs.in 123456
function #bs.bitwise:or
assert score $bitwise.or bs.out matches 1234690770
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Two complement returns correct values
# @batch bs.bitwise

scoreboard players set $bitwise.two_complement.n bs.in 123456
function #bs.bitwise:two_complement
assert score $bitwise.two_complement bs.out matches 123456

scoreboard players set $bitwise.two_complement.n bs.in -197364158
function #bs.bitwise:two_complement
assert score $bitwise.two_complement bs.out matches 1950119490
12 changes: 12 additions & 0 deletions datapacks/Bookshelf/data/bs.bitwise/tests/xor.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Xor operator returns correct values
# @batch bs.bitwise

scoreboard players set $bitwise.xor.a bs.in -9
scoreboard players set $bitwise.xor.b bs.in 57
function #bs.bitwise:xor
assert score $bitwise.xor bs.out matches -50

scoreboard players set $bitwise.xor.a bs.in 1234567890
scoreboard players set $bitwise.xor.b bs.in 123456
function #bs.bitwise:xor
assert score $bitwise.xor bs.out matches 1234690194
Loading
Loading