Skip to content

Commit 8e2ab27

Browse files
authored
Sync tests for practice exercise phone number (exercism#2616)
* Sync tests for practice exercise phone number * Fixing reference resolution to match new exception messages
1 parent 37ca3f0 commit 8e2ab27

3 files changed

Lines changed: 36 additions & 9 deletions

File tree

exercises/practice/phone-number/.meta/src/reference/java/PhoneNumber.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ private String extractDigits(String dirtyNumber) {
2626

2727
private String normalize(String number) {
2828
if (number.length() < 10) {
29-
throw new IllegalArgumentException("incorrect number of digits");
29+
throw new IllegalArgumentException("must not be fewer than 10 digits");
3030
}
3131

3232
if (number.length() > 11) {
33-
throw new IllegalArgumentException("more than 11 digits");
33+
throw new IllegalArgumentException("must not be greater than 11 digits");
3434
}
3535

3636
if (number.length() == 11) {

exercises/practice/phone-number/.meta/tests.toml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[79666dce-e0f1-46de-95a1-563802913c35]
613
description = "cleans the number"
@@ -13,6 +20,11 @@ description = "cleans numbers with multiple spaces"
1320

1421
[598d8432-0659-4019-a78b-1c6a73691d21]
1522
description = "invalid when 9 digits"
23+
include = false
24+
25+
[2de74156-f646-42b5-8638-0ef1d8b58bc2]
26+
description = "invalid when 9 digits"
27+
reimplements = "598d8432-0659-4019-a78b-1c6a73691d21"
1628

1729
[57061c72-07b5-431f-9766-d97da7c4399d]
1830
description = "invalid when 11 digits does not start with a 1"
@@ -25,12 +37,27 @@ description = "valid when 11 digits and starting with 1 even with punctuation"
2537

2638
[c6a5f007-895a-4fc5-90bc-a7e70f9b5cad]
2739
description = "invalid when more than 11 digits"
40+
include = false
41+
42+
[4a1509b7-8953-4eec-981b-c483358ff531]
43+
description = "invalid when more than 11 digits"
44+
reimplements = "c6a5f007-895a-4fc5-90bc-a7e70f9b5cad"
2845

2946
[63f38f37-53f6-4a5f-bd86-e9b404f10a60]
3047
description = "invalid with letters"
48+
include = false
49+
50+
[eb8a1fc0-64e5-46d3-b0c6-33184208e28a]
51+
description = "invalid with letters"
52+
reimplements = "63f38f37-53f6-4a5f-bd86-e9b404f10a60"
3153

3254
[4bd97d90-52fd-45d3-b0db-06ab95b1244e]
3355
description = "invalid with punctuations"
56+
include = false
57+
58+
[065f6363-8394-4759-b080-e6c8c351dd1f]
59+
description = "invalid with punctuations"
60+
reimplements = "4bd97d90-52fd-45d3-b0db-06ab95b1244e"
3461

3562
[d77d07f8-873c-4b17-8978-5f66139bf7d7]
3663
description = "invalid if area code starts with 0"

exercises/practice/phone-number/src/test/java/PhoneNumberTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void invalidWhen9Digits() {
3939

4040
assertThatExceptionOfType(IllegalArgumentException.class)
4141
.isThrownBy(() -> new PhoneNumber("123456789"))
42-
.withMessage("incorrect number of digits");
42+
.withMessage("must not be fewer than 10 digits");
4343
}
4444

4545
@Ignore("Remove to run test")
@@ -74,22 +74,22 @@ public void validWhen11DigitsAndStartingWith1EvenWithPunctuation() {
7474
public void invalidWhenMoreThan11Digits() {
7575
assertThatExceptionOfType(IllegalArgumentException.class)
7676
.isThrownBy(() -> new PhoneNumber("321234567890"))
77-
.withMessage("more than 11 digits");
77+
.withMessage("must not be greater than 11 digits");
7878
}
7979

8080
@Ignore("Remove to run test")
8181
@Test
8282
public void invalidWithLetters() {
8383
assertThatExceptionOfType(IllegalArgumentException.class)
84-
.isThrownBy(() -> new PhoneNumber("123-abc-7890"))
84+
.isThrownBy(() -> new PhoneNumber("523-abc-7890"))
8585
.withMessage("letters not permitted");
8686
}
8787

8888
@Ignore("Remove to run test")
8989
@Test
9090
public void invalidWithPunctuations() {
9191
assertThatExceptionOfType(IllegalArgumentException.class)
92-
.isThrownBy(() -> new PhoneNumber("123-@:!-7890"))
92+
.isThrownBy(() -> new PhoneNumber("523-@:!-7890"))
9393
.withMessage("punctuations not permitted");
9494
}
9595

0 commit comments

Comments
 (0)