test(growth): work on age calculation
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
João Paulo Dubas 2024-07-12 11:18:40 +00:00
parent 8e9907a3e8
commit c923b2efb7
Signed by: joao.dubas
SSH Key Fingerprint: SHA256:V1mixgOGRc/YMhGx/DNkOSmJxgA2vHNrDZEk3wt/kOA

View File

@ -0,0 +1,46 @@
defmodule Growth.Calc.AgeTest do
@moduledoc false
use ExUnit.Case, async: true
alias Growth.Calc.Age
describe "calculate/2" do
test "consider today as date of measurement" do
date_of_birth = Date.add(Date.utc_today(), -7)
assert 7 == Age.calculate(:day, date_of_birth)
end
end
describe "calculate/3" do
test "calculate age in days" do
date_of_measurement = ~D[2024-06-09]
days_of_birth = [{-1, 1}, {-7, 7}, {-30, 30}]
Enum.map(days_of_birth, fn {days_ago, expected_age} ->
date_of_birth = Date.add(date_of_measurement, days_ago)
assert expected_age == Age.calculate(:day, date_of_birth, date_of_measurement)
end)
end
test "calculate age in completed weeks" do
date_of_measurement = ~D[2024-06-09]
days_of_birth = [{-1, 0}, {-7, 1}, {-16, 2}, {-30, 4}]
Enum.map(days_of_birth, fn {days_ago, expected_age} ->
date_of_birth = Date.add(date_of_measurement, days_ago)
assert expected_age == Age.calculate(:week, date_of_birth, date_of_measurement)
end)
end
test "calculate age in completed months" do
date_of_measurement = ~D[2024-06-09]
days_of_birth = [{-1, 0}, {-16, 0}, {-31, 1}, {-70, 2}, {-93, 3}]
Enum.map(days_of_birth, fn {days_ago, expected_age} ->
date_of_birth = Date.add(date_of_measurement, days_ago)
assert expected_age == Age.calculate(:month, date_of_birth, date_of_measurement)
end)
end
end
end