From 108a9c821c961c32cc8ea968dfb6d95e4c3c3397 Mon Sep 17 00:00:00 2001 From: Pedro Medeiros Date: Mon, 18 Sep 2023 12:29:36 -0400 Subject: [PATCH] Update to crrect match spectation. On the problem specification for this exercise, we should follow what is defined. Matching the input error first in case both are invalid. For All your base exercise, we need it's valid to return input or output error when both are provided. This commit allows both to be returned from the tested function --- exercises/practice/all-your-base/.meta/example.ex | 8 ++++---- .../practice/all-your-base/test/all_your_base_test.exs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/exercises/practice/all-your-base/.meta/example.ex b/exercises/practice/all-your-base/.meta/example.ex index dad81d5946..072ed089e4 100644 --- a/exercises/practice/all-your-base/.meta/example.ex +++ b/exercises/practice/all-your-base/.meta/example.ex @@ -5,14 +5,14 @@ defmodule AllYourBase do """ @spec convert(list, integer, integer) :: {:ok, list} | {:error, String.t()} - def convert(_, _, output_base) when output_base < 2 do - {:error, "output base must be >= 2"} - end - def convert(_, input_base, _) when input_base < 2 do {:error, "input base must be >= 2"} end + def convert(_, _, output_base) when output_base < 2 do + {:error, "output base must be >= 2"} + end + def convert(digits, input_base, output_base) do if Enum.all?(digits, &(0 <= &1 && &1 < input_base)) do {:ok, do_convert(digits, input_base, output_base)} diff --git a/exercises/practice/all-your-base/test/all_your_base_test.exs b/exercises/practice/all-your-base/test/all_your_base_test.exs index 3ee560c572..b3a22d7c77 100644 --- a/exercises/practice/all-your-base/test/all_your_base_test.exs +++ b/exercises/practice/all-your-base/test/all_your_base_test.exs @@ -104,6 +104,6 @@ defmodule AllYourBaseTest do @tag :pending test "convert both bases are negative" do - assert AllYourBase.convert([1], -2, -7) == {:error, "output base must be >= 2"} + assert AllYourBase.convert([1], -2, -7) == {:error, "input base must be >= 2"} end end