Skip to content

Commit

Permalink
Dectests: Fix scripts/dectest.jl
Browse files Browse the repository at this point in the history
A wrong condition in the script resulted in valid test cases to be
omitted.
  • Loading branch information
barucden committed Nov 14, 2024
1 parent f48ea84 commit 97a4f97
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 2 deletions.
3 changes: 1 addition & 2 deletions scripts/dectest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function translate(io, dectest_path)

test = parse_test(line)
any(isspecial, test.operands) && continue
isspecial(test.result) && continue

dectest = decimal_test(test, directives)
println(io, dectest)
Expand All @@ -57,7 +56,7 @@ end

function isspecial(value)
value = lowercase(value)
return occursin(r"(inf|nan|#|\?)", value)
return occursin(r"(inf|nan|#)", value)
end

function parse_precision(line)
Expand Down
1 change: 1 addition & 0 deletions test/dectests/test_abs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ using Decimals: @with_context
@with_context (Emax = 384, Emin = -383, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(abs(dec"-56267e-2") == dec"562.67")
@with_context (Emax = 384, Emin = -383, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(abs(dec"-56267e-1") == dec"5626.7")
@with_context (Emax = 384, Emin = -383, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(abs(dec"-56267e-0") == dec"56267")
@with_context (Emax = 999999999, Emin = -999999999, precision = 3, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, abs(dec"9.999e+999999999"))
@with_context (Emax = 999, Emin = -999, precision = 3, rounding = RoundingMode{:NearestTiesAway}()) @test(abs(dec"1.00e-999") == dec"1.00e-999")
@with_context (Emax = 999, Emin = -999, precision = 3, rounding = RoundingMode{:NearestTiesAway}()) @test(abs(dec"0.1e-999") == dec"1e-1000")
@with_context (Emax = 999, Emin = -999, precision = 3, rounding = RoundingMode{:NearestTiesAway}()) @test(abs(dec"0.10e-999") == dec"1.0e-1000")
Expand Down
32 changes: 32 additions & 0 deletions test/dectests/test_add.jl
Original file line number Diff line number Diff line change
Expand Up @@ -568,16 +568,24 @@ using Decimals: @with_context
@with_context (Emax = 384, Emin = -383, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"-1.0" + dec"-0.0" == dec"-1.0")
@with_context (Emax = 384, Emin = -383, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"1.0" + dec"0.0" == dec"1.0")
@with_context (Emax = 384, Emin = -383, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"1.0" + dec"-0.0" == dec"1.0")
@with_context (Emax = 999999999, Emin = -999999999, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"1e+999999999" + dec"9e+999999999")
@with_context (Emax = 999999999, Emin = -999999999, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"9e+999999999" + dec"1e+999999999")
@with_context (Emax = 999999999, Emin = -999999999, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"-1.1e-999999999" + dec"1e-999999999" == dec"-1e-1000000000")
@with_context (Emax = 999999999, Emin = -999999999, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"1e-999999999" + dec"-1.1e-999999999" == dec"-1e-1000000000")
@with_context (Emax = 999999999, Emin = -999999999, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"-1.0001e-999999999" + dec"1e-999999999" == dec"-1e-1000000003")
@with_context (Emax = 999999999, Emin = -999999999, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"1e-999999999" + dec"-1.0001e-999999999" == dec"-1e-1000000003")
@with_context (Emax = 999999999, Emin = -999999999, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"-1e+999999999" + dec"-9e+999999999")
@with_context (Emax = 999999999, Emin = -999999999, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"-9e+999999999" + dec"-1e+999999999")
@with_context (Emax = 999999999, Emin = -999999999, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"+1.1e-999999999" + dec"-1e-999999999" == dec"1e-1000000000")
@with_context (Emax = 999999999, Emin = -999999999, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"-1e-999999999" + dec"+1.1e-999999999" == dec"1e-1000000000")
@with_context (Emax = 999999999, Emin = -999999999, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"+1.0001e-999999999" + dec"-1e-999999999" == dec"1e-1000000003")
@with_context (Emax = 999999999, Emin = -999999999, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"-1e-999999999" + dec"+1.0001e-999999999" == dec"1e-1000000003")
@with_context (Emax = 999999999, Emin = -999999999, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"-1e+999999999" + dec"+9e+999999999" == dec"8e+999999999")
@with_context (Emax = 999999999, Emin = -999999999, precision = 9, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"-9e+999999999" + dec"+1e+999999999" == dec"-8e+999999999")
@with_context (Emax = 999999999, Emin = -999999999, precision = 3, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"0" + dec"-9.999e+999999999")
@with_context (Emax = 999999999, Emin = -999999999, precision = 3, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"-9.999e+999999999" + dec"0")
@with_context (Emax = 999999999, Emin = -999999999, precision = 3, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"0" + dec"9.999e+999999999")
@with_context (Emax = 999999999, Emin = -999999999, precision = 3, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"9.999e+999999999" + dec"0")
@with_context (Emax = 999, Emin = -999, precision = 3, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"1.00e-999" + dec"0" == dec"1.00e-999")
@with_context (Emax = 999, Emin = -999, precision = 3, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"0.1e-999" + dec"0" == dec"1e-1000")
@with_context (Emax = 999, Emin = -999, precision = 3, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"0.10e-999" + dec"0" == dec"1.0e-1000")
Expand Down Expand Up @@ -638,13 +646,25 @@ using Decimals: @with_context
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"9.999999e+96" == dec"9.999999e+96")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"9.999999e+96" + dec"1" == dec"9.999999e+96")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"9999999e+90" + dec"1" == dec"9.999999e+96")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"9999999e+90" + dec"1e+90")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"9999999e+90" + dec"9e+89")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"9999999e+90" + dec"8e+89")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"9999999e+90" + dec"7e+89")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"9999999e+90" + dec"6e+89")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"9999999e+90" + dec"5e+89")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"9999999e+90" + dec"4e+89" == dec"9.999999e+96")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"9999999e+90" + dec"3e+89" == dec"9.999999e+96")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"9999999e+90" + dec"2e+89" == dec"9.999999e+96")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"9999999e+90" + dec"1e+89" == dec"9.999999e+96")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"-9.999999e+96" == dec"-9.999999e+96")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"-9.999999e+96" + dec"-1" == dec"-9.999999e+96")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"-9999999e+90" + dec"-1" == dec"-9.999999e+96")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"-9999999e+90" + dec"-1e+90")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"-9999999e+90" + dec"-9e+89")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"-9999999e+90" + dec"-8e+89")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"-9999999e+90" + dec"-7e+89")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"-9999999e+90" + dec"-6e+89")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test_throws(OverflowError, dec"-9999999e+90" + dec"-5e+89")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"-9999999e+90" + dec"-4e+89" == dec"-9.999999e+96")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"-9999999e+90" + dec"-3e+89" == dec"-9.999999e+96")
@with_context (Emax = 96, Emin = -95, precision = 7, rounding = RoundingMode{:NearestTiesAway}()) @test(dec"-9999999e+90" + dec"-2e+89" == dec"-9.999999e+96")
Expand Down Expand Up @@ -1486,13 +1506,25 @@ using Decimals: @with_context
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test(dec"9.999999999999999e+384" == dec"9.999999999999999e+384")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test(dec"9.999999999999999e+384" + dec"1" == dec"9.999999999999999e+384")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test(dec"9999999999999999e+369" + dec"1" == dec"9.999999999999999e+384")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test_throws(OverflowError, dec"9999999999999999e+369" + dec"1e+369")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test_throws(OverflowError, dec"9999999999999999e+369" + dec"9e+368")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test_throws(OverflowError, dec"9999999999999999e+369" + dec"8e+368")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test_throws(OverflowError, dec"9999999999999999e+369" + dec"7e+368")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test_throws(OverflowError, dec"9999999999999999e+369" + dec"6e+368")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test_throws(OverflowError, dec"9999999999999999e+369" + dec"5e+368")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test(dec"9999999999999999e+369" + dec"4e+368" == dec"9.999999999999999e+384")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test(dec"9999999999999999e+369" + dec"3e+368" == dec"9.999999999999999e+384")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test(dec"9999999999999999e+369" + dec"2e+368" == dec"9.999999999999999e+384")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test(dec"9999999999999999e+369" + dec"1e+368" == dec"9.999999999999999e+384")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test(dec"-9.999999999999999e+384" == dec"-9.999999999999999e+384")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test(dec"-9.999999999999999e+384" + dec"-1" == dec"-9.999999999999999e+384")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test(dec"-9999999999999999e+369" + dec"-1" == dec"-9.999999999999999e+384")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test_throws(OverflowError, dec"-9999999999999999e+369" + dec"-1e+369")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test_throws(OverflowError, dec"-9999999999999999e+369" + dec"-9e+368")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test_throws(OverflowError, dec"-9999999999999999e+369" + dec"-8e+368")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test_throws(OverflowError, dec"-9999999999999999e+369" + dec"-7e+368")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test_throws(OverflowError, dec"-9999999999999999e+369" + dec"-6e+368")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test_throws(OverflowError, dec"-9999999999999999e+369" + dec"-5e+368")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test(dec"-9999999999999999e+369" + dec"-4e+368" == dec"-9.999999999999999e+384")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test(dec"-9999999999999999e+369" + dec"-3e+368" == dec"-9.999999999999999e+384")
@with_context (Emax = 384, Emin = -383, precision = 16, rounding = RoundingMode{:Nearest}()) @test(dec"-9999999999999999e+369" + dec"-2e+368" == dec"-9.999999999999999e+384")
Expand Down
Loading

0 comments on commit 97a4f97

Please sign in to comment.