Skip to content
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

anagram: Sync tests #2762

Merged
merged 1 commit into from
Mar 31, 2024
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
1 change: 1 addition & 0 deletions exercises/practice/anagram/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"muzimuzhi",
"redshirt4",
"rohit1104",
"sanderploegsma",
"sjwarner-bp",
"SleeplessByte",
"Smarticles101",
Expand Down
6 changes: 6 additions & 0 deletions exercises/practice/anagram/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,9 @@ include = false
[33d3f67e-fbb9-49d3-a90e-0beb00861da7]
description = "words other than themselves can be anagrams"
reimplements = "a0705568-628c-4b55-9798-82e4acde51ca"

[a6854f66-eec1-4afd-a137-62ef2870c051]
description = "handles case of greek letters"

[fd3509e5-e3ba-409d-ac3d-a9ac84d13296]
description = "different characters may have the same bytes"
87 changes: 52 additions & 35 deletions exercises/practice/anagram/src/test/java/AnagramTest.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;

import static org.assertj.core.api.Assertions.assertThat;

public class AnagramTest {

@Test
public void testNoMatches() {
Anagram detector = new Anagram("diaper");

assertThat(
detector.match(
Arrays.asList("hello", "world", "zombies", "pants")))
.isEmpty();
detector.match(
Arrays.asList("hello", "world", "zombies", "pants")))
.isEmpty();
}

@Disabled("Remove to run test")
Expand All @@ -24,7 +24,7 @@ public void testDetectsTwoAnagrams() {
Anagram detector = new Anagram("solemn");

assertThat(detector.match(Arrays.asList("lemons", "cherry", "melons")))
.containsExactlyInAnyOrder("lemons", "melons");
.containsExactlyInAnyOrder("lemons", "melons");
}

@Disabled("Remove to run test")
Expand All @@ -41,25 +41,25 @@ public void testDetectLongerAnagram() {
Anagram detector = new Anagram("listen");

assertThat(
detector.match(
Arrays.asList("enlists", "google", "inlets", "banana")))
.containsExactlyInAnyOrder("inlets");
detector.match(
Arrays.asList("enlists", "google", "inlets", "banana")))
.containsExactlyInAnyOrder("inlets");
}

@Disabled("Remove to run test")
@Test
public void testDetectMultipleAnagramsForLongerWord() {
Anagram detector = new Anagram("allergy");
assertThat(
detector.match(
Arrays.asList(
"gallery",
"ballerina",
"regally",
"clergy",
"largely",
"leading")))
.containsExactlyInAnyOrder("gallery", "regally", "largely");
detector.match(
Arrays.asList(
"gallery",
"ballerina",
"regally",
"clergy",
"largely",
"leading")))
.containsExactlyInAnyOrder("gallery", "regally", "largely");
}

@Disabled("Remove to run test")
Expand All @@ -68,7 +68,7 @@ public void testDetectsMultipleAnagramsWithDifferentCase() {
Anagram detector = new Anagram("nose");

assertThat(detector.match(Arrays.asList("Eons", "ONES")))
.containsExactlyInAnyOrder("Eons", "ONES");
.containsExactlyInAnyOrder("Eons", "ONES");
}

@Disabled("Remove to run test")
Expand All @@ -77,7 +77,7 @@ public void testEliminateAnagramsWithSameChecksum() {
Anagram detector = new Anagram("mass");

assertThat(detector.match(Collections.singletonList("last")))
.isEmpty();
.isEmpty();
}

@Disabled("Remove to run test")
Expand All @@ -86,9 +86,9 @@ public void testCaseInsensitiveWhenBothAnagramAndSubjectStartWithUpperCaseLetter
Anagram detector = new Anagram("Orchestra");

assertThat(
detector.match(
Arrays.asList("cashregister", "Carthorse", "radishes")))
.containsExactlyInAnyOrder("Carthorse");
detector.match(
Arrays.asList("cashregister", "Carthorse", "radishes")))
.containsExactlyInAnyOrder("Carthorse");
}

@Disabled("Remove to run test")
Expand All @@ -97,9 +97,9 @@ public void testCaseInsensitiveWhenSubjectStartsWithUpperCaseLetter() {
Anagram detector = new Anagram("Orchestra");

assertThat(
detector.match(
Arrays.asList("cashregister", "carthorse", "radishes")))
.containsExactlyInAnyOrder("carthorse");
detector.match(
Arrays.asList("cashregister", "carthorse", "radishes")))
.containsExactlyInAnyOrder("carthorse");
}

@Disabled("Remove to run test")
Expand All @@ -108,9 +108,9 @@ public void testCaseInsensitiveWhenAnagramStartsWithUpperCaseLetter() {
Anagram detector = new Anagram("orchestra");

assertThat(
detector.match(
Arrays.asList("cashregister", "Carthorse", "radishes")))
.containsExactlyInAnyOrder("Carthorse");
detector.match(
Arrays.asList("cashregister", "Carthorse", "radishes")))
.containsExactlyInAnyOrder("Carthorse");
}

@Disabled("Remove to run test")
Expand All @@ -119,7 +119,7 @@ public void testIdenticalWordRepeatedIsNotAnagram() {
Anagram detector = new Anagram("go");

assertThat(detector.match(Collections.singletonList("goGoGO")))
.isEmpty();
.isEmpty();
}

@Disabled("Remove to run test")
Expand All @@ -128,7 +128,7 @@ public void testAnagramMustUseAllLettersExactlyOnce() {
Anagram detector = new Anagram("tapper");

assertThat(detector.match(Collections.singletonList("patter")))
.isEmpty();
.isEmpty();
}

@Disabled("Remove to run test")
Expand All @@ -137,7 +137,7 @@ public void testWordsAreNotAnagramsOfThemselvesCaseInsensitive() {
Anagram detector = new Anagram("BANANA");

assertThat(detector.match(Collections.singletonList("BANANA")))
.isEmpty();
.isEmpty();
}

@Disabled("Remove to run test")
Expand All @@ -146,7 +146,7 @@ public void testWordsAreNotAnagramsOfThemselvesEvenIfLetterCaseIsPartiallyDiffer
Anagram detector = new Anagram("BANANA");

assertThat(detector.match(Collections.singletonList("Banana")))
.isEmpty();
.isEmpty();
}

@Disabled("Remove to run test")
Expand All @@ -155,7 +155,7 @@ public void testWordsAreNotAnagramsOfThemselvesEvenIfLetterCaseIsCompletelyDiffe
Anagram detector = new Anagram("BANANA");

assertThat(detector.match(Collections.singletonList("banana")))
.isEmpty();
.isEmpty();
}

@Disabled("Remove to run test")
Expand All @@ -164,7 +164,24 @@ public void testWordsOtherThanThemselvesCanBeAnagrams() {
Anagram detector = new Anagram("LISTEN");

assertThat(detector.match(Arrays.asList("LISTEN", "Silent")))
.containsExactlyInAnyOrder("Silent");
.containsExactlyInAnyOrder("Silent");
}

@Disabled("Remove to run test")
@Test
public void testHandlesCaseOfGreekLetters() {
Anagram detector = new Anagram("ΑΒΓ");

assertThat(detector.match(Arrays.asList("ΒΓΑ", "ΒΓΔ", "γβα", "αβγ")))
.containsExactlyInAnyOrder("ΒΓΑ", "γβα");
}

@Disabled("Remove to run test")
@Test
public void testDifferentCharactersWithSameBytes() {
Anagram detector = new Anagram("a⬂");

assertThat(detector.match(Collections.singletonList("€a")))
.isEmpty();
}
}