Created
October 23, 2017 14:42
-
-
Save BaseCase/aa8febee5fc52e279e37e6beb45cf825 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
defmodule DecimalTest do | |
use ExUnit.Case, async: true | |
alias Decimal.Context | |
alias Decimal.Error | |
require Decimal | |
doctest Decimal | |
defmacrop d(sign, coef, exp) do | |
quote do | |
%Decimal{sign: unquote(sign), coef: unquote(coef), exp: unquote(exp)} | |
end | |
end | |
# Function version of the `d` macro, which appears to be equivalent | |
# in terms of outcome. | |
# def d(sign, coef, exp) do | |
# %Decimal{sign: sign, coef: coef, exp: exp} | |
# end | |
defmacrop sigil_d(str, _opts) do | |
quote do | |
Decimal.new(unquote(str)) | |
end | |
end | |
test "test functions" do | |
assert Decimal.nan?(~d"nan") | |
refute Decimal.nan?(~d"0") | |
assert Decimal.inf?(~d"inf") | |
refute Decimal.inf?(~d"0") | |
assert Decimal.decimal?(~d"nan") | |
assert Decimal.decimal?(~d"inf") | |
# ... lots more below |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment