Last active
September 7, 2019 16:33
-
-
Save elbow-jason/8da58de1a8c804c4c0189e2dd136f32e to your computer and use it in GitHub Desktop.
This file contains 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 MultisortDecimalTest do | |
use ExUnit.Case | |
@data [ | |
%{multiplier: Decimal.from_float(1.0), points: Decimal.from_float(400.0)}, | |
%{multiplier: Decimal.from_float(1.0), points: Decimal.from_float(500.0)}, | |
%{multiplier: Decimal.from_float(0.9), points: Decimal.from_float(600.0)}, | |
%{multiplier: Decimal.from_float(0.9), points: Decimal.from_float(700.0)} | |
] | |
@expected [ | |
%{multiplier: Decimal.from_float(1.0), points: Decimal.from_float(500.0)}, | |
%{multiplier: Decimal.from_float(1.0), points: Decimal.from_float(400.0)}, | |
%{multiplier: Decimal.from_float(0.9), points: Decimal.from_float(700.0)}, | |
%{multiplier: Decimal.from_float(0.9), points: Decimal.from_float(600.0)} | |
] | |
def compare(d1, d2) do | |
case Decimal.cmp(d1, d2) do | |
:gt -> 1.0 | |
:eq -> 0.0 | |
:lt -> -1.0 | |
end | |
end | |
def sort(data) do | |
data | |
|> Enum.sort_by(fn row -> | |
{to_string(row.multiplier), to_string(row.points)} | |
end) | |
|> Enum.reverse() | |
end | |
test "works" do | |
assert sort(@data) == @expected | |
end | |
end |
...but I can't seem to edit the gist...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def compare
should not be there.