Skip to content

Instantly share code, notes, and snippets.

@BaseCase
Created October 23, 2017 14:42
Show Gist options
  • Save BaseCase/aa8febee5fc52e279e37e6beb45cf825 to your computer and use it in GitHub Desktop.
Save BaseCase/aa8febee5fc52e279e37e6beb45cf825 to your computer and use it in GitHub Desktop.

Revisions

  1. BaseCase revised this gist Oct 23, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions decimal_test.exs
    Original 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
  2. BaseCase created this gist Oct 23, 2017.
    36 changes: 36 additions & 0 deletions decimal_test.exs
    Original 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")