From 7f886a7fd06acfba5e9c511b49a727d871c53a57 Mon Sep 17 00:00:00 2001 From: Joao P Dubas Date: Sat, 26 Jun 2021 19:07:51 +0000 Subject: [PATCH] [day-05] test imc logic --- test/wabanex/imc_test.exs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/wabanex/imc_test.exs diff --git a/test/wabanex/imc_test.exs b/test/wabanex/imc_test.exs new file mode 100644 index 0000000..eda3b51 --- /dev/null +++ b/test/wabanex/imc_test.exs @@ -0,0 +1,31 @@ +defmodule Wabanex.IMCTest do + use ExUnit.Case, async: true + + alias Wabanex.IMC + + describe "calculate/1" do + test "when the file exists returns calculated values" do + params = %{"filename" => "students.csv"} + + imc = IMC.calculate(params) + + expected_imc = %{ + "Americo" => 24.508945765204302, + "Ana" => 21.30394857667585, + "Claudio" => 30.42184964845863, + "João" => 31.88775510204082, + "Luiz" => 27.777777777777775 + } + + assert {:ok, expected_imc} == imc + end + + test "when the file is unavailable returns an error" do + params = %{"filename" => "unavailable.csv"} + + imc = IMC.calculate(params) + + assert {:error, "Error while opening the file"} == imc + end + end +end