Skip to content

Commit

Permalink
Update to crrect match spectation.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pedrosnk committed Sep 19, 2023
1 parent 9169c53 commit 108a9c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions exercises/practice/all-your-base/.meta/example.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 108a9c8

Please sign in to comment.