-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from jhawthorn/float_compatibility
Make float output identical to JSON gem
- Loading branch information
Showing
6 changed files
with
116 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[5e-324] | ||
[5.0e-324] |
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 |
---|---|---|
@@ -1 +1 @@ | ||
[1.7976931348623157e308] | ||
[1.7976931348623157e+308] |
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,54 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class TestAllocations < Minitest::Test | ||
def test_integer | ||
assert_encode_allocations 1, [1, 2, 3, 4, 5] | ||
end | ||
|
||
def test_boolean | ||
assert_encode_allocations 1, [true, false, true, false, true, false] | ||
end | ||
|
||
def test_float | ||
# FIXME: ideally would not allocate | ||
assert_encode_allocations 6, [1.0, 2.0, 3.0, 4.0, 5.0] | ||
end | ||
|
||
def test_symbol | ||
assert_encode_allocations 1, %i[foo bar baz quux] | ||
end | ||
|
||
def test_string | ||
assert_encode_allocations 1, %w[foo bar baz quux] | ||
end | ||
|
||
def test_array | ||
assert_encode_allocations 1, [[], [], [], [], []] | ||
end | ||
|
||
def test_hash | ||
assert_encode_allocations 1, {foo: 1, bar: 2, baz: 3, quux: 4} | ||
end | ||
|
||
def assert_encode_allocations(expected, data) | ||
allocations = measure_allocations { RapidJSON.encode(data) } | ||
assert_equal expected, allocations | ||
end | ||
|
||
def measure_allocations | ||
i = 0 | ||
while i < 2 | ||
before = allocations | ||
yield | ||
after = allocations | ||
i += 1 | ||
end | ||
after - before | ||
end | ||
|
||
def allocations | ||
GC.stat(:total_allocated_objects) | ||
end | ||
end |
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