This commit is contained in:
33
test/monfari/amount_test.exs
Normal file
33
test/monfari/amount_test.exs
Normal file
@@ -0,0 +1,33 @@
|
||||
defmodule Monfari.AmountTest do
|
||||
use ExUnit.Case
|
||||
use ExUnitProperties
|
||||
alias Monfari.Types.Amount
|
||||
|
||||
defp amounts(), do: member_of(["USD", "GBP", "EUR"]) |> bind(&amounts/1)
|
||||
|
||||
defp amounts(currency) do
|
||||
gen all sign <- member_of([1, -1]),
|
||||
whole <- non_negative_integer(),
|
||||
part <- integer(0..99) do
|
||||
%Amount{sign: sign, whole: whole, part: part, currency: currency}
|
||||
end
|
||||
end
|
||||
|
||||
property "parser and formatter roundtrip" do
|
||||
check all amount <- amounts() do
|
||||
with {:ok, str} <- Amount.dump(amount),
|
||||
{:ok, roundtripped} <- Amount.load(str),
|
||||
do: assert roundtripped == amount
|
||||
end
|
||||
end
|
||||
|
||||
property "value roundtrips" do
|
||||
check all value <- integer() do
|
||||
assert Amount.value(Amount.from_value(value, "USD")) == value
|
||||
end
|
||||
|
||||
check all amount <- amounts() do
|
||||
assert Amount.from_value(Amount.value(amount), amount.currency) == amount
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user