This commit is contained in:
bluepython508
2024-11-12 19:03:03 +00:00
parent f99153d6fd
commit 5ea2ef7a23
7 changed files with 130 additions and 2 deletions

View 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