Skip to content

Instantly share code, notes, and snippets.

@BaseCase
Created October 23, 2017 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BaseCase/aa8febee5fc52e279e37e6beb45cf825 to your computer and use it in GitHub Desktop.
Save BaseCase/aa8febee5fc52e279e37e6beb45cf825 to your computer and use it in GitHub Desktop.
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