Files
plantid-discord-bot/test/utils/duration_test.exs
T
owenrees 02372f2076 Feat/error logs (#16)
* added list of tasks to achieve

* update deps

* update elixir version in CI/CD pipeline

* update todo with branch push checks

* underscores separation of large numbers

* update elixir version and deps

* add basic module  docs

* remove IO.inspect call

* check if list is empty rather than traversing list for length

* revert empty list code

* duration tests

* add mime type tests

* use logger instread of inspect, remove todos

* replace list length check with Enum.empty

* replace list length check with !Enum.empty?

* numbers readability fix by using underscores on large numbers

* iucn parser replaced case with multiclause function and added test

* replace map and join with map_join

* fix multiple spec issues where map() must be inside a list
2025-12-06 23:41:59 +01:00

40 lines
1.1 KiB
Elixir

defmodule PlantIdDiscordBotTest.Utils.Duration do
use ExUnit.Case, async: true
alias PlantIdDiscordBot.Utils.Duration
doctest Duration
describe "sec_to_str/1" do
test "seconds" do
assert Duration.sec_to_str(5) == "5s"
refute Duration.sec_to_str(60) == "60s"
end
test "minutes" do
assert Duration.sec_to_str(60) == "1m"
assert Duration.sec_to_str(75) == "1m 15s"
refute Duration.sec_to_str(3600) == "60m"
end
test "hours" do
assert Duration.sec_to_str(3600) == "1h"
assert Duration.sec_to_str(7205) == "2h 5s"
assert Duration.sec_to_str(36_300) == "10h 5m"
assert Duration.sec_to_str(36_315) == "10h 5m 15s"
refute Duration.sec_to_str(86_400) == "24h"
end
test "days" do
assert Duration.sec_to_str(86_400) == "1d"
assert Duration.sec_to_str(86_715) == "1d 5m 15s"
refute Duration.sec_to_str(604_800) == "7d"
end
test "weeks" do
assert Duration.sec_to_str(604_800) == "1w"
assert Duration.sec_to_str(6_048_000) == "10w"
end
end
end