Skip to content

Commit

Permalink
add tests to compare/3 and eq? /3
Browse files Browse the repository at this point in the history
  • Loading branch information
v1d3rm3 committed May 25, 2024
1 parent 2771ecc commit 0244e66
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/decimal_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,24 @@ defmodule DecimalTest do
end
end

test "compare/3" do
assert Decimal.compare(~d"420.5", ~d"42e1", "0.5") == :eq
assert Decimal.compare(~d"420.5", ~d"42e1", "0.2") == :gt

assert_raise Error, fn ->
Decimal.compare(~d"420.5", ~d"42e1", "-0.2")
end

assert Decimal.compare(~d"1", ~d"0", "0") == :gt

assert Decimal.compare(~d"-inf", ~d"inf", "100") == :lt
assert Decimal.compare(~d"inf", ~d"-inf", "0") == :gt
assert Decimal.compare(~d"0", ~d"inf", "1000000") == :lt

assert Decimal.compare(~d"0.123", ~d"0", "0") == :gt
assert Decimal.compare(~d"0.123", ~d"0", "0.2") == :eq
end

test "equal?/2" do
assert Decimal.equal?(~d"420", ~d"42e1")
refute Decimal.equal?(~d"1", ~d"0")
Expand All @@ -277,6 +295,13 @@ defmodule DecimalTest do
refute Decimal.eq?(~d"1", ~d"nan")
end

test "eq/3?" do

Check failure on line 298 in test/decimal_test.exs

View workflow job for this annotation

GitHub Actions / test (1.8.2, 20.3.x)

test eq/3? (DecimalTest)

Check failure on line 298 in test/decimal_test.exs

View workflow job for this annotation

GitHub Actions / test (1.14.x, 25.x, lint)

test eq/3? (DecimalTest)
assert Decimal.eq?(~d"420", ~d"42e1", ~d"0")
assert Decimal.eq?(~d"1", ~d"0", ~d"1")
refute Decimal.eq?(~d"1", ~d"0", ~d"0")
refute Decimal.eq?(~d"nan", ~d"1", ~d"1")
end

test "gt?/2" do
refute Decimal.gt?(~d"420", ~d"42e1")
assert Decimal.gt?(~d"1", ~d"0")
Expand Down

0 comments on commit 0244e66

Please sign in to comment.