Skip to content

Sync Phone Number tests with canonical specs #1362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions exercises/practice/phone-number/.meta/example.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions exercises/practice/phone-number/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/phone-number/test/phone_number_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down