Skip to content

Commit

Permalink
chore: make tests independent of order
Browse files Browse the repository at this point in the history
  • Loading branch information
Joeri Dijkstra committed Dec 29, 2023
1 parent f73726b commit c3a284d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions test/map_grid_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ defmodule MapGridTest do

test "can convert" do
maps = [%{name: "john", age: 99}, %{name: "doe", age: 100}]
assert [[:name, :age] | rest] = MapGrid.convert(maps)
assert Enum.member?(rest, ["john", 99])
assert Enum.member?(rest, ["doe", 100])
result = Enum.map(MapGrid.convert(maps), &Enum.sort/1)
assert result == [[:age, :name], [99, "john"], [100, "doe"]]
end

test "empty" do
Expand All @@ -16,9 +15,8 @@ defmodule MapGridTest do

test "uneven amount of values in map" do
maps = [%{name: "john", age: 99}, %{name: "doe", age: 100, desc: "some description"}]

assert [[:name, :age] | rest] = MapGrid.convert(maps)
assert [["doe", "some description", 100], ["john", 99]] == Enum.sort(rest)
result = Enum.map(MapGrid.convert(maps), &Enum.sort/1)
assert [[:age, :name], [99, "john"], [100, "doe", "some description"]] == result
end

test "with a function" do
Expand All @@ -28,8 +26,9 @@ defmodule MapGridTest do
Map.put(x, :batch, 3)
end

assert [[:name, :batch, :age] | rest] = MapGrid.convert(maps, item_function: function)
assert [["doe", 3, 100], ["john", 3, 99]] == Enum.sort(rest)
converted = MapGrid.convert(maps, item_function: function)
result = Enum.map(converted, &Enum.sort/1)
assert [[:age, :batch, :name], [3, 99, "john"], [3, 100, "doe"]] == result
end

test "with keys" do
Expand Down

0 comments on commit c3a284d

Please sign in to comment.