Skip to content
Merged
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@ bin/configlet
bin/configlet.exe
/exercises/.nb-gradle/
**/out
exercises/.project
exercises/.settings/
exercises/*/bin
exercises/*/.classpath
exercises/*/.project
exercises/*/.settings/
_template/bin
_template/.classpath
_template/.project
_template/.settings/
6 changes: 3 additions & 3 deletions exercises/alphametics/src/test/java/AlphameticsTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import static org.junit.Assert.assertEquals;

import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.util.LinkedHashMap;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

public class AlphameticsTest {
@Rule
Expand All @@ -33,7 +33,7 @@ public void testUniqueValue() throws UnsolvablePuzzleException {
@Test
public void testLeadingZero() throws UnsolvablePuzzleException {
expectedException.expect(UnsolvablePuzzleException.class);
assertNull(new Alphametics("ACA + DD == BD").solve());
new Alphametics("ACA + DD == BD").solve();
}

@Ignore("Remove to run test")
Expand Down
1 change: 1 addition & 0 deletions exercises/anagram/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repositories {

dependencies {
testCompile "junit:junit:4.12"
testImplementation "org.assertj:assertj-core:3.15.0"
}

test {
Expand Down
87 changes: 60 additions & 27 deletions exercises/anagram/src/test/java/AnagramTest.java
Original file line number Diff line number Diff line change
@@ -1,121 +1,154 @@
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Ignore;
import org.junit.Test;

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

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

public class AnagramTest {


@Test
public void testNoMatches() {
Anagram detector = new Anagram("diaper");
assertTrue(detector.match(Arrays.asList("hello", "world", "zombies", "pants")).isEmpty());

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

@Ignore("Remove to run test")
@Test
public void testDetectMultipleAnagrams() {
Anagram detector = new Anagram("master");
List<String> anagrams = detector.match(Arrays.asList("stream", "pigeon", "maters"));
assertThat(anagrams, allOf(hasItem("maters"), hasItem("stream")));

assertThat(detector.match(Arrays.asList("stream", "pigeon", "maters")))
.containsExactlyInAnyOrder​("maters", "stream");
}

@Ignore("Remove to run test")
@Test
public void testEliminateAnagramSubsets() {
Anagram detector = new Anagram("good");
assertTrue(detector.match(Arrays.asList("dog", "goody")).isEmpty());

assertThat(detector.match(Arrays.asList("dog", "goody"))).isEmpty();
}

@Ignore("Remove to run test")
@Test
public void testDetectLongerAnagram() {
Anagram detector = new Anagram("listen");
List<String> anagrams = detector.match(Arrays.asList("enlists", "google", "inlets", "banana"));
assertThat(anagrams, hasItem("inlets"));

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

@Ignore("Remove to run test")
@Test
public void testDetectMultipleAnagramsForLongerWord() {
Anagram detector = new Anagram("allergy");
List<String> anagrams = detector.match(Arrays.asList("gallery", "ballerina",
"regally", "clergy",
"largely", "leading"));
assertThat(anagrams, allOf(hasItem("gallery"), hasItem("regally"), hasItem("largely")));
assertThat(
detector.match(
Arrays.asList(
"gallery",
"ballerina",
"regally",
"clergy",
"largely",
"leading")))
.containsExactlyInAnyOrder​("gallery", "regally", "largely");
}

@Ignore("Remove to run test")
@Test
public void testDetectsMultipleAnagramsWithDifferentCase() {
Anagram detector = new Anagram("nose");
List<String> anagrams = detector.match(Arrays.asList("Eons", "ONES"));
assertThat(anagrams, allOf(hasItem("Eons"), hasItem("ONES")));

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

@Ignore("Remove to run test")
@Test
public void testEliminateAnagramsWithSameChecksum() {
Anagram detector = new Anagram("mass");
assertTrue(detector.match(Collections.singletonList("last")).isEmpty());

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

@Ignore("Remove to run test")
@Test
public void testCaseInsensitiveWhenBothAnagramAndSubjectStartWithUpperCaseLetter() {
Anagram detector = new Anagram("Orchestra");
List<String> anagrams = detector.match(Arrays.asList("cashregister", "Carthorse", "radishes"));
assertThat(anagrams, hasItem("Carthorse"));

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

@Ignore("Remove to run test")
@Test
public void testCaseInsensitiveWhenSubjectStartsWithUpperCaseLetter() {
Anagram detector = new Anagram("Orchestra");
List<String> anagrams = detector.match(Arrays.asList("cashregister", "carthorse", "radishes"));
assertThat(anagrams, hasItem("carthorse"));

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

@Ignore("Remove to run test")
@Test
public void testCaseInsensitiveWhenAnagramStartsWithUpperCaseLetter() {
Anagram detector = new Anagram("orchestra");
List<String> anagrams = detector.match(Arrays.asList("cashregister", "Carthorse", "radishes"));
assertThat(anagrams, hasItem("Carthorse"));

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

@Ignore("Remove to run test")
@Test
public void testIdenticalWordRepeatedIsNotAnagram() {
Anagram detector = new Anagram("go");
assertTrue(detector.match(Collections.singletonList("go Go GO")).isEmpty());

assertThat(detector.match(Collections.singletonList("go Go GO")))
.isEmpty();
}

@Ignore("Remove to run test")
@Test
public void testAnagramMustUseAllLettersExactlyOnce() {
Anagram detector = new Anagram("tapper");
assertTrue(detector.match(Collections.singletonList("patter")).isEmpty());

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

@Ignore("Remove to run test")
@Test
public void testWordsAreNotAnagramsOfThemselvesCaseInsensitive() {
Anagram detector = new Anagram("BANANA");
assertTrue(detector.match(Arrays.asList("BANANA", "Banana", "banana")).isEmpty());

assertThat(detector.match(Arrays.asList("BANANA", "Banana", "banana")))
.isEmpty();
}

@Ignore("Remove to run test")
@Test
public void testWordsOtherThanThemselvesCanBeAnagrams() {
Anagram detector = new Anagram("LISTEN");
List<String> anagrams = detector.match(Arrays.asList("Listen", "Silent", "LISTEN"));
assertThat(anagrams, hasItem("Silent"));

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

}
1 change: 1 addition & 0 deletions exercises/circular-buffer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repositories {

dependencies {
testCompile "junit:junit:4.12"
testImplementation "org.assertj:assertj-core:3.15.0"
}

test {
Expand Down
45 changes: 22 additions & 23 deletions exercises/circular-buffer/src/test/java/CircularBufferTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Ignore;
import org.junit.Rule;
Expand All @@ -26,7 +25,7 @@ public void canReadItemJustWritten() throws BufferIOException {
CircularBuffer<Integer> buffer = new CircularBuffer<>(1);

buffer.write(1);
assertThat(buffer.read(), is(1));
assertThat(buffer.read()).isEqualTo(1);
}

@Ignore("Remove to run test")
Expand All @@ -35,7 +34,7 @@ public void canReadItemOnlyOnce() throws BufferIOException {
CircularBuffer<Integer> buffer = new CircularBuffer<>(1);

buffer.write(1);
assertThat(buffer.read(), is(1));
assertThat(buffer.read()).isEqualTo(1);

expectedException.expect(BufferIOException.class);
expectedException.expectMessage("Tried to read from empty buffer");
Expand All @@ -49,8 +48,8 @@ public void readsItemsInOrderWritten() throws BufferIOException {

buffer.write(1);
buffer.write(2);
assertThat(buffer.read(), is(1));
assertThat(buffer.read(), is(2));
assertThat(buffer.read()).isEqualTo(1);
assertThat(buffer.read()).isEqualTo(2);
}

@Ignore("Remove to run test")
Expand All @@ -70,9 +69,9 @@ public void readFreesUpSpaceForWrite() throws BufferIOException {
CircularBuffer<Integer> buffer = new CircularBuffer<>(1);

buffer.write(1);
assertThat(buffer.read(), is(1));
assertThat(buffer.read()).isEqualTo(1);
buffer.write(2);
assertThat(buffer.read(), is(2));
assertThat(buffer.read()).isEqualTo(2);
}

@Ignore("Remove to run test")
Expand All @@ -82,10 +81,10 @@ public void maintainsReadPositionAcrossWrites() throws BufferIOException {

buffer.write(1);
buffer.write(2);
assertThat(buffer.read(), is(1));
assertThat(buffer.read()).isEqualTo(1);
buffer.write(3);
assertThat(buffer.read(), is(2));
assertThat(buffer.read(), is(3));
assertThat(buffer.read()).isEqualTo(2);
assertThat(buffer.read()).isEqualTo(3);
}

@Ignore("Remove to run test")
Expand All @@ -108,7 +107,7 @@ public void clearFreesUpCapacity() throws BufferIOException {
buffer.write(1);
buffer.clear();
buffer.write(2);
assertThat(buffer.read(), is(2));
assertThat(buffer.read()).isEqualTo(2);
}

@Ignore("Remove to run test")
Expand All @@ -118,7 +117,7 @@ public void clearDoesNothingOnEmptyBuffer() throws BufferIOException {

buffer.clear();
buffer.write(1);
assertThat(buffer.read(), is(1));
assertThat(buffer.read()).isEqualTo(1);
}

@Ignore("Remove to run test")
Expand All @@ -128,8 +127,8 @@ public void overwriteActsLikeWriteOnNonFullBuffer() throws BufferIOException {

buffer.write(1);
buffer.overwrite(2);
assertThat(buffer.read(), is(1));
assertThat(buffer.read(), is(2));
assertThat(buffer.read()).isEqualTo(1);
assertThat(buffer.read()).isEqualTo(2);
}

@Ignore("Remove to run test")
Expand All @@ -140,8 +139,8 @@ public void overwriteRemovesOldestElementOnFullBuffer() throws BufferIOException
buffer.write(1);
buffer.write(2);
buffer.overwrite(3);
assertThat(buffer.read(), is(2));
assertThat(buffer.read(), is(3));
assertThat(buffer.read()).isEqualTo(2);
assertThat(buffer.read()).isEqualTo(3);
}

@Ignore("Remove to run test")
Expand All @@ -152,12 +151,12 @@ public void overwriteDoesntRemoveAnAlreadyReadElement() throws BufferIOException
buffer.write(1);
buffer.write(2);
buffer.write(3);
assertThat(buffer.read(), is(1));
assertThat(buffer.read()).isEqualTo(1);
buffer.write(4);
buffer.overwrite(5);
assertThat(buffer.read(), is(3));
assertThat(buffer.read(), is(4));
assertThat(buffer.read(), is(5));
assertThat(buffer.read()).isEqualTo(3);
assertThat(buffer.read()).isEqualTo(4);
assertThat(buffer.read()).isEqualTo(5);
}

@Ignore("Remove to run test")
Expand All @@ -170,8 +169,8 @@ public void initialClearDoesNotAffectWrappingAround() throws BufferIOException {
buffer.write(2);
buffer.overwrite(3);
buffer.overwrite(4);
assertThat(buffer.read(), is(3));
assertThat(buffer.read(), is(4));
assertThat(buffer.read()).isEqualTo(3);
assertThat(buffer.read()).isEqualTo(4);
expectedException.expect(BufferIOException.class);
expectedException.expectMessage("Tried to read from empty buffer");
buffer.read();
Expand Down
1 change: 1 addition & 0 deletions exercises/diamond/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repositories {

dependencies {
testCompile "junit:junit:4.12"
testImplementation "org.assertj:assertj-core:3.15.0"
}

test {
Expand Down
Loading