-
Notifications
You must be signed in to change notification settings - Fork 8
Added some bit library tests #33
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
Open
FirstLemon
wants to merge
2
commits into
CFC-Servers:main
Choose a base branch
from
FirstLemon:bit-tests-pr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| --- @type GLuaTest_TestGroup | ||
| return { | ||
| groupName = "bit.arshift", | ||
| cases = { | ||
| { | ||
| name = "Should be a function", | ||
| func = function() | ||
| expect( bit.arshift ).to.beA( "function" ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Should correctly shift positive numbers", | ||
| func = function() | ||
| expect( bit.arshift( 8, 1 ) ).to.equal( 4 ) | ||
| expect( bit.arshift( 16, 2 ) ).to.equal( 4 ) | ||
| expect( bit.arshift( 0, 1 ) ).to.equal( 0 ) | ||
| expect( bit.arshift( 312, 0 ) ).to.equal( 312 ) | ||
| expect( bit.arshift( 123, 32 ) ).to.equal( 123 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Returns correct values for negative arhithmetic shifting", | ||
| func = function() | ||
| expect( bit.arshift( -8, 1 ) ).to.equal( -4 ) | ||
| expect( bit.arshift( -16, 2 ) ).to.equal( -4 ) | ||
| expect( bit.arshift( -12345, 5 ) ).to.equal( -386 ) | ||
| expect( bit.arshift( -1, 10 ) ).to.equal( -1 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Fails on invalid input", | ||
| func = function() | ||
| expect( bit.arshift, nil, nil ).to.err() | ||
| expect( bit.arshift, "abc", "def" ).to.err() | ||
| expect( bit.arshift, {}, {} ).to.err() | ||
| end | ||
| }, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| --- @type GLuaTest_TestGroup | ||
| return { | ||
| groupName = "bit.band", | ||
| cases = { | ||
| { | ||
| name = "Should be a function", | ||
| func = function() | ||
| expect( bit.band ).to.beA( "function" ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Should handle positive numbers correctly", | ||
| func = function() | ||
| expect( bit.band( 8, 8 ) ).to.equal( 8 ) | ||
| expect( bit.band( 42, 17 ) ).to.equal( 0 ) | ||
| expect( bit.band( 13, 7 ) ).to.equal( 5 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Should handle negative numbers correctly", | ||
| func = function() | ||
| expect( bit.band( -8, 8 ) ).to.equal( 8 ) | ||
| expect( bit.band( -10, -12 ) ).to.equal( -12 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Functions properly with more than 2 args", | ||
| func = function() | ||
| expect( bit.band( 15, 67, 13 ) ).to.equal( 1 ) | ||
| expect( bit.band( 300, 200, 300 ) ).to.equal( 8 ) | ||
| expect( bit.band( 1, 2, 4, 8, 16, 32, 64 ) ).to.equal( 0 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Returns same result when args are flipped", | ||
| func = function() | ||
| expect( bit.band( 123, 456 ) ).to.equal( bit.band( 456, 123 ) ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Fails on invalid input", | ||
| func = function() | ||
| expect( bit.band, nil, nil ).to.err() | ||
| expect( bit.band, "abc", "def" ).to.err() | ||
| expect( bit.band, {}, {} ).to.err() | ||
| end | ||
| }, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| --- @type GLuaTest_TestGroup | ||
| return { | ||
| groupName = "bit.bnot", | ||
| cases = { | ||
| { | ||
| name = "Should be a function", | ||
| func = function() | ||
| expect( bit.bnot ).to.beA( "function" ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Should correctly invert positive and negative numbers", | ||
| func = function() | ||
| expect( bit.bnot( 8 ) ).to.equal( -9 ) | ||
| expect( bit.bnot( 32 ) ).to.equal( -33 ) | ||
| expect( bit.bnot( -27534 ) ).to.equal( 27533 ) | ||
| expect( bit.bnot( -69 ) ).to.equal( 68 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Should handle edge cases correctly", | ||
| func = function() | ||
| expect( bit.bnot( 0 ) ).to.equal( -1 ) | ||
| expect( bit.bnot( -1 ) ).to.equal( 0 ) | ||
|
|
||
| expect( bit.bnot( 2147483647 ) ).to.equal( -2147483648 ) | ||
| expect( bit.bnot( -2147483648 ) ).to.equal( 2147483647 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Fails on invalid input", | ||
| func = function() | ||
| expect( bit.bnot, nil ).to.err() | ||
| expect( bit.bnot, "abc" ).to.err() | ||
| expect( bit.bnot, {} ).to.err() | ||
| end | ||
| }, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| --- @type GLuaTest_TestGroup | ||
| return { | ||
| groupName = "bit.bor", | ||
| cases = { | ||
| { | ||
| name = "Should be a function", | ||
| func = function() | ||
| expect( bit.bor ).to.beA( "function" ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Should handle positive numbers correctly", | ||
| func = function() | ||
| expect( bit.bor( 8, 8 ) ).to.equal( 8 ) | ||
| expect( bit.bor( 8, 1 ) ).to.equal( 9 ) | ||
| expect( bit.bor( 27533, 17 ) ).to.equal( 27549 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Should handle negative numbers correctly", | ||
| func = function() | ||
| expect( bit.bor( -1, 0 ) ).to.equal( -1 ) | ||
| expect( bit.bor( -8, 1 ) ).to.equal( -7 ) | ||
| expect( bit.bor( -100, 50 ) ).to.equal( -66 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Should handle zero values correctly", | ||
| func = function() | ||
| expect( bit.bor( 0, 69 ) ).to.equal( 69 ) | ||
| expect( bit.bor( -42, 0 ) ).to.equal( -42 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Returns correct value with multiple args", | ||
| func = function() | ||
| expect( bit.bor( 1, 2, 4, 8 ) ).to.equal( 15 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Handles Min and max values", | ||
| func = function() | ||
| expect( bit.bor( 2147483647, 2147483648 ) ).to.equal( -1 ) | ||
| expect( bit.bor( -2147483648, 0 ) ).to.equal( -2147483648 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Fails on invalid input", | ||
| func = function() | ||
| expect( bit.bor, nil, nil ).to.err() | ||
| expect( bit.bor, "abc", "def" ).to.err() | ||
| expect( bit.bor, {}, {} ).to.err() | ||
| end | ||
| }, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| --- @type GLuaTest_TestGroup | ||
| return { | ||
| groupName = "bit.bswap", | ||
| cases = { | ||
| { | ||
| name = "Should be a function", | ||
| func = function() | ||
| expect( bit.bswap ).to.beA( "function" ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "positive number byte swap", | ||
| func = function() | ||
| expect( bit.bswap( 327 ) ).to.equal( 1191247872 ) | ||
| expect( bit.bswap( 8 ) ).to.equal( 134217728 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Negative number byte swap", | ||
| func = function() | ||
| expect( bit.bswap( -8 ) ).to.equal( -117440513 ) | ||
| expect( bit.bswap( -100 ) ).to.equal( -1660944385 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Swapping 0 and -1 returns the correct value", | ||
| func = function() | ||
| expect( bit.bswap( 0 ) ).to.equal( 0 ) | ||
| expect( bit.bswap( -1 ) ).to.equal( -1 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Fails on invalid input", | ||
| func = function() | ||
| expect( bit.bswap, nil ).to.err() | ||
| expect( bit.bswap, "abc" ).to.err() | ||
| expect( bit.bswap, {} ).to.err() | ||
| end | ||
| }, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| --- @type GLuaTest_TestGroup | ||
| return { | ||
| groupName = "bit.bxor", | ||
| cases = { | ||
| { | ||
| name = "Should be a function", | ||
| func = function() | ||
| expect( bit.bxor ).to.beA( "function" ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Positive XOR operation", | ||
| func = function() | ||
| expect( bit.bxor( 19, 82 ) ).to.equal( 65 ) | ||
| expect( bit.bxor( 327, 63 ) ).to.equal( 376 ) | ||
| expect( bit.bxor( 234, 0 ) ).to.equal( 234 ) | ||
| expect( bit.bxor( 32, 32 ) ).to.equal( 0 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Negative XOR operation", | ||
| func = function() | ||
| expect( bit.bxor( -99, -55 ) ).to.equal( 84 ) | ||
| expect( bit.bxor( -420, -67 ) ).to.equal( 481 ) | ||
| expect( bit.bxor( -32, 0 ) ).to.equal( -32 ) | ||
| expect( bit.bxor( 42, -1 ) ).to.equal( -43 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Handles min and max 32-bit integers correctly", | ||
| func = function() | ||
| expect( bit.bxor( 2147483647, -2147483648 ) ).to.equal( -1 ) | ||
| expect( bit.bxor( 2147483647, 1 ) ).to.equal( 2147483646 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Handles multiple arguments correctly", | ||
| func = function() | ||
| expect( bit.bxor( 1, 2, 3, 4, 5 ) ).to.equal( 1 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Fails on invalid input", | ||
| func = function() | ||
| expect( bit.bxor, nil, nil ).to.err() | ||
| expect( bit.bxor, "abc", "def" ).to.err() | ||
| expect( bit.bxor, {}, {} ).to.err() | ||
| end | ||
| }, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| --- @type GLuaTest_TestGroup | ||
| return { | ||
| groupName = "bit.lshift", | ||
| cases = { | ||
| { | ||
| name = "Should be a function", | ||
| func = function() | ||
| expect( bit.lshift ).to.beA( "function" ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Should correctly shift positive numbers", | ||
| func = function() | ||
| expect( bit.lshift( 15, 4 ) ).to.equal( 240 ) | ||
| expect( bit.lshift( 96, 4 ) ).to.equal( 1536 ) | ||
| expect( bit.lshift( 63, 2 ) ).to.equal( 252 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Should correctly shift negative numbers", | ||
| func = function() | ||
| expect( bit.lshift( -8, 1 ) ).to.equal( -16 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Values are getting clamped over the signed 32-bit int limit", | ||
| func = function() | ||
| expect( bit.lshift( 4294967295, 1 ) ).to.equal( -2 ) | ||
| expect( bit.lshift( 1, 31 ) ).to.equal( -2147483648 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Shifting 0 times should return the same value", | ||
| func = function() | ||
| expect( bit.lshift( 1, 0 ) ).to.equal( 1 ) | ||
| expect( bit.lshift( 12345678, 0 ) ).to.equal( 12345678 ) | ||
| end | ||
| }, | ||
|
|
||
| { | ||
| name = "Fails on invalid input", | ||
| func = function() | ||
| expect( bit.lshift, nil, nil ).to.err() | ||
| expect( bit.lshift, "abc", "def" ).to.err() | ||
| expect( bit.lshift, {}, {} ).to.err() | ||
| end | ||
| }, | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Might be better to catch the full error message here