Skip to content

Commit 1f5c266

Browse files
tests added for Ryu.writeshortest output format options
1 parent 3c48c86 commit 1f5c266

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

test/ryu.jl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,34 @@ todouble(sign, exp, mant) = Core.bitcast(Float64, (UInt64(sign) << 63) | (UInt64
1919
@test Ryu.writeshortest(-Inf) == "-Inf"
2020
end
2121

22+
@testset "OutputOptions" begin
23+
# plus
24+
@test "+1" == Base.Ryu.writeshortest(1.0, true, false, false)
25+
@test "-1" == Base.Ryu.writeshortest(-1.0, true, false, false)
26+
27+
# space
28+
@test " 1" == Ryu.writeshortest(1.0, false, true, false)
29+
30+
# hash
31+
@test "0" == Ryu.writeshortest(0.0, false, false, false)
32+
33+
# precision
34+
@test "9.9900" == Ryu.writeshortest(9.99, false, false, true, 5)
35+
@test "1." == Ryu.writeshortest(1.0, false, false, true, 1)
36+
37+
# expchar
38+
@test "1.0d6" == Ryu.writeshortest(1e6, false, false, true, -1, UInt8('d'))
39+
40+
# padexp
41+
@test "3.0e+08" == Ryu.writeshortest(3e8, false, false, true, -1, UInt8('e'), true)
42+
43+
# decchar
44+
@test "3,14" == Ryu.writeshortest(3.14, false, false, true, -1, UInt8('e'), false, UInt8(','))
45+
46+
# compact
47+
@test "0.333333" == Ryu.writeshortest(1/3, false, false, true, -1, UInt8('e'), false, UInt8('.'), false, true)
48+
end
49+
2250
@testset "SwitchToSubnormal" begin
2351
@test "2.2250738585072014e-308" == Ryu.writeshortest(2.2250738585072014e-308)
2452
end
@@ -241,6 +269,17 @@ end # Float64
241269
@test "-Inf" == Ryu.writeshortest(Float32(-Inf))
242270
end
243271

272+
@testset "OutputOptions" begin
273+
# typed
274+
@test "1.0f0" == Ryu.writeshortest(Float32(1.0), false, false, true, -1, UInt8('e'), false, UInt8('.'), true)
275+
@test "Inf32" == Ryu.writeshortest(Float32(Inf), false, false, true, -1, UInt8('e'), false, UInt8('.'), true)
276+
@test "NaN32" == Ryu.writeshortest(Float32(NaN), false, false, true, -1, UInt8('e'), false, UInt8('.'), true)
277+
@test "3.14f0" == Ryu.writeshortest(Float32(3.14), false, false, true, -1, UInt8('e'), false, UInt8('.'), true)
278+
279+
# typed and no-hash
280+
@test "1f0" == Ryu.writeshortest(1.0f0, false, false, false, -1, UInt8('e'), false, UInt8('.'), true)
281+
end
282+
244283
@testset "SwitchToSubnormal" begin
245284
@test "1.1754944e-38" == Ryu.writeshortest(1.1754944f-38)
246285
end
@@ -341,6 +380,17 @@ end # Float32
341380
@test "-Inf" == Ryu.writeshortest(Float16(-Inf))
342381
end
343382

383+
@testset "OutputOptions" begin
384+
# typed
385+
@test "Float16(1.0)" == Ryu.writeshortest(Float16(1.0), false, false, true, -1, UInt8('e'), false, UInt8('.'), true)
386+
@test "Inf16" == Ryu.writeshortest(Float16(Inf), false, false, true, -1, UInt8('e'), false, UInt8('.'), true)
387+
@test "NaN16" == Ryu.writeshortest(Float16(NaN), false, false, true, -1, UInt8('e'), false, UInt8('.'), true)
388+
@test "Float16(3.14)" == Ryu.writeshortest(Float16(3.14), false, false, true, -1, UInt8('e'), false, UInt8('.'), true)
389+
390+
# typed and no-hash
391+
@test "Float16(1)" == Ryu.writeshortest(Float16(1.0), false, false, false, -1, UInt8('e'), false, UInt8('.'), true)
392+
end
393+
344394
let x=floatmin(Float16)
345395
while x <= floatmax(Float16)
346396
@test parse(Float16, Ryu.writeshortest(x)) == x

0 commit comments

Comments
 (0)