forked from kipcole9/money
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgringotts_test.exs
26 lines (22 loc) · 1.06 KB
/
gringotts_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
defmodule Money.GringottsTest do
use ExUnit.Case
alias Gringotts.Money, as: MoneyProtocol
describe "Gringotts.Money protocol implementation" do
test "currency is an upcase String.t" do
the_currency = MoneyProtocol.currency(Money.new(0, :USD))
assert match?(currency when is_binary(currency), the_currency)
assert the_currency == String.upcase(the_currency)
end
test "to_integer" do
assert match?({"EUR", 4200, -2}, MoneyProtocol.to_integer(Money.new(42, :EUR)))
assert match?({"BHD", 42_000, -3}, MoneyProtocol.to_integer(Money.new(42, :BHD)))
assert match?({"BHD", 42_007, -3}, MoneyProtocol.to_integer(Money.new("42.0066", :BHD)))
end
test "to_string" do
assert match?({"EUR", "42"}, MoneyProtocol.to_string(Money.new("42.00", :EUR)))
assert match?({"EUR", "42"}, MoneyProtocol.to_string(Money.new(42, :EUR)))
assert match?({"EUR", "42.01"}, MoneyProtocol.to_string(Money.new("42.0064", :EUR)))
assert match?({"BHD", "42.006"}, MoneyProtocol.to_string(Money.new("42.006", :BHD)))
end
end
end