-
Notifications
You must be signed in to change notification settings - Fork 16
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
handle exponential floats #16
Open
zoryamba
wants to merge
7
commits into
jgranstrom:master
Choose a base branch
from
zoryamba:master
base: master
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9c7e0c1
handle exponential floats
zoryamba 75fdfb3
fix 1.23e+123 parsing to 1.2299..99e+123 parsing
zoryamba d18462b
get rid of RegExp
zoryamba cc37990
add small exponential tests
zoryamba 9fdf508
revert integer determination
zoryamba bd869b8
get rid of redundant float conversion
zoryamba e027be2
get rid of redundant float conversion
zoryamba 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 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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,77 @@ | ||
import {describe, it} from "mocha"; | ||
import {TestCase} from "../test-case"; | ||
import { | ||
FLOAT_EXPONENT_DELIMITER, | ||
FLOAT_FULL_PRECISION_DELIMITER, | ||
FLOAT_REDUCED_PRECISION_DELIMITER, | ||
FLOAT_TOKEN, | ||
INTEGER_SMALL_TOKEN_ELEMENT_OFFSET, | ||
INTEGER_SMALL_TOKENS, | ||
UNREFERENCED_INTEGER_TOKEN | ||
} from "../../lib/constants"; | ||
|
||
|
||
const testCases = [ | ||
new TestCase('small-integer', | ||
1, | ||
[INTEGER_SMALL_TOKENS[INTEGER_SMALL_TOKEN_ELEMENT_OFFSET + 1]] | ||
), | ||
new TestCase('big-integer', | ||
61, | ||
[UNREFERENCED_INTEGER_TOKEN, 'z'] | ||
), | ||
new TestCase('float', | ||
0.123, | ||
[FLOAT_TOKEN, '0', FLOAT_REDUCED_PRECISION_DELIMITER, '1z'] | ||
), | ||
new TestCase('float-negative', | ||
-0.123, | ||
[FLOAT_TOKEN, '0', FLOAT_REDUCED_PRECISION_DELIMITER, '-1z'] | ||
), | ||
new TestCase('float-full-precision', | ||
0.1234567, | ||
[FLOAT_TOKEN, '0', FLOAT_FULL_PRECISION_DELIMITER, '1234567'], | ||
{fullPrecisionFloats: true} | ||
), | ||
new TestCase('float-full-precision-negative', | ||
-0.1234567, | ||
[FLOAT_TOKEN, '-0', FLOAT_FULL_PRECISION_DELIMITER, '1234567'], | ||
{fullPrecisionFloats: true} | ||
), | ||
new TestCase('float-exp-positive', | ||
1.23e+123, | ||
[FLOAT_TOKEN, '1', FLOAT_FULL_PRECISION_DELIMITER, '23', FLOAT_EXPONENT_DELIMITER, '1z'], | ||
{fullPrecisionFloats: true} | ||
), | ||
new TestCase('float-exp-negative', | ||
1.23e-123, | ||
[FLOAT_TOKEN, '1', FLOAT_FULL_PRECISION_DELIMITER, '23', FLOAT_EXPONENT_DELIMITER, '-1z'], | ||
{fullPrecisionFloats: true} | ||
), | ||
new TestCase('float-exp-positive', | ||
1e+1, | ||
[UNREFERENCED_INTEGER_TOKEN, 'A'], | ||
), | ||
new TestCase('float-exp-negative', | ||
1e-1, | ||
[FLOAT_TOKEN, '0', FLOAT_REDUCED_PRECISION_DELIMITER, '1c'], | ||
), | ||
]; | ||
|
||
describe('Number', function() { | ||
for(let i = 0; i < testCases.length; i++) { | ||
const testCase = testCases[i]; | ||
|
||
describe(testCase.name, function() { | ||
it('compress', function() { | ||
testCase.compress(); | ||
}); | ||
it('decompress', function() { | ||
testCase.decompress(); | ||
}); | ||
it('decompress-incremental', function() { | ||
testCase.decompressIncremental(); | ||
}); | ||
}); | ||
} | ||
}) |
This file contains 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
This file contains 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
This file contains 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,35 @@ | ||
import {CompressOptions} from "../lib"; | ||
import {parse, parseIncremental, stringify} from "../src"; | ||
import {expect} from "chai"; | ||
|
||
export class TestCase { | ||
constructor( | ||
public name: string, | ||
private obj: any, | ||
private tokens: string[], | ||
private options: CompressOptions = {} | ||
) {} | ||
|
||
compress() { | ||
const compressed = stringify(this.obj, this.options); | ||
expect(compressed).to.equal(this.tokens.join('')); | ||
} | ||
|
||
decompress() { | ||
const decompressed = parse(this.tokens.join('')); | ||
expect(decompressed).to.deep.equal(this.obj); | ||
} | ||
|
||
decompressIncremental() { | ||
const all = this.tokens.join(''); | ||
for(let i = 0; i < all.length; i++) { | ||
for(let j = i; j < all.length; j++) { | ||
const increment = parseIncremental(); | ||
increment(all.slice(0, i)); | ||
increment(all.slice(i, j)); | ||
increment(all.slice(j)); | ||
expect(increment(null)).to.deep.equal(this.obj); | ||
} | ||
} | ||
} | ||
} |
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.
Another couple of test cases that would be worth adding is like
1e1
and1e-1
for numbers that would generally not be expressed with this notation, but still could be.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.
Makes sense. Added them in test/full/number.ts