Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
barucden committed Oct 16, 2024
1 parent fd69b8d commit 557fbd0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 23 deletions.
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ global d = [

include("test_constructor.jl")
include("test_parse.jl")
include("test_show.jl")
include("test_decimal.jl")
include("test_norm.jl")
include("test_arithmetic.jl")
Expand Down
47 changes: 24 additions & 23 deletions test/test_decimal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,25 @@ using Test

@testset "String/Number to Decimal" begin
@testset "Direct" begin
@test parse(Decimal, "0.01") == Decimal(0.01) == Decimal(false, 1, -2)
@test parse(Decimal, ".001") == Decimal(.001) == Decimal(false, 1, -3)
@test parse(Decimal, "15.23") == Decimal(15.23) == Decimal(false, 1523, -2)
@test parse(Decimal, "543") == Decimal(543) == Decimal(false, 543, 0)
@test parse(Decimal, "-345") == Decimal(-345) == Decimal(true, 345, 0)
@test parse(Decimal, "000123") == Decimal(000123) == Decimal(false, 123, 0)
@test parse(Decimal, "-00032") == Decimal(-00032) == Decimal(true, 32, 0)
@test parse(Decimal, "200100") == Decimal(200100) == Decimal(false, 2001, 2)
@test parse(Decimal, "-.123") == Decimal(-.123) == Decimal(true, 123, -3)
@test parse(Decimal, "1.23000") == Decimal(1.23000) == Decimal(false, 123, -2)
@test parse(Decimal, "4734.612") == Decimal(4734.612) == Decimal(false, 4734612, -3)
@test parse(Decimal, "541724.2") == Decimal(541724.2) == Decimal(false,5417242,-1)
@test parse(Decimal, "2.5e6") == Decimal(2.5e6) == Decimal(false, 25, 5)
@test parse(Decimal, "2.385350e8") == Decimal(2.385350e8) == Decimal(false, 238535, 3)
@test parse(Decimal, "12.3e-4") == Decimal(12.3e-4) == Decimal(false, 123, -5)

@test parse(Decimal, "-12.3e4") == Decimal(-12.3e4) == Decimal(true, 123, 3)

@test parse(Decimal, "-12.3e-4") == Decimal(-12.3e-4) == Decimal(true, 123, -5)
@test parse(Decimal, "-12.3E-4") == Decimal(true, 123, -5)

@test parse(Decimal, "0.1234567891") == Decimal(0.1234567891) == Decimal(false,1234567891, -10)
@test parse(Decimal, "0.12345678912") == Decimal(0.12345678912) == Decimal(false,12345678912, -11)
@test Decimal(0.01) == Decimal(false, 1, -2)
@test Decimal(.001) == Decimal(false, 1, -3)
@test Decimal(15.23) == Decimal(false, 1523, -2)
@test Decimal(543) == Decimal(false, 543, 0)
@test Decimal(-345) == Decimal(true, 345, 0)
@test Decimal(000123) == Decimal(false, 123, 0)
@test Decimal(-00032) == Decimal(true, 32, 0)
@test Decimal(200100) == Decimal(false, 2001, 2)
@test Decimal(-.123) == Decimal(true, 123, -3)
@test Decimal(1.23000) == Decimal(false, 123, -2)
@test Decimal(4734.612) == Decimal(false, 4734612, -3)
@test Decimal(541724.2) == Decimal(false,5417242,-1)
@test Decimal(2.5e6) == Decimal(false, 25, 5)
@test Decimal(2.385350e8) == Decimal(false, 238535, 3)
@test Decimal(12.3e-4) == Decimal(false, 123, -5)
@test Decimal(-12.3e4) == Decimal(true, 123, 3)
@test Decimal(-12.3e-4) == Decimal(true, 123, -5)
@test Decimal(0.1234567891) == Decimal(false,1234567891, -10)
@test Decimal(0.12345678912) == Decimal(false,12345678912, -11)
end
end

Expand Down Expand Up @@ -61,4 +57,9 @@ end
@test Float64(Decimal(false, 123, -2)) == 1.23
end

@testset "Number functions" begin
@test isfinite(Decimal(0, 1, 1))
@test !isnan(Decimal(0, 1, 1))
end

end
3 changes: 3 additions & 0 deletions test/test_parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
@test dec"-123" == Decimal(1, 123, 0)
@test dec"1_000.002" == Decimal(0, 1000002, -3)
@test dec"1_000_000.002" == Decimal(0, 1000000002, -3)

@test_throws ArgumentError dec"100_"
@test_throws ArgumentError dec"100_.0"
end

end
23 changes: 23 additions & 0 deletions test/test_show.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@testset "Showing" begin
@testset "repr" begin
@test repr(Decimal(1, 2, 3)) == "Decimal(1, 2, 3)"
end

@testset "Scientific notation" begin
repr("text/plain", Decimal(0,123,0)) == "123"
repr("text/plain", Decimal(1,123,0)) == "-123"
repr("text/plain", Decimal(0,123,1)) == "1.23E+3"
repr("text/plain", Decimal(0,123,3)) == "1.23E+5"
repr("text/plain", Decimal(0,123,-1)) == "12.3"
repr("text/plain", Decimal(0,123,-5)) == "0.00123"
repr("text/plain", Decimal(0,123,-10)) == "1.23E-8"
repr("text/plain", Decimal(1,123,-12)) == "-1.23E-10"
repr("text/plain", Decimal(0,0,0)) == "0"
repr("text/plain", Decimal(0,0,-2)) == "0.00"
repr("text/plain", Decimal(0,0,2)) == "0E+2"
repr("text/plain", Decimal(1,0,0)) == "-0"
repr("text/plain", Decimal(0,5,-6)) == "0.000005"
repr("text/plain", Decimal(0,50,-7)) == "0.0000050"
repr("text/plain", Decimal(0,5,-7)) == "5E-7"
end
end

0 comments on commit 557fbd0

Please sign in to comment.