Created
October 23, 2017 14:42
-
-
Save BaseCase/aa8febee5fc52e279e37e6beb45cf825 to your computer and use it in GitHub Desktop.
Revisions
-
BaseCase revised this gist
Oct 23, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -34,3 +34,4 @@ defmodule DecimalTest do assert Decimal.decimal?(~d"nan") assert Decimal.decimal?(~d"inf") # ... lots more below -
BaseCase created this gist
Oct 23, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ 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")