-
Notifications
You must be signed in to change notification settings - Fork 152
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
toArray/toString: add tests #36
base: master
Are you sure you want to change the base?
Changes from all commits
11d82d0
d6d252c
8b13595
7d9198b
1b56590
6e065cb
dc79116
59a2122
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
{ | ||
"valid": [ | ||
{ | ||
"dec": "0", | ||
"hex": "00" | ||
}, | ||
{ | ||
"dec": "1", | ||
"hex": "01" | ||
}, | ||
{ | ||
"dec": "-1", | ||
"hex": "ff" | ||
}, | ||
{ | ||
"dec": "127", | ||
"hex": "7f" | ||
}, | ||
{ | ||
"dec": "-127", | ||
"hex": "81" | ||
}, | ||
{ | ||
"dec": "128", | ||
"hex": "80" | ||
}, | ||
{ | ||
"dec": "-128", | ||
"hex": "80" | ||
}, | ||
{ | ||
"dec": "255", | ||
"hex": "ff" | ||
}, | ||
{ | ||
"dec": "-255", | ||
"hex": "ff01" | ||
}, | ||
{ | ||
"dec": "16300", | ||
"hex": "3fac" | ||
}, | ||
{ | ||
"dec": "-16300", | ||
"hex": "c054" | ||
}, | ||
{ | ||
"dec": "62300", | ||
"hex": "f35c" | ||
}, | ||
{ | ||
"dec": "-62300", | ||
"hex": "ff0ca4" | ||
}, | ||
{ | ||
"dec": "158798437896437949616241483468158498679", | ||
"hex": "77777777777777777777777777777777" | ||
}, | ||
{ | ||
"dec": "115792089237316195423570985008687907852837564279074904382605163141518161494336", | ||
"hex": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140" | ||
}, | ||
{ | ||
"dec": "48968302285117906840285529799176770990048954789747953886390402978935544927851", | ||
"hex": "6c4313b03f2e7324d75e642f0ab81b734b724e13fec930f309e222470236d66b" | ||
} | ||
], | ||
"invalid": [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So far, none of these are throwing. Is that intentional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this is for speed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean, for speed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean that checking and throwing takes time, and I want it to be as fast as possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, what would the expected behaviour be then? Just so I can put it under these tests :) Like, does it just skip bad characters? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is worse than that :) You'll get some garbage. Predictable, but still a garbage. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not make the default safe, and for the internal usage a factory method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dcousens I don't even use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would most certainly be a start. |
||
{ | ||
"description": "non-decimal string", | ||
"dec": "invalid" | ||
}, | ||
{ | ||
"description": "non-hex string", | ||
"hex": "invalid" | ||
}, | ||
{ | ||
"description": "incomplete hex", | ||
"hex": "ffffd0a" | ||
}, | ||
{ | ||
"description": "non-decimal alphabet", | ||
"dec": "c2F0b3NoaQo=" | ||
}, | ||
{ | ||
"description": "non-hex alphabet", | ||
"hex": "c2F0b3NoaQo=" | ||
}, | ||
{ | ||
"description": "internal whitespace", | ||
"dec": "11111 11111", | ||
"hex": "11111 11111" | ||
}, | ||
{ | ||
"description": "leading whitespace", | ||
"dec": " 1111111111", | ||
"hex": " 1111111111" | ||
}, | ||
{ | ||
"description": "trailing whitespace", | ||
"dec": "1111111111 ", | ||
"hex": "1111111111 " | ||
} | ||
] | ||
} |
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.
Why should this happen? Hex could be negative too, right?
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.
It is the twos complement, that is negative.
On 11 Apr 2015 04:28, "Fedor Indutny" [email protected] wrote:
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.
Mmm...? I don't think I support twos complement anywhere in code. Also, it doesn't seem to be a desired feature to me.
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.
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.
@dcousens HEX is nothing special to
.toString()
, the base-36 or base-3 encoding should work the same way as the HEX does.I guess the two's complement thing should happen in the code responsible for encoding this. There are various way to encode it, and this doesn't look like a reason to make HEX something special.
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.
Agreed, maybe it's worth having it as separate functionality? In any
case, I'll amend the test vectors.
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.
Sure, makes sense for another issue/PR ;)