diff --git a/exercises/practice/phone-number/.meta/example.ex b/exercises/practice/phone-number/.meta/example.ex index 759d15858e..ae0240d3a5 100644 --- a/exercises/practice/phone-number/.meta/example.ex +++ b/exercises/practice/phone-number/.meta/example.ex @@ -36,10 +36,12 @@ defmodule PhoneNumber do end defp validate_length(number) do - if String.length(number) in 10..11 do - {:ok, number} - else - {:error, "incorrect number of digits"} + length = String.length(number) + + cond do + length < 10 -> {:error, "must not be fewer than 10 digits"} + length > 11 -> {:error, "must not be greater than 11 digits"} + true -> {:ok, number} end end diff --git a/exercises/practice/phone-number/.meta/tests.toml b/exercises/practice/phone-number/.meta/tests.toml index ee308c3e59..24dbf07a76 100644 --- a/exercises/practice/phone-number/.meta/tests.toml +++ b/exercises/practice/phone-number/.meta/tests.toml @@ -20,6 +20,11 @@ description = "cleans numbers with multiple spaces" [598d8432-0659-4019-a78b-1c6a73691d21] description = "invalid when 9 digits" +include = false + +[2de74156-f646-42b5-8638-0ef1d8b58bc2] +description = "invalid when 9 digits" +reimplements = "598d8432-0659-4019-a78b-1c6a73691d21" [57061c72-07b5-431f-9766-d97da7c4399d] description = "invalid when 11 digits does not start with a 1" @@ -32,6 +37,11 @@ description = "valid when 11 digits and starting with 1 even with punctuation" [c6a5f007-895a-4fc5-90bc-a7e70f9b5cad] description = "invalid when more than 11 digits" +include = false + +[4a1509b7-8953-4eec-981b-c483358ff531] +description = "invalid when more than 11 digits" +reimplements = "c6a5f007-895a-4fc5-90bc-a7e70f9b5cad" [63f38f37-53f6-4a5f-bd86-e9b404f10a60] description = "invalid with letters" diff --git a/exercises/practice/phone-number/test/phone_number_test.exs b/exercises/practice/phone-number/test/phone_number_test.exs index ec5b64df47..82fb90cd0d 100644 --- a/exercises/practice/phone-number/test/phone_number_test.exs +++ b/exercises/practice/phone-number/test/phone_number_test.exs @@ -18,7 +18,7 @@ defmodule PhoneNumberTest do @tag :pending test "invalid when 9 digits" do - assert PhoneNumber.clean("212555010") == {:error, "incorrect number of digits"} + assert PhoneNumber.clean("123456789") == {:error, "must not be fewer than 10 digits"} end @tag :pending @@ -38,7 +38,7 @@ defmodule PhoneNumberTest do @tag :pending test "invalid when more than 11 digits" do - assert PhoneNumber.clean("321234567890") == {:error, "incorrect number of digits"} + assert PhoneNumber.clean("321234567890") == {:error, "must not be greater than 11 digits"} end @tag :pending