-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: vshev4enko <[email protected]>
- Loading branch information
1 parent
0ae3bd5
commit eed830a
Showing
5 changed files
with
65 additions
and
9 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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
defmodule Decimal.PropertyTest do | ||
use ExUnit.Case, async: true | ||
use ExUnitProperties | ||
|
||
describe "compare/2" do | ||
test "integer equality" do | ||
check all( | ||
first <- StreamData.integer(), | ||
second <- StreamData.integer() | ||
) do | ||
assert Decimal.compare(first, second) == term_compare(first, second) | ||
end | ||
end | ||
|
||
test "float equality" do | ||
check all( | ||
first <- StreamData.float(), | ||
second <- StreamData.float() | ||
) do | ||
assert Decimal.compare(to_dec(first), to_dec(second)) == term_compare(first, second) | ||
end | ||
end | ||
|
||
test "number equality" do | ||
check all( | ||
first <- stream_data_number(), | ||
second <- stream_data_number() | ||
) do | ||
assert Decimal.compare(to_dec(first), to_dec(second)) == term_compare(first, second) | ||
end | ||
end | ||
end | ||
|
||
defp to_dec(float) when is_float(float), do: Decimal.from_float(float) | ||
defp to_dec(other), do: Decimal.new(other) | ||
|
||
defp term_compare(first, second) do | ||
cond do | ||
first < second -> :lt | ||
first > second -> :gt | ||
true -> :eq | ||
end | ||
end | ||
|
||
defp stream_data_number() do | ||
StreamData.one_of([StreamData.integer(), StreamData.float()]) | ||
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