Skip to content

Commit

Permalink
add test for Quotes.random for #4 dwyl/learn-elixir#95
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Oct 14, 2019
1 parent 5591be8 commit 796cb32
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion test/quotes_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ defmodule QuotesTest do
end)
end


def get_random_quote_until_collision(random_quotes_list) do
random_quote = Quotes.random()
if Enum.member?(random_quotes_list, random_quote) do
random_quotes_list
else
get_random_quote_until_collision([random_quote | random_quotes_list])
end
end

test "Quotes.random returns a random quote by any author" do
random_quotes_list = get_random_quote_until_collision([])
# this is the birthday paradox at work! ;-)
IO.inspect Enum.count(random_quotes_list), Label: "Collision after"
assert Enum.count(random_quotes_list) < 200
end

end

0 comments on commit 796cb32

Please sign in to comment.