@@ -18,15 +18,15 @@ static int solve(int a, int b) { @ParameterizedTest @CsvSource({ - "0, 0, 0", - "0, 1, 1", - "0, 3, 2", - "0, 7, 3", - "0, 10, 2", - "31, 14, 2", - "31, 31, 0", - "7, 17, 3", - "330274332, 199260599, 19", + "0, 0, 0", + "0, 1, 1", + "0, 3, 2", + "0, 7, 3", + "0, 10, 2", + "31, 14, 2", + "31, 31, 0", + "7, 17, 3", + "330274332, 199260599, 19", }) void countsDifferingBits(int a, int b, int expected) { assertThat(solve(a, b)).isEqualTo(expected); diff --git a/src/test/java/io/github/diegourban/algorithms/problems/bit/FindUniqueIdTest.java b/src/test/java/io/github/diegourban/algorithms/problems/bit/FindUniqueIdTest.java index 81ce5ec..5835edc 100644 --- a/src/test/java/io/github/diegourban/algorithms/problems/bit/FindUniqueIdTest.java +++ b/src/test/java/io/github/diegourban/algorithms/problems/bit/FindUniqueIdTest.java @@ -1,9 +1,9 @@ package io.github.diegourban.algorithms.problems.bit; -import org.junit.jupiter.api.Test; - import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.Test; + /** * The Stolen Breakfast Drone — Interview Cake. *
@@ -23,16 +23,16 @@ static int solve(int[] ids) { @Test void findsUniqueIdAtTheStart() { - assertThat(solve(new int[]{1, 2, 2})).isOne(); + assertThat(solve(new int[] {1, 2, 2})).isOne(); } @Test void findsUniqueIdInTheMiddle() { - assertThat(solve(new int[]{1, 2, 1})).isEqualTo(2); + assertThat(solve(new int[] {1, 2, 1})).isEqualTo(2); } @Test void findsUniqueIdAmongManyPairs() { - assertThat(solve(new int[]{1, 5, 8, 2, 4, 9, 9, 8, 4, 1, 2})).isEqualTo(5); + assertThat(solve(new int[] {1, 5, 8, 2, 4, 9, 9, 8, 4, 1, 2})).isEqualTo(5); } } diff --git a/src/test/java/io/github/diegourban/algorithms/problems/bit/ParityTest.java b/src/test/java/io/github/diegourban/algorithms/problems/bit/ParityTest.java index a082ce7..f090e11 100644 --- a/src/test/java/io/github/diegourban/algorithms/problems/bit/ParityTest.java +++ b/src/test/java/io/github/diegourban/algorithms/problems/bit/ParityTest.java @@ -1,9 +1,9 @@ package io.github.diegourban.algorithms.problems.bit; -import org.junit.jupiter.api.Test; - import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.Test; + /** * Parity — beecrowd (formerly URI Online Judge) 2176. *
@@ -41,7 +41,8 @@ void oddCountOfOnesAppendsOne() { @Test void handlesHundredBits() { - var bits = "0101011001101010011001010101001010101010101010101011010010101010101011010110101010000101010101010101"; + var bits = + "0101011001101010011001010101001010101010101010101011010010101010101011010110101010000101010101010101"; assertThat(solve(bits)).isEqualTo(bits + "1"); } } diff --git a/src/test/java/io/github/diegourban/algorithms/problems/bit/ToCarryOrNotToCarryTest.java b/src/test/java/io/github/diegourban/algorithms/problems/bit/ToCarryOrNotToCarryTest.java index ec32db0..7720389 100644 --- a/src/test/java/io/github/diegourban/algorithms/problems/bit/ToCarryOrNotToCarryTest.java +++ b/src/test/java/io/github/diegourban/algorithms/problems/bit/ToCarryOrNotToCarryTest.java @@ -1,16 +1,15 @@ package io.github.diegourban.algorithms.problems.bit; +import static org.assertj.core.api.Assertions.assertThat; + import io.github.diegourban.algorithms.io.Reader; import io.github.diegourban.algorithms.testing.SampleLoader; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - import java.io.EOFException; import java.io.IOException; import java.io.InputStream; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; /** * To Carry or not to Carry — beecrowd (formerly URI Online Judge) 1026. diff --git a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/EqualSidesOfAnArrayTest.java b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/EqualSidesOfAnArrayTest.java index 020a2c3..d47f364 100644 --- a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/EqualSidesOfAnArrayTest.java +++ b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/EqualSidesOfAnArrayTest.java @@ -1,10 +1,9 @@ package io.github.diegourban.algorithms.problems.datastructure.array; -import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.Test; /** * Equal Sides Of An Array — Codewars (6 kyu). @@ -28,43 +27,43 @@ static int solve(int[] arr) { @Test void findsMiddleOfUniformArray() { - assertThat(solve(new int[]{1, 1, 1})).isEqualTo(1); + assertThat(solve(new int[] {1, 1, 1})).isEqualTo(1); } @Test void returnsMinusOneWhenNoIndexBalances() { - assertThat(solve(new int[]{1, 1, 2})).isEqualTo(-1); - assertThat(solve(new int[]{1, 1})).isEqualTo(-1); + assertThat(solve(new int[] {1, 1, 2})).isEqualTo(-1); + assertThat(solve(new int[] {1, 1})).isEqualTo(-1); } @Test void returnsMinusOneForEmptyArray() { - assertThat(solve(new int[]{})).isEqualTo(-1); + assertThat(solve(new int[] {})).isEqualTo(-1); } @Test void balancesSymmetricSides() { - assertThat(solve(new int[]{2, 50, 3, 50, 2})).isEqualTo(2); + assertThat(solve(new int[] {2, 50, 3, 50, 2})).isEqualTo(2); } @Test void balancesAsymmetricSidesWithEqualSums() { - assertThat(solve(new int[]{20, 30, 3, 48, 2})).isEqualTo(2); + assertThat(solve(new int[] {20, 30, 3, 48, 2})).isEqualTo(2); } @Test void firstIndexBalancesWhenTheRestSumsToZero() { - assertThat(solve(new int[]{20, 10, -80, 10, 10, 15, 35})).isEqualTo(0); + assertThat(solve(new int[] {20, 10, -80, 10, 10, 15, 35})).isEqualTo(0); } @Test void lastIndexBalancesWhenTheRestSumsToZero() { - assertThat(solve(new int[]{1, -1, 5})).isEqualTo(2); + assertThat(solve(new int[] {1, -1, 5})).isEqualTo(2); } @Test void handlesNegativeValues() { - assertThat(solve(new int[]{20, -30, 3, -30, 20})).isEqualTo(2); - assertThat(solve(new int[]{1, 2, 3, -30, 3, -30, 6})).isEqualTo(4); + assertThat(solve(new int[] {20, -30, 3, -30, 20})).isEqualTo(2); + assertThat(solve(new int[] {1, 2, 3, -30, 3, -30, 6})).isEqualTo(4); } } diff --git a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/LargestDifferenceTest.java b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/LargestDifferenceTest.java index 64a176c..41b44c5 100644 --- a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/LargestDifferenceTest.java +++ b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/LargestDifferenceTest.java @@ -1,9 +1,9 @@ package io.github.diegourban.algorithms.problems.datastructure.array; -import org.junit.jupiter.api.Test; - import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.Test; + /** * Largest Difference in Increasing Indexes — Codewars (5 kyu). *
@@ -29,29 +29,29 @@ static int solve(int[] data) { @Test void singleElementHasNoDifference() { - assertThat(solve(new int[]{0})).isZero(); + assertThat(solve(new int[] {0})).isZero(); } @Test void strictlyDecreasingHasNoDifference() { - assertThat(solve(new int[]{2, 1})).isZero(); - assertThat(solve(new int[]{3, 2, 1})).isZero(); + assertThat(solve(new int[] {2, 1})).isZero(); + assertThat(solve(new int[] {3, 2, 1})).isZero(); } @Test void equalValuesCount() { - assertThat(solve(new int[]{1, 1})).isEqualTo(1); - assertThat(solve(new int[]{1, 1, 1})).isEqualTo(2); + assertThat(solve(new int[] {1, 1})).isEqualTo(1); + assertThat(solve(new int[] {1, 1, 1})).isEqualTo(2); } @Test void increasingPairSpansTheArray() { - assertThat(solve(new int[]{1, 2})).isEqualTo(1); - assertThat(solve(new int[]{1, 1, 3})).isEqualTo(2); + assertThat(solve(new int[] {1, 2})).isEqualTo(1); + assertThat(solve(new int[] {1, 1, 3})).isEqualTo(2); } @Test void findsWidestPairInMixedData() { - assertThat(solve(new int[]{9, 4, 1, 10, 3, 4, 0, -1, -2})).isEqualTo(4); + assertThat(solve(new int[] {9, 4, 1, 10, 3, 4, 0, -1, -2})).isEqualTo(4); } } diff --git a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/SingleRiffleCheckTest.java b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/SingleRiffleCheckTest.java index e32f4f2..6eea47e 100644 --- a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/SingleRiffleCheckTest.java +++ b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/SingleRiffleCheckTest.java @@ -1,9 +1,9 @@ package io.github.diegourban.algorithms.problems.datastructure.array; -import org.junit.jupiter.api.Test; - import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.Test; + /** * Single Riffle Check — Interview Cake. *
@@ -31,36 +31,40 @@ static boolean solve(int[] half1, int[] half2, int[] deck) {
@Test
void interleavedHalvesAreARiffle() {
- assertThat(solve(new int[]{1, 3, 5}, new int[]{2, 4, 6}, new int[]{1, 2, 3, 4, 5, 6})).isTrue();
+ assertThat(solve(new int[] {1, 3, 5}, new int[] {2, 4, 6}, new int[] {1, 2, 3, 4, 5, 6}))
+ .isTrue();
}
@Test
void oneHalfThenTheOtherIsARiffle() {
- assertThat(solve(new int[]{1, 2}, new int[]{3, 4}, new int[]{1, 2, 3, 4})).isTrue();
+ assertThat(solve(new int[] {1, 2}, new int[] {3, 4}, new int[] {1, 2, 3, 4}))
+ .isTrue();
}
@Test
void unevenInterleavingIsARiffle() {
- assertThat(solve(new int[]{1, 3, 5}, new int[]{2, 4, 6}, new int[]{1, 3, 2, 5, 4, 6})).isTrue();
+ assertThat(solve(new int[] {1, 3, 5}, new int[] {2, 4, 6}, new int[] {1, 3, 2, 5, 4, 6}))
+ .isTrue();
}
@Test
void cardOutOfOrderWithinItsHalfIsNotARiffle() {
- assertThat(solve(new int[]{1, 3, 5}, new int[]{2, 4, 6}, new int[]{3, 1, 2, 4, 5, 6})).isFalse();
+ assertThat(solve(new int[] {1, 3, 5}, new int[] {2, 4, 6}, new int[] {3, 1, 2, 4, 5, 6}))
+ .isFalse();
}
@Test
void unknownCardIsNotARiffle() {
- assertThat(solve(new int[]{1}, new int[]{2}, new int[]{1, 7})).isFalse();
+ assertThat(solve(new int[] {1}, new int[] {2}, new int[] {1, 7})).isFalse();
}
@Test
void missingCardsAreNotARiffle() {
- assertThat(solve(new int[]{1, 3}, new int[]{2}, new int[]{1, 2})).isFalse();
+ assertThat(solve(new int[] {1, 3}, new int[] {2}, new int[] {1, 2})).isFalse();
}
@Test
void emptyDeckOfEmptyHalvesIsARiffle() {
- assertThat(solve(new int[]{}, new int[]{}, new int[]{})).isTrue();
+ assertThat(solve(new int[] {}, new int[] {}, new int[] {})).isTrue();
}
}
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/TheForceAwakensTest.java b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/TheForceAwakensTest.java
index 27c66fb..81287cd 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/TheForceAwakensTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/array/TheForceAwakensTest.java
@@ -1,16 +1,15 @@
package io.github.diegourban.algorithms.problems.datastructure.array;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.io.Reader;
import io.github.diegourban.algorithms.testing.SampleLoader;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ValueSource;
-
import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
/**
* The Force Awakens — beecrowd (formerly URI Online Judge) 2163.
@@ -26,8 +25,7 @@ class TheForceAwakensTest {
private static final int GUARD = 7;
/** A 1-based terrain position. */
- record Position(int row, int column) {
- }
+ record Position(int row, int column) {}
static Optional
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/FindRepeatBeastModeTest.java b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/FindRepeatBeastModeTest.java
index 8658769..f10ceec 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/FindRepeatBeastModeTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/FindRepeatBeastModeTest.java
@@ -1,9 +1,9 @@
package io.github.diegourban.algorithms.problems.datastructure.linkedlist;
-import org.junit.jupiter.api.Test;
-
import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
+
/**
* Find Repeat, Space Edition BEAST MODE — Interview Cake.
*
@@ -24,7 +24,9 @@ static int solve(int[] numbers) {
}
var cycleLength = 1;
- for (var position = next(numbers, positionInCycle); position != positionInCycle; position = next(numbers, position)) {
+ for (var position = next(numbers, positionInCycle);
+ position != positionInCycle;
+ position = next(numbers, position)) {
cycleLength++;
}
@@ -46,31 +48,31 @@ private static int next(int[] numbers, int position) {
@Test
void smallestInputsRepeatOne() {
- assertThat(solve(new int[]{1, 1})).isOne();
- assertThat(solve(new int[]{1, 1, 1})).isOne();
+ assertThat(solve(new int[] {1, 1})).isOne();
+ assertThat(solve(new int[] {1, 1, 1})).isOne();
}
@Test
void findsAdjacentRepeatAnywhereInTheRange() {
- assertThat(solve(new int[]{1, 1, 2, 3, 4, 5, 6, 7, 8, 9})).isOne();
- assertThat(solve(new int[]{1, 2, 2, 3, 4, 5, 6, 7, 8, 9})).isEqualTo(2);
- assertThat(solve(new int[]{1, 2, 3, 3, 4, 5, 6, 7, 8, 9})).isEqualTo(3);
- assertThat(solve(new int[]{1, 2, 3, 4, 4, 5, 6, 7, 8, 9})).isEqualTo(4);
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 5, 6, 7, 8, 9})).isEqualTo(5);
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 6, 6, 7, 8, 9})).isEqualTo(6);
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 6, 7, 7, 8, 9})).isEqualTo(7);
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 8, 9})).isEqualTo(8);
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 9})).isEqualTo(9);
+ assertThat(solve(new int[] {1, 1, 2, 3, 4, 5, 6, 7, 8, 9})).isOne();
+ assertThat(solve(new int[] {1, 2, 2, 3, 4, 5, 6, 7, 8, 9})).isEqualTo(2);
+ assertThat(solve(new int[] {1, 2, 3, 3, 4, 5, 6, 7, 8, 9})).isEqualTo(3);
+ assertThat(solve(new int[] {1, 2, 3, 4, 4, 5, 6, 7, 8, 9})).isEqualTo(4);
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 5, 6, 7, 8, 9})).isEqualTo(5);
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 6, 6, 7, 8, 9})).isEqualTo(6);
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 6, 7, 7, 8, 9})).isEqualTo(7);
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 8, 9})).isEqualTo(8);
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 9})).isEqualTo(9);
}
@Test
void findsRepeatRegardlessOfPosition() {
- assertThat(solve(new int[]{1, 2, 1, 3, 4, 5, 6, 7, 8})).isOne();
- assertThat(solve(new int[]{1, 2, 3, 1, 4, 5, 6, 7, 8})).isOne();
- assertThat(solve(new int[]{1, 2, 3, 4, 1, 5, 6, 7, 8})).isOne();
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 1, 6, 7, 8})).isOne();
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 6, 1, 7, 8})).isOne();
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 6, 7, 1, 8})).isOne();
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 1})).isOne();
+ assertThat(solve(new int[] {1, 2, 1, 3, 4, 5, 6, 7, 8})).isOne();
+ assertThat(solve(new int[] {1, 2, 3, 1, 4, 5, 6, 7, 8})).isOne();
+ assertThat(solve(new int[] {1, 2, 3, 4, 1, 5, 6, 7, 8})).isOne();
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 1, 6, 7, 8})).isOne();
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 6, 1, 7, 8})).isOne();
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 6, 7, 1, 8})).isOne();
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 1})).isOne();
}
}
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/LinkedListCycleTest.java b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/LinkedListCycleTest.java
index 0c26ea5..ec88c5c 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/LinkedListCycleTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/LinkedListCycleTest.java
@@ -1,11 +1,11 @@
package io.github.diegourban.algorithms.problems.datastructure.linkedlist;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.datastructure.Element;
import io.github.diegourban.algorithms.datastructure.linkedlist.LinkedListNode;
import org.junit.jupiter.api.Test;
-import static org.assertj.core.api.Assertions.assertThat;
-
/**
* Does This Linked List Have A Cycle? — Interview Cake.
*
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/MergeSortedLinkedListsTest.java b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/MergeSortedLinkedListsTest.java
index 5b4dac7..354d948 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/MergeSortedLinkedListsTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/MergeSortedLinkedListsTest.java
@@ -1,11 +1,10 @@
package io.github.diegourban.algorithms.problems.datastructure.linkedlist;
-import org.junit.jupiter.api.Test;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
/**
* Merge two sorted linked lists — HackerRank.
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/ReverseLinkedListTest.java b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/ReverseLinkedListTest.java
index 481d141..9823b50 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/ReverseLinkedListTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/linkedlist/ReverseLinkedListTest.java
@@ -1,12 +1,12 @@
package io.github.diegourban.algorithms.problems.datastructure.linkedlist;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.datastructure.Element;
import io.github.diegourban.algorithms.datastructure.linkedlist.LinkedList;
import io.github.diegourban.algorithms.datastructure.linkedlist.LinkedListNode;
import org.junit.jupiter.api.Test;
-import static org.assertj.core.api.Assertions.assertThat;
-
/**
* Reverse A Linked List — Interview Cake.
*
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/map/DroughtTest.java b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/map/DroughtTest.java
index 97ecfbf..c881edf 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/map/DroughtTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/map/DroughtTest.java
@@ -1,11 +1,10 @@
package io.github.diegourban.algorithms.problems.datastructure.map;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.entry;
+
import io.github.diegourban.algorithms.io.Reader;
import io.github.diegourban.algorithms.testing.SampleLoader;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ValueSource;
-
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
@@ -16,9 +15,9 @@
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.stream.Collectors;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.entry;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
/**
* Drought — beecrowd (formerly URI Online Judge) 1023.
@@ -30,15 +29,13 @@
*/
class DroughtTest {
- record Property(int residents, int consumption) {
- }
+ record Property(int residents, int consumption) {}
/**
* @param residentsByConsumption residents per per-capita consumption, ascending by consumption
* @param averageConsumption total consumption over total residents, truncated to 2 decimals
*/
- record City(SortedMap
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/stack/LargestStackTest.java b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/stack/LargestStackTest.java
index 9f180f0..8865c4d 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/stack/LargestStackTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/stack/LargestStackTest.java
@@ -1,11 +1,10 @@
package io.github.diegourban.algorithms.problems.datastructure.stack;
-import org.junit.jupiter.api.Test;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayDeque;
import java.util.Deque;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
/**
* Largest Stack — Interview Cake.
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/stack/ParenthesisBalanceTest.java b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/stack/ParenthesisBalanceTest.java
index 9e8d315..7a335a8 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/stack/ParenthesisBalanceTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/stack/ParenthesisBalanceTest.java
@@ -1,16 +1,15 @@
package io.github.diegourban.algorithms.problems.datastructure.stack;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.io.Reader;
import io.github.diegourban.algorithms.testing.SampleLoader;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ValueSource;
-
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
/**
* Parenthesis Balance I — beecrowd (formerly URI Online Judge) 1068.
@@ -32,7 +31,7 @@ static boolean solve(String expression) {
return false;
}
}
- default -> { }
+ default -> {}
}
}
return depth == 0;
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/tree/BalancedBinaryTreeTest.java b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/tree/BalancedBinaryTreeTest.java
index 0bf010c..b8be54c 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/tree/BalancedBinaryTreeTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/tree/BalancedBinaryTreeTest.java
@@ -1,12 +1,11 @@
package io.github.diegourban.algorithms.problems.datastructure.tree;
-import io.github.diegourban.algorithms.datastructure.binarytree.BinaryTreeNode;
-import org.junit.jupiter.api.Test;
+import static org.assertj.core.api.Assertions.assertThat;
+import io.github.diegourban.algorithms.datastructure.binarytree.BinaryTreeNode;
import java.util.ArrayDeque;
import java.util.ArrayList;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
/**
* Balanced Binary Tree — Interview Cake.
@@ -18,8 +17,7 @@
*/
class BalancedBinaryTreeTest {
- private record NodeDepth(BinaryTreeNode node, int depth) {
- }
+ private record NodeDepth(BinaryTreeNode node, int depth) {}
static boolean solve(BinaryTreeNode root) {
if (root == null) {
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/tree/BinarySearchTreeCheckerTest.java b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/tree/BinarySearchTreeCheckerTest.java
index c5f7759..7f3cdbe 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/tree/BinarySearchTreeCheckerTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/tree/BinarySearchTreeCheckerTest.java
@@ -1,11 +1,10 @@
package io.github.diegourban.algorithms.problems.datastructure.tree;
-import io.github.diegourban.algorithms.datastructure.binarytree.BinaryTreeNode;
-import org.junit.jupiter.api.Test;
+import static org.assertj.core.api.Assertions.assertThat;
+import io.github.diegourban.algorithms.datastructure.binarytree.BinaryTreeNode;
import java.util.ArrayDeque;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
/**
* Binary Search Tree Checker — Interview Cake.
@@ -17,8 +16,7 @@
*/
class BinarySearchTreeCheckerTest {
- private record NodeBounds(BinaryTreeNode node, long lower, long upper) {
- }
+ private record NodeBounds(BinaryTreeNode node, long lower, long upper) {}
static boolean solve(BinaryTreeNode root) {
if (root == null) {
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/tree/SecondLargestItemInBstTest.java b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/tree/SecondLargestItemInBstTest.java
index a11ddf9..f202912 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/tree/SecondLargestItemInBstTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/tree/SecondLargestItemInBstTest.java
@@ -1,11 +1,11 @@
package io.github.diegourban.algorithms.problems.datastructure.tree;
-import io.github.diegourban.algorithms.datastructure.binarytree.BinaryTreeNode;
-import org.junit.jupiter.api.Test;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import io.github.diegourban.algorithms.datastructure.binarytree.BinaryTreeNode;
+import org.junit.jupiter.api.Test;
+
/**
* Find The Second Largest Item In A Binary Search Tree — Interview Cake.
*
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/trie/MillionGazillionTest.java b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/trie/MillionGazillionTest.java
index 5072914..f631e2b 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/datastructure/trie/MillionGazillionTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/datastructure/trie/MillionGazillionTest.java
@@ -1,11 +1,10 @@
package io.github.diegourban.algorithms.problems.datastructure.trie;
-import org.junit.jupiter.api.Test;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
/**
* MillionGazillion — Interview Cake.
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/dp/CakeThiefTest.java b/src/test/java/io/github/diegourban/algorithms/problems/dp/CakeThiefTest.java
index 8e76f74..c76c087 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/dp/CakeThiefTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/dp/CakeThiefTest.java
@@ -1,10 +1,10 @@
package io.github.diegourban.algorithms.problems.dp;
-import org.junit.jupiter.api.Test;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import org.junit.jupiter.api.Test;
+
/**
* The Cake Thief — Interview Cake.
*
@@ -16,8 +16,7 @@
*/
class CakeThiefTest {
- record Box(int weight, int value) {
- }
+ record Box(int weight, int value) {}
static class InfinityException extends RuntimeException {
InfinityException() {
@@ -45,14 +44,14 @@ static long solve(Box[] boxes, int capacity) {
@Test
void takesAsManyOfTheBestBoxesAsFit() {
- var boxes = new Box[]{new Box(1, 3), new Box(2, 2), new Box(4, 5)};
+ var boxes = new Box[] {new Box(1, 3), new Box(2, 2), new Box(4, 5)};
assertThat(solve(boxes, 15)).isEqualTo(45L);
}
@Test
void weightlessValuableBoxIsInfinite() {
- var boxes = new Box[]{new Box(0, 1), new Box(2, 2)};
+ var boxes = new Box[] {new Box(0, 1), new Box(2, 2)};
assertThatExceptionOfType(InfinityException.class).isThrownBy(() -> solve(boxes, 5));
}
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/greedy/BanknotesAndCoinsTest.java b/src/test/java/io/github/diegourban/algorithms/problems/greedy/BanknotesAndCoinsTest.java
index 2a53d68..c5a5236 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/greedy/BanknotesAndCoinsTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/greedy/BanknotesAndCoinsTest.java
@@ -1,13 +1,12 @@
package io.github.diegourban.algorithms.problems.greedy;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.CsvSource;
+import static org.assertj.core.api.Assertions.assertThat;
import java.math.BigDecimal;
import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
/**
* Banknotes and Coins — beecrowd (formerly URI Online Judge) 1021.
@@ -23,16 +22,16 @@ class BanknotesAndCoinsTest {
static final List
@@ -40,12 +39,12 @@ static String run(InputStream in) throws IOException {
@ParameterizedTest
@CsvSource({
- "8, 12, 4",
- "9, 27, 9",
- "259, 111, 37",
- "1, 1, 1",
- "7, 13, 1",
- "1000, 1000, 1000",
+ "8, 12, 4",
+ "9, 27, 9",
+ "259, 111, 37",
+ "1, 1, 1",
+ "7, 13, 1",
+ "1000, 1000, 1000",
})
void largestPileSizeIsTheGcd(int f1, int f2, long expected) {
assertThat(solve(f1, f2)).isEqualTo(expected);
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/CommonDenominatorsTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/CommonDenominatorsTest.java
index 8fa797e..0935916 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/CommonDenominatorsTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/CommonDenominatorsTest.java
@@ -1,11 +1,10 @@
package io.github.diegourban.algorithms.problems.math;
-import io.github.diegourban.algorithms.math.NumberTheory;
-import org.junit.jupiter.api.Test;
+import static org.assertj.core.api.Assertions.assertThat;
+import io.github.diegourban.algorithms.math.NumberTheory;
import java.util.Arrays;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
/**
* Common Denominators — Codewars (5 kyu).
@@ -24,23 +23,27 @@ static String solve(long[][] fractions) {
var lcm = NumberTheory.lcm(Arrays.stream(fractions).mapToLong(f -> f[1]).toArray());
var result = new StringBuilder();
for (var f : fractions) {
- result.append('(').append(f[0] * (lcm / f[1])).append(',').append(lcm).append(')');
+ result.append('(')
+ .append(f[0] * (lcm / f[1]))
+ .append(',')
+ .append(lcm)
+ .append(')');
}
return result.toString();
}
@Test
void emptyListGivesEmptyString() {
- assertThat(solve(new long[][]{})).isEmpty();
+ assertThat(solve(new long[][] {})).isEmpty();
}
@Test
void unitFractions() {
- assertThat(solve(new long[][]{{1, 2}, {1, 3}, {1, 4}})).isEqualTo("(6,12)(4,12)(3,12)");
+ assertThat(solve(new long[][] {{1, 2}, {1, 3}, {1, 4}})).isEqualTo("(6,12)(4,12)(3,12)");
}
@Test
void coprimeDenominators() {
- assertThat(solve(new long[][]{{1, 130}, {1, 131}, {1, 4}})).isEqualTo("(262,34060)(260,34060)(8515,34060)");
+ assertThat(solve(new long[][] {{1, 130}, {1, 131}, {1, 4}})).isEqualTo("(262,34060)(260,34060)(8515,34060)");
}
}
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/DivisorsTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/DivisorsTest.java
index 2b141f5..5bf783c 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/DivisorsTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/DivisorsTest.java
@@ -1,11 +1,10 @@
package io.github.diegourban.algorithms.problems.math;
-import org.junit.jupiter.api.Test;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
/**
* Divisors I — beecrowd (formerly URI Online Judge) 1157.
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/EasyLineTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/EasyLineTest.java
index b09b2e7..0d4fb8f 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/EasyLineTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/EasyLineTest.java
@@ -1,13 +1,12 @@
package io.github.diegourban.algorithms.problems.math;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.math.Combinatorics;
+import java.math.BigInteger;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
-import java.math.BigInteger;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
/**
* Easy Line — Codewars (7 kyu).
*
@@ -22,18 +21,18 @@ static BigInteger solve(int n) {
@ParameterizedTest
@CsvSource({
- "0, 1",
- "1, 2",
- "2, 6",
- "3, 20",
- "4, 70",
- "5, 252",
- "6, 924",
- "7, 3432",
- "13, 10400600",
- "17, 2333606220",
- "19, 35345263800",
- "50, 100891344545564193334812497256",
+ "0, 1",
+ "1, 2",
+ "2, 6",
+ "3, 20",
+ "4, 70",
+ "5, 252",
+ "6, 924",
+ "7, 3432",
+ "13, 10400600",
+ "17, 2333606220",
+ "19, 35345263800",
+ "50, 100891344545564193334812497256",
})
void sumsSquaresOfPascalRow(int n, BigInteger expected) {
assertThat(solve(n)).isEqualTo(expected);
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/FactorialSumTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/FactorialSumTest.java
index f2c6bbc..3c328ed 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/FactorialSumTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/FactorialSumTest.java
@@ -1,16 +1,15 @@
package io.github.diegourban.algorithms.problems.math;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.io.Reader;
import io.github.diegourban.algorithms.testing.SampleLoader;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.CsvSource;
-import org.junit.jupiter.params.provider.ValueSource;
-
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.junit.jupiter.params.provider.ValueSource;
/**
* Factorial Sum — beecrowd (formerly URI Online Judge) 1161.
@@ -50,12 +49,12 @@ static String run(InputStream in) throws IOException {
@ParameterizedTest
@CsvSource({
- "4, 4, 48",
- "0, 0, 2",
- "0, 2, 3",
- "1, 2, 3",
- "5, 0, 121",
- "20, 20, 4865804016353280000",
+ "4, 4, 48",
+ "0, 0, 2",
+ "0, 2, 3",
+ "1, 2, 3",
+ "5, 0, 121",
+ "20, 20, 4865804016353280000",
})
void sumsBothFactorials(int m, int n, long expected) {
assertThat(solve(m, n)).isEqualTo(expected);
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/FibonacciArrayTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/FibonacciArrayTest.java
index 2bcd9ca..7fd14da 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/FibonacciArrayTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/FibonacciArrayTest.java
@@ -1,10 +1,10 @@
package io.github.diegourban.algorithms.problems.math;
+import static org.assertj.core.api.Assertions.assertThat;
+
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
-import static org.assertj.core.api.Assertions.assertThat;
-
/**
* Fibonacci Array — beecrowd (formerly URI Online Judge) 1176.
*
@@ -28,14 +28,14 @@ static long solve(int n) {
@ParameterizedTest
@CsvSource({
- "0, 0",
- "1, 1",
- "2, 1",
- "4, 3",
- "10, 55",
- "46, 1836311903",
- "47, 2971215073",
- "60, 1548008755920",
+ "0, 0",
+ "1, 1",
+ "2, 1",
+ "4, 3",
+ "10, 55",
+ "46, 1836311903",
+ "47, 2971215073",
+ "60, 1548008755920",
})
void nthFibonacci(int n, long expected) {
assertThat(solve(n)).isEqualTo(expected);
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/PascalsTriangleTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/PascalsTriangleTest.java
index 6faca70..18cf34c 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/PascalsTriangleTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/PascalsTriangleTest.java
@@ -1,15 +1,14 @@
package io.github.diegourban.algorithms.problems.math;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.math.Combinatorics;
+import java.math.BigInteger;
+import java.util.stream.IntStream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
-import java.math.BigInteger;
-import java.util.stream.IntStream;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
/**
* Pascal's Triangle — beecrowd (formerly URI Online Judge) 2232.
*
@@ -25,11 +24,11 @@ static long solve(int n) {
@ParameterizedTest
@CsvSource({
- "1, 1",
- "2, 3",
- "5, 31",
- "31, 2147483647",
- "50, 1125899906842623",
+ "1, 1",
+ "2, 3",
+ "5, 31",
+ "31, 2147483647",
+ "50, 1125899906842623",
})
void sumOfFirstRows(int n, long expected) {
assertThat(solve(n)).isEqualTo(expected);
@@ -40,7 +39,8 @@ void closedFormMatchesSummingTheBinomialCoefficients() {
for (var n = 1; n <= 20; n++) {
var sum = IntStream.range(0, n)
.boxed()
- .flatMap(row -> IntStream.rangeClosed(0, row).mapToObj(k -> Combinatorics.binomialCoefficient(row, k)))
+ .flatMap(row ->
+ IntStream.rangeClosed(0, row).mapToObj(k -> Combinatorics.binomialCoefficient(row, k)))
.reduce(BigInteger.ZERO, BigInteger::add);
assertThat(solve(n)).as("n = %d", n).isEqualTo(sum.longValueExact());
}
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/PerfectNumberTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/PerfectNumberTest.java
index 7ec21bd..a592201 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/PerfectNumberTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/PerfectNumberTest.java
@@ -1,10 +1,10 @@
package io.github.diegourban.algorithms.problems.math;
+import static org.assertj.core.api.Assertions.assertThat;
+
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
-import static org.assertj.core.api.Assertions.assertThat;
-
/**
* Perfect Number — beecrowd (formerly URI Online Judge) 1164.
*
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/PrefaceTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/PrefaceTest.java
index b5d65fe..67cdda0 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/PrefaceTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/PrefaceTest.java
@@ -1,12 +1,12 @@
package io.github.diegourban.algorithms.problems.math;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
-
/**
* Preface — beecrowd (formerly URI Online Judge) 1837.
*
@@ -17,8 +17,7 @@
*/
class PrefaceTest {
- record Division(int quotient, int remainder) {
- }
+ record Division(int quotient, int remainder) {}
static Division solve(int a, int b) {
if (b == 0) {
@@ -30,14 +29,14 @@ static Division solve(int a, int b) {
@ParameterizedTest
@CsvSource({
- "7, 3, 2, 1",
- "-7, -3, 3, 2",
- "-736, 539, -2, 342",
- "62, -59, -1, 3",
- "999, 999, 1, 0",
- "-1000, -1000, 1, 0",
- "-6, 3, -2, 0",
- "0, -5, 0, 0",
+ "7, 3, 2, 1",
+ "-7, -3, 3, 2",
+ "-736, 539, -2, 342",
+ "62, -59, -1, 3",
+ "999, 999, 1, 0",
+ "-1000, -1000, 1, 0",
+ "-6, 3, -2, 0",
+ "0, -5, 0, 0",
})
void remainderIsNeverNegative(int a, int b, int quotient, int remainder) {
assertThat(solve(a, b)).isEqualTo(new Division(quotient, remainder));
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/PrimeGeneratorTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/PrimeGeneratorTest.java
index cc2329d..198d9d6 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/PrimeGeneratorTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/PrimeGeneratorTest.java
@@ -1,17 +1,16 @@
package io.github.diegourban.algorithms.problems.math;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.io.Reader;
import io.github.diegourban.algorithms.testing.SampleLoader;
-import org.junit.jupiter.api.Test;
-
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
/**
* Prime Generator — SPOJ PRIME1.
@@ -75,8 +74,9 @@ private static InputStream input(String text) {
@Test
void primesUpToOneHundred() {
- assertThat(solve(1, 100)).containsExactly(
- 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97);
+ assertThat(solve(1, 100))
+ .containsExactly(
+ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97);
}
@Test
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/PrimeNumberTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/PrimeNumberTest.java
index 3a2a062..f56cdce 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/PrimeNumberTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/PrimeNumberTest.java
@@ -1,11 +1,11 @@
package io.github.diegourban.algorithms.problems.math;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.math.NumberTheory;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
-import static org.assertj.core.api.Assertions.assertThat;
-
/**
* Prime Number — beecrowd (formerly URI Online Judge) 1165.
*
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/PrimesInNumbersTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/PrimesInNumbersTest.java
index 30ee306..af543b0 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/PrimesInNumbersTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/PrimesInNumbersTest.java
@@ -1,14 +1,13 @@
package io.github.diegourban.algorithms.problems.math;
-import io.github.diegourban.algorithms.math.NumberTheory;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.CsvSource;
+import static org.assertj.core.api.Assertions.assertThat;
+import io.github.diegourban.algorithms.math.NumberTheory;
import java.util.TreeMap;
import java.util.function.Function;
import java.util.stream.Collectors;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
/**
* Primes in numbers — Codewars (5 kyu).
@@ -34,20 +33,20 @@ static String solve(int n) {
@ParameterizedTest
@CsvSource({
- "2, (2)",
- "3, (3)",
- "4, (2**2)",
- "5, (5)",
- "6, (2)(3)",
- "7, (7)",
- "8, (2**3)",
- "9, (3**2)",
- "10, (2)(5)",
- "11, (11)",
- "12, (2**2)(3)",
- "13, (13)",
- "86240, (2**5)(5)(7**2)(11)",
- "7775460, (2**2)(3**3)(5)(7)(11**2)(17)",
+ "2, (2)",
+ "3, (3)",
+ "4, (2**2)",
+ "5, (5)",
+ "6, (2)(3)",
+ "7, (7)",
+ "8, (2**3)",
+ "9, (3**2)",
+ "10, (2)(5)",
+ "11, (11)",
+ "12, (2**2)(3)",
+ "13, (13)",
+ "86240, (2**5)(5)(7**2)(11)",
+ "7775460, (2**2)(3**3)(5)(7)(11**2)(17)",
})
void decomposesIntoPrimePowers(int n, String expected) {
assertThat(solve(n)).isEqualTo(expected);
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/QueenTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/QueenTest.java
index e68b188..3b1d553 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/QueenTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/QueenTest.java
@@ -1,16 +1,15 @@
package io.github.diegourban.algorithms.problems.math;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.io.Reader;
import io.github.diegourban.algorithms.testing.SampleLoader;
+import java.io.IOException;
+import java.io.InputStream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
-import java.io.IOException;
-import java.io.InputStream;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
/**
* Queen — beecrowd (formerly URI Online Judge) 1087.
*
@@ -50,14 +49,14 @@ static String run(InputStream in) throws IOException {
@ParameterizedTest
@CsvSource({
- "4, 4, 6, 2, 1",
- "3, 5, 3, 5, 0",
- "5, 5, 4, 3, 2",
- "1, 1, 1, 8, 1",
- "1, 1, 8, 1, 1",
- "1, 1, 8, 8, 1",
- "1, 8, 8, 1, 1",
- "1, 1, 2, 3, 2",
+ "4, 4, 6, 2, 1",
+ "3, 5, 3, 5, 0",
+ "5, 5, 4, 3, 2",
+ "1, 1, 1, 8, 1",
+ "1, 1, 8, 1, 1",
+ "1, 1, 8, 8, 1",
+ "1, 8, 8, 1, 1",
+ "1, 1, 2, 3, 2",
})
void minimumMoves(int x1, int y1, int x2, int y2, int expected) {
assertThat(solve(x1, y1, x2, y2)).isEqualTo(expected);
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/RainfallTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/RainfallTest.java
index f8d42df..5564bd5 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/RainfallTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/RainfallTest.java
@@ -1,13 +1,12 @@
package io.github.diegourban.algorithms.problems.math;
-import io.github.diegourban.algorithms.math.Statistics;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.within;
+import io.github.diegourban.algorithms.math.Statistics;
+import java.util.Arrays;
+import org.junit.jupiter.api.Test;
+
/**
* Rainfall — Codewars (6 kyu).
*
@@ -16,8 +15,7 @@
*/
class RainfallTest {
- record Rainfall(double mean, double variance) {
- }
+ record Rainfall(double mean, double variance) {}
static final Rainfall UNKNOWN = new Rainfall(-1, -1);
@@ -30,7 +28,10 @@ static Rainfall solve(String town, String data) {
.mapToDouble(month -> Double.parseDouble(month.split(" ")[1]))
.toArray();
var mean = Statistics.mean(values);
- var variance = Arrays.stream(values).map(v -> (v - mean) * (v - mean)).average().orElseThrow();
+ var variance = Arrays.stream(values)
+ .map(v -> (v - mean) * (v - mean))
+ .average()
+ .orElseThrow();
return new Rainfall(mean, variance);
})
.orElse(UNKNOWN);
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/RectangularLoveTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/RectangularLoveTest.java
index 13db347..d32445a 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/RectangularLoveTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/RectangularLoveTest.java
@@ -1,9 +1,9 @@
package io.github.diegourban.algorithms.problems.math;
-import org.junit.jupiter.api.Test;
-
import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
+
/**
* Rectangular Love — Interview Cake.
*
@@ -15,11 +15,9 @@
class RectangularLoveTest {
/** {@code (leftX, bottomY)} is the bottom-left corner. */
- record Rectangle(int leftX, int bottomY, int width, int height) {
- }
+ record Rectangle(int leftX, int bottomY, int width, int height) {}
- private record RangeOverlap(int startPoint, int length) {
- }
+ private record RangeOverlap(int startPoint, int length) {}
private static final Rectangle NO_OVERLAP = new Rectangle(0, 0, 0, 0);
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/RomanNumeralsTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/RomanNumeralsTest.java
index 19968f7..1ede0f1 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/RomanNumeralsTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/RomanNumeralsTest.java
@@ -1,10 +1,10 @@
package io.github.diegourban.algorithms.problems.math;
+import static org.assertj.core.api.Assertions.assertThat;
+
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
-import static org.assertj.core.api.Assertions.assertThat;
-
/**
* Roman Numerals for Page Numbers — beecrowd (formerly URI Online Judge) 1960.
*
@@ -32,18 +32,18 @@ static String solve(int n) {
@ParameterizedTest
@CsvSource({
- "666, DCLXVI",
- "83, LXXXIII",
- "1, I",
- "5, V",
- "10, X",
- "50, L",
- "100, C",
- "500, D",
- "4, IV",
- "49, XLIX",
- "444, CDXLIV",
- "999, CMXCIX",
+ "666, DCLXVI",
+ "83, LXXXIII",
+ "1, I",
+ "5, V",
+ "10, X",
+ "50, L",
+ "100, C",
+ "500, D",
+ "4, IV",
+ "49, XLIX",
+ "444, CDXLIV",
+ "999, CMXCIX",
})
void convertsToRoman(int n, String expected) {
assertThat(solve(n)).isEqualTo(expected);
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/SumByFactorsTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/SumByFactorsTest.java
index 7dd6309..55906b2 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/SumByFactorsTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/SumByFactorsTest.java
@@ -1,11 +1,10 @@
package io.github.diegourban.algorithms.problems.math;
-import io.github.diegourban.algorithms.math.NumberTheory;
-import org.junit.jupiter.api.Test;
+import static org.assertj.core.api.Assertions.assertThat;
+import io.github.diegourban.algorithms.math.NumberTheory;
import java.util.TreeMap;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
/**
* Sum by Factors — Codewars (4 kyu).
@@ -25,22 +24,23 @@ static String solve(int[] numbers) {
}
}
var result = new StringBuilder();
- sums.forEach((prime, sum) -> result.append('(').append(prime).append(' ').append(sum).append(')'));
+ sums.forEach((prime, sum) ->
+ result.append('(').append(prime).append(' ').append(sum).append(')'));
return result.toString();
}
@Test
void sumsEachPrimeFactorInAscendingOrder() {
- assertThat(solve(new int[]{12, 15})).isEqualTo("(2 12)(3 27)(5 15)");
+ assertThat(solve(new int[] {12, 15})).isEqualTo("(2 12)(3 27)(5 15)");
}
@Test
void negativeNumbersContributeTheirSignedValue() {
- assertThat(solve(new int[]{15, 30, -45})).isEqualTo("(2 30)(3 0)(5 0)");
+ assertThat(solve(new int[] {15, 30, -45})).isEqualTo("(2 30)(3 0)(5 0)");
}
@Test
void emptyListGivesEmptyString() {
- assertThat(solve(new int[]{})).isEmpty();
+ assertThat(solve(new int[] {})).isEmpty();
}
}
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/TdaRationalTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/TdaRationalTest.java
index a4d40b6..659f2ab 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/TdaRationalTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/TdaRationalTest.java
@@ -1,11 +1,11 @@
package io.github.diegourban.algorithms.problems.math;
-import io.github.diegourban.algorithms.math.NumberTheory;
-import org.junit.jupiter.api.Test;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import io.github.diegourban.algorithms.math.NumberTheory;
+import org.junit.jupiter.api.Test;
+
/**
* TDA Rational — beecrowd (formerly URI Online Judge) 1022.
*
@@ -16,18 +16,20 @@
*/
class TdaRationalTest {
- record Fraction(int numerator, int denominator) {
- }
+ record Fraction(int numerator, int denominator) {}
- record Result(Fraction raw, Fraction simplified) {
- }
+ record Result(Fraction raw, Fraction simplified) {}
static Result solve(Fraction a, char operator, Fraction b) {
var raw = switch (operator) {
- case '+' -> new Fraction(a.numerator() * b.denominator() + b.numerator() * a.denominator(),
- a.denominator() * b.denominator());
- case '-' -> new Fraction(a.numerator() * b.denominator() - b.numerator() * a.denominator(),
- a.denominator() * b.denominator());
+ case '+' ->
+ new Fraction(
+ a.numerator() * b.denominator() + b.numerator() * a.denominator(),
+ a.denominator() * b.denominator());
+ case '-' ->
+ new Fraction(
+ a.numerator() * b.denominator() - b.numerator() * a.denominator(),
+ a.denominator() * b.denominator());
case '*' -> new Fraction(a.numerator() * b.numerator(), a.denominator() * b.denominator());
case '/' -> new Fraction(a.numerator() * b.denominator(), b.numerator() * a.denominator());
default -> throw new IllegalArgumentException("Invalid operator: " + operator);
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/math/TripleDoubleTest.java b/src/test/java/io/github/diegourban/algorithms/problems/math/TripleDoubleTest.java
index 6f582d4..dbe8e47 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/math/TripleDoubleTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/math/TripleDoubleTest.java
@@ -1,11 +1,10 @@
package io.github.diegourban.algorithms.problems.math;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.CsvSource;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.stream.IntStream;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
/**
* Triple trouble — Codewars (6 kyu).
@@ -22,19 +21,21 @@ static int solve(long num1, long num2) {
var a = Long.toString(num1);
var b = Long.toString(num2);
return IntStream.rangeClosed(0, 9)
- .mapToObj(Integer::toString)
- .anyMatch(d -> a.contains(d.repeat(3)) && b.contains(d.repeat(2))) ? 1 : 0;
+ .mapToObj(Integer::toString)
+ .anyMatch(d -> a.contains(d.repeat(3)) && b.contains(d.repeat(2)))
+ ? 1
+ : 0;
}
@ParameterizedTest
@CsvSource({
- "451999277, 41177722899, 1",
- "1222345, 12345, 0",
- "12345, 12345, 0",
- "666789, 12345667, 1",
- "10560002, 100, 1",
- "111, 22, 0",
- "1112, 122, 0",
+ "451999277, 41177722899, 1",
+ "1222345, 12345, 0",
+ "12345, 12345, 0",
+ "666789, 12345667, 1",
+ "10560002, 100, 1",
+ "111, 22, 0",
+ "1112, 122, 0",
})
void requiresTripleAndDoubleOfTheSameDigit(long num1, long num2, int expected) {
assertThat(solve(num1, num2)).isEqualTo(expected);
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/recursion/CollatzConjectureTest.java b/src/test/java/io/github/diegourban/algorithms/problems/recursion/CollatzConjectureTest.java
index 579cb1a..42df6b3 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/recursion/CollatzConjectureTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/recursion/CollatzConjectureTest.java
@@ -1,10 +1,10 @@
package io.github.diegourban.algorithms.problems.recursion;
+import static org.assertj.core.api.Assertions.assertThat;
+
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
-import static org.assertj.core.api.Assertions.assertThat;
-
/**
* Collatz Conjecture — Codewars (7 kyu).
*
@@ -22,13 +22,7 @@ static long solve(long x) {
@ParameterizedTest
@CsvSource({
- "1, 1",
- "2, 2",
- "3, 8",
- "30, 19",
- "27, 112",
- "100, 26",
- "103, 88",
+ "1, 1", "2, 2", "3, 8", "30, 19", "27, 112", "100, 26", "103, 88",
})
void countsSequenceLength(long x, long expected) {
assertThat(solve(x)).isEqualTo(expected);
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/recursion/RecursiveStringPermutationsTest.java b/src/test/java/io/github/diegourban/algorithms/problems/recursion/RecursiveStringPermutationsTest.java
index 7b42c4d..887303e 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/recursion/RecursiveStringPermutationsTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/recursion/RecursiveStringPermutationsTest.java
@@ -1,11 +1,10 @@
package io.github.diegourban.algorithms.problems.recursion;
-import org.junit.jupiter.api.Test;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashSet;
import java.util.Set;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
/**
* Recursive String Permutations — Interview Cake.
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/recursion/SquareRootOfTwoTest.java b/src/test/java/io/github/diegourban/algorithms/problems/recursion/SquareRootOfTwoTest.java
index 7656e7a..156c50d 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/recursion/SquareRootOfTwoTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/recursion/SquareRootOfTwoTest.java
@@ -1,14 +1,13 @@
package io.github.diegourban.algorithms.problems.recursion;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.offset;
+
+import java.util.Locale;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
-import java.util.Locale;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.offset;
-
/**
* Square Root of 2 — beecrowd (formerly URI Online Judge) 2166.
*
@@ -29,10 +28,10 @@ private static double tail(int n) {
@ParameterizedTest
@CsvSource({
- "0, 1.0000000000",
- "1, 1.5000000000",
- "5, 1.4142857143",
- "100, 1.4142135624",
+ "0, 1.0000000000",
+ "1, 1.5000000000",
+ "5, 1.4142857143",
+ "100, 1.4142135624",
})
void approximatesSquareRootOfTwoToTenDecimals(int n, String expected) {
assertThat(String.format(Locale.ROOT, "%.10f", solve(n))).isEqualTo(expected);
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/search/FindRepeatTest.java b/src/test/java/io/github/diegourban/algorithms/problems/search/FindRepeatTest.java
index 80fc247..08eb636 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/search/FindRepeatTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/search/FindRepeatTest.java
@@ -1,9 +1,9 @@
package io.github.diegourban.algorithms.problems.search;
-import org.junit.jupiter.api.Test;
-
import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
+
/**
* Find Repeat, Space Edition — Interview Cake.
*
@@ -37,31 +37,31 @@ static int solve(int[] numbers) {
@Test
void smallestInputsRepeatOne() {
- assertThat(solve(new int[]{1, 1})).isOne();
- assertThat(solve(new int[]{1, 1, 1})).isOne();
+ assertThat(solve(new int[] {1, 1})).isOne();
+ assertThat(solve(new int[] {1, 1, 1})).isOne();
}
@Test
void findsAdjacentRepeatAnywhereInTheRange() {
- assertThat(solve(new int[]{1, 1, 2, 3, 4, 5, 6, 7, 8, 9})).isOne();
- assertThat(solve(new int[]{1, 2, 2, 3, 4, 5, 6, 7, 8, 9})).isEqualTo(2);
- assertThat(solve(new int[]{1, 2, 3, 3, 4, 5, 6, 7, 8, 9})).isEqualTo(3);
- assertThat(solve(new int[]{1, 2, 3, 4, 4, 5, 6, 7, 8, 9})).isEqualTo(4);
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 5, 6, 7, 8, 9})).isEqualTo(5);
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 6, 6, 7, 8, 9})).isEqualTo(6);
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 6, 7, 7, 8, 9})).isEqualTo(7);
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 8, 9})).isEqualTo(8);
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 9})).isEqualTo(9);
+ assertThat(solve(new int[] {1, 1, 2, 3, 4, 5, 6, 7, 8, 9})).isOne();
+ assertThat(solve(new int[] {1, 2, 2, 3, 4, 5, 6, 7, 8, 9})).isEqualTo(2);
+ assertThat(solve(new int[] {1, 2, 3, 3, 4, 5, 6, 7, 8, 9})).isEqualTo(3);
+ assertThat(solve(new int[] {1, 2, 3, 4, 4, 5, 6, 7, 8, 9})).isEqualTo(4);
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 5, 6, 7, 8, 9})).isEqualTo(5);
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 6, 6, 7, 8, 9})).isEqualTo(6);
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 6, 7, 7, 8, 9})).isEqualTo(7);
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 8, 9})).isEqualTo(8);
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 9})).isEqualTo(9);
}
@Test
void findsRepeatRegardlessOfPosition() {
- assertThat(solve(new int[]{1, 2, 1, 3, 4, 5, 6, 7, 8})).isOne();
- assertThat(solve(new int[]{1, 2, 3, 1, 4, 5, 6, 7, 8})).isOne();
- assertThat(solve(new int[]{1, 2, 3, 4, 1, 5, 6, 7, 8})).isOne();
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 1, 6, 7, 8})).isOne();
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 6, 1, 7, 8})).isOne();
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 6, 7, 1, 8})).isOne();
- assertThat(solve(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 1})).isOne();
+ assertThat(solve(new int[] {1, 2, 1, 3, 4, 5, 6, 7, 8})).isOne();
+ assertThat(solve(new int[] {1, 2, 3, 1, 4, 5, 6, 7, 8})).isOne();
+ assertThat(solve(new int[] {1, 2, 3, 4, 1, 5, 6, 7, 8})).isOne();
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 1, 6, 7, 8})).isOne();
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 6, 1, 7, 8})).isOne();
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 6, 7, 1, 8})).isOne();
+ assertThat(solve(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 1})).isOne();
}
}
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/search/FindRotationPointTest.java b/src/test/java/io/github/diegourban/algorithms/problems/search/FindRotationPointTest.java
index 7d27fef..803c12f 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/search/FindRotationPointTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/search/FindRotationPointTest.java
@@ -1,9 +1,9 @@
package io.github.diegourban.algorithms.problems.search;
-import org.junit.jupiter.api.Test;
-
import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
+
/**
* Find Rotation Point — Interview Cake.
*
@@ -34,34 +34,45 @@ static int solve(String[] words) {
@Test
void findsRotationPointInSingleLetterWords() {
- assertThat(solve(new String[]{"k", "v", "a", "b", "c", "d", "e", "g", "i"})).isEqualTo(2);
+ assertThat(solve(new String[] {"k", "v", "a", "b", "c", "d", "e", "g", "i"}))
+ .isEqualTo(2);
}
@Test
void findsRotationPointInDictionaryWords() {
- assertThat(solve(new String[]{
- "ptolemaic", "retrograde", "supplant", "undulate", "xenoepist",
- "asymptote", "babka", "banoffee", "engender", "karpatka", "othellolagkage"
- })).isEqualTo(5);
+ assertThat(solve(new String[] {
+ "ptolemaic",
+ "retrograde",
+ "supplant",
+ "undulate",
+ "xenoepist",
+ "asymptote",
+ "babka",
+ "banoffee",
+ "engender",
+ "karpatka",
+ "othellolagkage"
+ }))
+ .isEqualTo(5);
}
@Test
void findsRotationPointRightAfterTheFirstWord() {
- assertThat(solve(new String[]{"z", "a", "b", "c", "d"})).isOne();
+ assertThat(solve(new String[] {"z", "a", "b", "c", "d"})).isOne();
}
@Test
void unrotatedListStartsAtZero() {
- assertThat(solve(new String[]{"a", "b", "c", "d"})).isZero();
+ assertThat(solve(new String[] {"a", "b", "c", "d"})).isZero();
}
@Test
void singleWordStartsAtZero() {
- assertThat(solve(new String[]{"a"})).isZero();
+ assertThat(solve(new String[] {"a"})).isZero();
}
@Test
void findsRotationPointAtTheEnd() {
- assertThat(solve(new String[]{"b", "c", "d", "a"})).isEqualTo(3);
+ assertThat(solve(new String[] {"b", "c", "d", "a"})).isEqualTo(3);
}
}
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/search/TwoBillsTest.java b/src/test/java/io/github/diegourban/algorithms/problems/search/TwoBillsTest.java
index 852676a..a600847 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/search/TwoBillsTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/search/TwoBillsTest.java
@@ -1,18 +1,17 @@
package io.github.diegourban.algorithms.problems.search;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.io.Reader;
import io.github.diegourban.algorithms.testing.SampleLoader;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.CsvSource;
-import org.junit.jupiter.params.provider.ValueSource;
-
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.junit.jupiter.params.provider.ValueSource;
/**
* Two Bills — beecrowd (formerly URI Online Judge) 2140.
@@ -43,8 +42,9 @@ static boolean solve(int price, int paid) {
static String run(InputStream in) throws IOException {
var reader = new Reader(in);
var out = new StringBuilder();
- for (int price = reader.nextInt(), paid = reader.nextInt(); price != 0 || paid != 0;
- price = reader.nextInt(), paid = reader.nextInt()) {
+ for (int price = reader.nextInt(), paid = reader.nextInt();
+ price != 0 || paid != 0;
+ price = reader.nextInt(), paid = reader.nextInt()) {
out.append(solve(price, paid) ? "possible" : "impossible").append('\n');
}
return out.toString();
@@ -52,11 +52,11 @@ static String run(InputStream in) throws IOException {
@ParameterizedTest
@CsvSource({
- "11, 23",
- "500, 650",
- "9948, 9963",
- "1, 5",
- "0, 200",
+ "11, 23",
+ "500, 650",
+ "9948, 9963",
+ "1, 5",
+ "0, 200",
})
void changeMadeOfTwoBillsIsPossible(int price, int paid) {
assertThat(solve(price, paid)).isTrue();
@@ -64,12 +64,12 @@ void changeMadeOfTwoBillsIsPossible(int price, int paid) {
@ParameterizedTest
@CsvSource({
- "100, 600",
- "1, 2",
- "1, 3",
- "1, 7",
- "5, 5",
- "0, 201",
+ "100, 600",
+ "1, 2",
+ "1, 3",
+ "1, 7",
+ "5, 5",
+ "0, 201",
})
void otherChangeIsImpossible(int price, int paid) {
assertThat(solve(price, paid)).isFalse();
@@ -77,7 +77,8 @@ void otherChangeIsImpossible(int price, int paid) {
@Test
void zeroZeroEndsTheInput() throws IOException {
- assertThat(run(new ByteArrayInputStream("0 0\n".getBytes(StandardCharsets.UTF_8)))).isEmpty();
+ assertThat(run(new ByteArrayInputStream("0 0\n".getBytes(StandardCharsets.UTF_8))))
+ .isEmpty();
}
@ParameterizedTest
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/simulation/MaestersMapTest.java b/src/test/java/io/github/diegourban/algorithms/problems/simulation/MaestersMapTest.java
index 714a410..d510a9a 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/simulation/MaestersMapTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/simulation/MaestersMapTest.java
@@ -1,17 +1,16 @@
package io.github.diegourban.algorithms.problems.simulation;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.io.Reader;
import io.github.diegourban.algorithms.testing.SampleLoader;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ValueSource;
-
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
/**
* Maester's Map — beecrowd (formerly URI Online Judge) 1855.
@@ -77,10 +76,7 @@ static String run(InputStream in) throws IOException {
@Test
void followsArrowsToTheChest() {
- assertThat(solve(List.of(
- ">..v",
- "....",
- "*..<"))).isTrue();
+ assertThat(solve(List.of(">..v", "....", "*..<"))).isTrue();
}
@Test
@@ -90,10 +86,7 @@ void walksStraightIntoTheChest() {
@Test
void reusingAnArrowIsALoop() {
- assertThat(solve(List.of(
- ">.....v",
- ".......",
- "^.....<"))).isFalse();
+ assertThat(solve(List.of(">.....v", ".......", "^.....<"))).isFalse();
}
@Test
@@ -103,19 +96,21 @@ void walkingOffTheMapIsAFailure() {
}
@ParameterizedTest
- @ValueSource(strings = {
- "sampleFindChest1", "sampleFindChest2", "sampleFindChest3",
- "sampleFindChest4", "sampleFindChest5", "sampleFindChest6",
- })
+ @ValueSource(
+ strings = {
+ "sampleFindChest1", "sampleFindChest2", "sampleFindChest3",
+ "sampleFindChest4", "sampleFindChest5", "sampleFindChest6",
+ })
void samplesThatReachTheChest(String name) throws IOException {
assertThat(run(samples.loadAsInputStream(name + ".in"))).isEqualTo("*\n");
}
@ParameterizedTest
- @ValueSource(strings = {
- "sampleLoop1", "sampleLoop2", "sampleLoop3", "sampleLoop4",
- "sampleOutOfBounds1", "sampleOutOfBounds2", "sampleOutOfBounds3", "sampleOutOfBounds4",
- })
+ @ValueSource(
+ strings = {
+ "sampleLoop1", "sampleLoop2", "sampleLoop3", "sampleLoop4",
+ "sampleOutOfBounds1", "sampleOutOfBounds2", "sampleOutOfBounds3", "sampleOutOfBounds4",
+ })
void samplesThatLoopOrLeaveTheMap(String name) throws IOException {
assertThat(run(samples.loadAsInputStream(name + ".in"))).isEqualTo("!\n");
}
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/simulation/StarTrekTest.java b/src/test/java/io/github/diegourban/algorithms/problems/simulation/StarTrekTest.java
index 4dabc1c..c85ab5c 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/simulation/StarTrekTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/simulation/StarTrekTest.java
@@ -1,16 +1,15 @@
package io.github.diegourban.algorithms.problems.simulation;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.io.Reader;
import io.github.diegourban.algorithms.testing.SampleLoader;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.CsvSource;
-
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
/**
* Star Trek — beecrowd (formerly URI Online Judge) 1973.
@@ -25,8 +24,7 @@ class StarTrekTest {
private final SampleLoader samples = new SampleLoader("problems/simulation/star-trek");
- record Raid(int starsAttacked, long sheepLeft) {
- }
+ record Raid(int starsAttacked, long sheepLeft) {}
static Raid solve(int[] sheep) {
var left = sheep.clone();
@@ -61,43 +59,43 @@ static String run(InputStream in) throws IOException {
@Test
void singleStarWithOneSheep() {
- assertThat(solve(new int[]{1})).isEqualTo(new Raid(1, 0));
+ assertThat(solve(new int[] {1})).isEqualTo(new Raid(1, 0));
}
@Test
void allOddStarsAreAttackedOnceOnTheWayOut() {
- assertThat(solve(new int[]{1, 1, 1, 1, 1})).isEqualTo(new Raid(5, 0));
- assertThat(solve(new int[]{3, 3, 3, 3, 3})).isEqualTo(new Raid(5, 10));
+ assertThat(solve(new int[] {1, 1, 1, 1, 1})).isEqualTo(new Raid(5, 0));
+ assertThat(solve(new int[] {3, 3, 3, 3, 3})).isEqualTo(new Raid(5, 10));
}
@Test
void evenStarTurnsKirkBackAndEveryStarBehindIsRobbedAgain() {
- assertThat(solve(new int[]{1, 1, 2, 1, 1})).isEqualTo(new Raid(3, 3));
- assertThat(solve(new int[]{3, 3, 2, 3, 3})).isEqualTo(new Raid(3, 9));
+ assertThat(solve(new int[] {1, 1, 2, 1, 1})).isEqualTo(new Raid(3, 3));
+ assertThat(solve(new int[] {3, 3, 2, 3, 3})).isEqualTo(new Raid(3, 9));
}
@Test
void evenLastStarTurnsKirkBack() {
- assertThat(solve(new int[]{1, 1, 1, 1, 2})).isEqualTo(new Raid(5, 1));
- assertThat(solve(new int[]{3, 3, 3, 3, 2})).isEqualTo(new Raid(5, 5));
+ assertThat(solve(new int[] {1, 1, 1, 1, 2})).isEqualTo(new Raid(5, 1));
+ assertThat(solve(new int[] {3, 3, 3, 3, 2})).isEqualTo(new Raid(5, 5));
}
@Test
void emptyStarIsEvenAndHasNothingToSteal() {
- assertThat(solve(new int[]{3, 0, 5})).isEqualTo(new Raid(2, 6));
+ assertThat(solve(new int[] {3, 0, 5})).isEqualTo(new Raid(2, 6));
}
@Test
void judgeSamples() {
- assertThat(solve(new int[]{1, 3, 5, 7, 11, 13, 17, 19})).isEqualTo(new Raid(8, 68));
- assertThat(solve(new int[]{1, 3, 5, 7, 11, 13, 16, 19})).isEqualTo(new Raid(7, 63));
+ assertThat(solve(new int[] {1, 3, 5, 7, 11, 13, 17, 19})).isEqualTo(new Raid(8, 68));
+ assertThat(solve(new int[] {1, 3, 5, 7, 11, 13, 16, 19})).isEqualTo(new Raid(7, 63));
}
@ParameterizedTest
@CsvSource({
- "max, 10000 99990000",
- "max2, 16000 15999968000",
- "max3, 8000 15999968002",
+ "max, 10000 99990000",
+ "max2, 16000 15999968000",
+ "max3, 8000 15999968002",
})
void maxSamples(String name, String expected) throws IOException {
assertThat(run(samples.loadAsInputStream(name + ".in"))).isEqualTo(expected + "\n");
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/sorting/FindTheOddIntTest.java b/src/test/java/io/github/diegourban/algorithms/problems/sorting/FindTheOddIntTest.java
index 62bb7ca..0158c7d 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/sorting/FindTheOddIntTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/sorting/FindTheOddIntTest.java
@@ -1,11 +1,11 @@
package io.github.diegourban.algorithms.problems.sorting;
-import io.github.diegourban.algorithms.sorting.MergeSort;
-import org.junit.jupiter.api.Test;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import io.github.diegourban.algorithms.sorting.MergeSort;
+import org.junit.jupiter.api.Test;
+
/**
* Find the odd int — Codewars (6 kyu).
*
@@ -34,40 +34,41 @@ static int solve(int[] numbers) {
@Test
void findsValueAppearingOddTimesAmongPairs() {
- assertThat(solve(new int[]{20, 1, -1, 2, -2, 3, 3, 5, 5, 1, 2, 4, 20, 4, -1, -2, 5})).isEqualTo(5);
- assertThat(solve(new int[]{20, 1, 1, 2, 2, 3, 3, 5, 5, 4, 20, 4, 5})).isEqualTo(5);
+ assertThat(solve(new int[] {20, 1, -1, 2, -2, 3, 3, 5, 5, 1, 2, 4, 20, 4, -1, -2, 5}))
+ .isEqualTo(5);
+ assertThat(solve(new int[] {20, 1, 1, 2, 2, 3, 3, 5, 5, 4, 20, 4, 5})).isEqualTo(5);
}
@Test
void handlesNegativeValues() {
- assertThat(solve(new int[]{1, 1, 2, -2, 5, 2, 4, 4, -1, -2, 5})).isEqualTo(-1);
+ assertThat(solve(new int[] {1, 1, 2, -2, 5, 2, 4, 4, -1, -2, 5})).isEqualTo(-1);
}
@Test
void singleElementIsTheAnswer() {
- assertThat(solve(new int[]{10})).isEqualTo(10);
+ assertThat(solve(new int[] {10})).isEqualTo(10);
}
@Test
void valueSurroundedByAnEvenRunOfAnother() {
- assertThat(solve(new int[]{1, 1, 1, 1, 1, 1, 10, 1, 1, 1, 1})).isEqualTo(10);
+ assertThat(solve(new int[] {1, 1, 1, 1, 1, 1, 10, 1, 1, 1, 1})).isEqualTo(10);
}
@Test
void answerIsTheSmallestValue() {
- assertThat(solve(new int[]{5, 4, 3, 2, 1, 5, 4, 3, 2, 10, 10})).isEqualTo(1);
+ assertThat(solve(new int[] {5, 4, 3, 2, 1, 5, 4, 3, 2, 10, 10})).isEqualTo(1);
}
@Test
void doesNotMutateInput() {
- var numbers = new int[]{3, 1, 3};
+ var numbers = new int[] {3, 1, 3};
solve(numbers);
assertThat(numbers).containsExactly(3, 1, 3);
}
@Test
void rejectsInputWithoutAnOddCount() {
- assertThatIllegalArgumentException().isThrownBy(() -> solve(new int[]{}));
- assertThatIllegalArgumentException().isThrownBy(() -> solve(new int[]{7, 7}));
+ assertThatIllegalArgumentException().isThrownBy(() -> solve(new int[] {}));
+ assertThatIllegalArgumentException().isThrownBy(() -> solve(new int[] {7, 7}));
}
}
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/string/ContractRevisionTest.java b/src/test/java/io/github/diegourban/algorithms/problems/string/ContractRevisionTest.java
index 78490aa..65735d0 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/string/ContractRevisionTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/string/ContractRevisionTest.java
@@ -1,16 +1,15 @@
package io.github.diegourban.algorithms.problems.string;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.io.Reader;
import io.github.diegourban.algorithms.testing.SampleLoader;
+import java.io.IOException;
+import java.io.InputStream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
-import java.io.IOException;
-import java.io.InputStream;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
/**
* Contract Revision — beecrowd (formerly URI Online Judge) 1120.
*
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/string/EncryptionTest.java b/src/test/java/io/github/diegourban/algorithms/problems/string/EncryptionTest.java
index 43240ba..e3b2c1a 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/string/EncryptionTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/string/EncryptionTest.java
@@ -1,16 +1,15 @@
package io.github.diegourban.algorithms.problems.string;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.io.Reader;
import io.github.diegourban.algorithms.testing.SampleLoader;
+import java.io.IOException;
+import java.io.InputStream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
-import java.io.IOException;
-import java.io.InputStream;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
/**
* Encryption — beecrowd (formerly URI Online Judge) 1024.
*
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/string/MorseTest.java b/src/test/java/io/github/diegourban/algorithms/problems/string/MorseTest.java
index bffcacf..2d859fd 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/string/MorseTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/string/MorseTest.java
@@ -1,11 +1,10 @@
package io.github.diegourban.algorithms.problems.string;
-import org.junit.jupiter.api.Test;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.stream.Collectors;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
/**
* Morse — beecrowd (formerly URI Online Judge) 2338.
@@ -18,8 +17,8 @@
class MorseTest {
private static final String[] MORSE = {
- ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
- "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."
+ ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
+ "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."
};
static String solve(String code) {
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/string/OneTwoThreeTest.java b/src/test/java/io/github/diegourban/algorithms/problems/string/OneTwoThreeTest.java
index 5098db7..3baf9df 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/string/OneTwoThreeTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/string/OneTwoThreeTest.java
@@ -1,16 +1,15 @@
package io.github.diegourban.algorithms.problems.string;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.io.Reader;
import io.github.diegourban.algorithms.testing.SampleLoader;
+import java.io.IOException;
+import java.io.InputStream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
-import java.io.IOException;
-import java.io.InputStream;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
/**
* One-Two-Three — beecrowd (formerly URI Online Judge) 1332.
*
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/string/ParenthesisMatchingTest.java b/src/test/java/io/github/diegourban/algorithms/problems/string/ParenthesisMatchingTest.java
index 2e3d03e..c04f74f 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/string/ParenthesisMatchingTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/string/ParenthesisMatchingTest.java
@@ -1,10 +1,10 @@
package io.github.diegourban.algorithms.problems.string;
-import org.junit.jupiter.api.Test;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import org.junit.jupiter.api.Test;
+
/**
* Parenthesis Matching — Interview Cake.
*
@@ -26,7 +26,7 @@ static int solve(String sentence, int openingParenthesisIndex) {
}
openNested--;
}
- default -> { }
+ default -> {}
}
}
throw new IllegalArgumentException("No closing parenthesis :(");
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/string/PlayingWithPassphrasesTest.java b/src/test/java/io/github/diegourban/algorithms/problems/string/PlayingWithPassphrasesTest.java
index 40b95aa..fbc2caf 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/string/PlayingWithPassphrasesTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/string/PlayingWithPassphrasesTest.java
@@ -1,9 +1,9 @@
package io.github.diegourban.algorithms.problems.string;
-import org.junit.jupiter.api.Test;
-
import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
+
/**
* Playing with passphrases — Codewars (6 kyu).
*
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/string/ReverseWordsTest.java b/src/test/java/io/github/diegourban/algorithms/problems/string/ReverseWordsTest.java
index 1c2c7e5..909562d 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/string/ReverseWordsTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/string/ReverseWordsTest.java
@@ -1,9 +1,9 @@
package io.github.diegourban.algorithms.problems.string;
-import org.junit.jupiter.api.Test;
-
import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
+
/**
* Reverse Words — Interview Cake.
*
diff --git a/src/test/java/io/github/diegourban/algorithms/problems/string/SearchingSubsequencesTest.java b/src/test/java/io/github/diegourban/algorithms/problems/string/SearchingSubsequencesTest.java
index 38bb947..8fe8e83 100644
--- a/src/test/java/io/github/diegourban/algorithms/problems/string/SearchingSubsequencesTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/problems/string/SearchingSubsequencesTest.java
@@ -1,16 +1,15 @@
package io.github.diegourban.algorithms.problems.string;
+import static org.assertj.core.api.Assertions.assertThat;
+
import io.github.diegourban.algorithms.io.Reader;
import io.github.diegourban.algorithms.testing.SampleLoader;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.ValueSource;
-
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
/**
* Searching Subsequences — beecrowd (formerly URI Online Judge) 2126.
@@ -25,8 +24,7 @@ class SearchingSubsequencesTest {
private static final SampleLoader SAMPLES = new SampleLoader("problems/string/searching-subsequences");
/** {@code count} occurrences, the last one starting at 1-based {@code lastPosition} (0 when none). */
- record Occurrences(int count, int lastPosition) {
- }
+ record Occurrences(int count, int lastPosition) {}
static Occurrences solve(String pattern, String text) {
var count = 0;
diff --git a/src/test/java/io/github/diegourban/algorithms/search/BinarySearchPropertyTest.java b/src/test/java/io/github/diegourban/algorithms/search/BinarySearchPropertyTest.java
index 546d7ab..f27ce51 100644
--- a/src/test/java/io/github/diegourban/algorithms/search/BinarySearchPropertyTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/search/BinarySearchPropertyTest.java
@@ -1,11 +1,10 @@
package io.github.diegourban.algorithms.search;
-import net.jqwik.api.ForAll;
-import net.jqwik.api.Property;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import net.jqwik.api.ForAll;
+import net.jqwik.api.Property;
/**
* {@link BinarySearch#indexOf(int[], int)} must agree with {@link Arrays#binarySearch(int[], int)} on whether the key
diff --git a/src/test/java/io/github/diegourban/algorithms/search/BinarySearchTest.java b/src/test/java/io/github/diegourban/algorithms/search/BinarySearchTest.java
index 99e9811..a9d673e 100644
--- a/src/test/java/io/github/diegourban/algorithms/search/BinarySearchTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/search/BinarySearchTest.java
@@ -1,9 +1,9 @@
package io.github.diegourban.algorithms.search;
-import org.junit.jupiter.api.Test;
-
import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.api.Test;
+
class BinarySearchTest {
private static final int[] ONE_TO_TEN = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
@@ -26,7 +26,8 @@ void findsBothEnds() {
@Test
void returnsMinusOneForAMissingKey() {
- assertThat(BinarySearch.indexOf(new int[]{1, 2, 3, 5, 6, 7, 8, 9, 10}, 4)).isEqualTo(-1);
+ assertThat(BinarySearch.indexOf(new int[] {1, 2, 3, 5, 6, 7, 8, 9, 10}, 4))
+ .isEqualTo(-1);
}
@Test
@@ -37,6 +38,6 @@ void returnsMinusOneOutsideTheRange() {
@Test
void returnsMinusOneForAnEmptyArray() {
- assertThat(BinarySearch.indexOf(new int[]{}, 1)).isEqualTo(-1);
+ assertThat(BinarySearch.indexOf(new int[] {}, 1)).isEqualTo(-1);
}
}
diff --git a/src/test/java/io/github/diegourban/algorithms/sorting/SorterPropertyTest.java b/src/test/java/io/github/diegourban/algorithms/sorting/SorterPropertyTest.java
index dcdd5d5..e70a9b1 100644
--- a/src/test/java/io/github/diegourban/algorithms/sorting/SorterPropertyTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/sorting/SorterPropertyTest.java
@@ -1,15 +1,14 @@
package io.github.diegourban.algorithms.sorting;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Arrays;
import net.jqwik.api.Arbitraries;
import net.jqwik.api.Arbitrary;
import net.jqwik.api.ForAll;
import net.jqwik.api.Property;
import net.jqwik.api.Provide;
-import java.util.Arrays;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
/**
* Every {@link Sorter} must agree with {@link Arrays#sort(int[])} on any input.
*/
diff --git a/src/test/java/io/github/diegourban/algorithms/sorting/SorterTest.java b/src/test/java/io/github/diegourban/algorithms/sorting/SorterTest.java
index abc10a5..e5ec128 100644
--- a/src/test/java/io/github/diegourban/algorithms/sorting/SorterTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/sorting/SorterTest.java
@@ -1,11 +1,10 @@
package io.github.diegourban.algorithms.sorting;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.MethodSource;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.stream.Stream;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
/**
* Example-based checks run against every {@link Sorter}; {@link SorterPropertyTest} covers random inputs.
diff --git a/src/test/java/io/github/diegourban/algorithms/string/StringUtilsPropertyTest.java b/src/test/java/io/github/diegourban/algorithms/string/StringUtilsPropertyTest.java
index 9f878ad..09e7b28 100644
--- a/src/test/java/io/github/diegourban/algorithms/string/StringUtilsPropertyTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/string/StringUtilsPropertyTest.java
@@ -1,17 +1,16 @@
package io.github.diegourban.algorithms.string;
-import net.jqwik.api.ForAll;
-import net.jqwik.api.Property;
-import net.jqwik.api.constraints.AlphaChars;
-import net.jqwik.api.constraints.NotEmpty;
-import net.jqwik.api.constraints.StringLength;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.stream.Collectors;
-
-import static org.assertj.core.api.Assertions.assertThat;
+import net.jqwik.api.ForAll;
+import net.jqwik.api.Property;
+import net.jqwik.api.constraints.AlphaChars;
+import net.jqwik.api.constraints.NotEmpty;
+import net.jqwik.api.constraints.StringLength;
/**
* Inputs are ASCII letters: both methods compare {@code char} by {@code char}, so the properties check their logic
@@ -27,8 +26,8 @@ void isPalindromeAgreesWithReversing(@ForAll @AlphaChars @NotEmpty @StringLength
}
@Property
- void mirroredStringsArePalindromes(@ForAll @AlphaChars @NotEmpty @StringLength(max = 20) String s,
- @ForAll @AlphaChars char middle) {
+ void mirroredStringsArePalindromes(
+ @ForAll @AlphaChars @NotEmpty @StringLength(max = 20) String s, @ForAll @AlphaChars char middle) {
var reversed = new StringBuilder(s).reverse().toString();
assertThat(StringUtils.isPalindrome(s + reversed)).isTrue();
@@ -42,12 +41,13 @@ void aShuffleIsAnAnagram(@ForAll @AlphaChars String s, @ForAll long seed) {
var shuffled = chars.stream().map(String::valueOf).collect(Collectors.joining());
assertThat(StringUtils.isAnagram(s, shuffled)).isTrue();
- assertThat(StringUtils.isAnagram(s.toUpperCase(), shuffled.toLowerCase())).isTrue();
+ assertThat(StringUtils.isAnagram(s.toUpperCase(), shuffled.toLowerCase()))
+ .isTrue();
}
@Property
- void isAnagramAgreesWithLetterCounts(@ForAll @AlphaChars @StringLength(max = 6) String a,
- @ForAll @AlphaChars @StringLength(max = 6) String b) {
+ void isAnagramAgreesWithLetterCounts(
+ @ForAll @AlphaChars @StringLength(max = 6) String a, @ForAll @AlphaChars @StringLength(max = 6) String b) {
assertThat(StringUtils.isAnagram(a, b)).isEqualTo(letterCounts(a).equals(letterCounts(b)));
}
diff --git a/src/test/java/io/github/diegourban/algorithms/string/StringUtilsTest.java b/src/test/java/io/github/diegourban/algorithms/string/StringUtilsTest.java
index be626a8..2f4ff4f 100644
--- a/src/test/java/io/github/diegourban/algorithms/string/StringUtilsTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/string/StringUtilsTest.java
@@ -1,10 +1,8 @@
package io.github.diegourban.algorithms.string;
-import org.junit.jupiter.api.Test;
-
-
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+import org.junit.jupiter.api.Test;
class StringUtilsTest {
@@ -26,5 +24,4 @@ void shouldNotConsiderPalindrome() {
assertThat(StringUtils.isPalindrome("ab")).isFalse();
assertThat(StringUtils.isPalindrome("abb")).isFalse();
}
-
}
diff --git a/src/test/java/io/github/diegourban/algorithms/testing/SampleBuilder.java b/src/test/java/io/github/diegourban/algorithms/testing/SampleBuilder.java
index 83aa952..d86d5d6 100644
--- a/src/test/java/io/github/diegourban/algorithms/testing/SampleBuilder.java
+++ b/src/test/java/io/github/diegourban/algorithms/testing/SampleBuilder.java
@@ -76,5 +76,4 @@ private boolean endsWithSpaceSeparator() {
private void trim() {
this.stringBuilder.deleteCharAt(this.stringBuilder.length() - 1);
}
-
}
diff --git a/src/test/java/io/github/diegourban/algorithms/testing/SampleBuilderTest.java b/src/test/java/io/github/diegourban/algorithms/testing/SampleBuilderTest.java
index 544aea0..d4c5f78 100644
--- a/src/test/java/io/github/diegourban/algorithms/testing/SampleBuilderTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/testing/SampleBuilderTest.java
@@ -1,11 +1,11 @@
package io.github.diegourban.algorithms.testing;
+import static org.assertj.core.api.Assertions.assertThat;
+
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import static org.assertj.core.api.Assertions.assertThat;
-
class SampleBuilderTest {
private SampleBuilder sampleBuilder;
@@ -57,7 +57,12 @@ void shouldAppendString() {
@Test
void shouldAppendAllTypes() {
- String sample = this.sampleBuilder.append(123).append(9.9).append(9876543210L).append("bla bla").build();
+ String sample = this.sampleBuilder
+ .append(123)
+ .append(9.9)
+ .append(9876543210L)
+ .append("bla bla")
+ .build();
assertThat(sample).isEqualTo("123 9.9 9876543210 bla bla");
}
@@ -79,7 +84,8 @@ void shouldAppendTwoDoubleLines() {
@Test
void shouldAppendTwoLongLines() {
- String sample = this.sampleBuilder.appendln(123987123987L).append(1122334455L).build();
+ String sample =
+ this.sampleBuilder.appendln(123987123987L).append(1122334455L).build();
String expected = "123987123987" + System.lineSeparator() + "1122334455";
assertThat(sample).isEqualTo(expected);
@@ -111,10 +117,15 @@ void shouldAppendTwoLinesWithNewLineAtTheEnd() {
@Test
void shouldAppendFourLinesOneTypeEach() {
- String sample = this.sampleBuilder.appendln(123).appendln(987654321L).appendln(99.99).appendln("end").build();
-
- String expected = "123" + System.lineSeparator() + "987654321" + System.lineSeparator() + "99.99" + System.lineSeparator() + "end" + System.lineSeparator();
+ String sample = this.sampleBuilder
+ .appendln(123)
+ .appendln(987654321L)
+ .appendln(99.99)
+ .appendln("end")
+ .build();
+
+ String expected = "123" + System.lineSeparator() + "987654321" + System.lineSeparator() + "99.99"
+ + System.lineSeparator() + "end" + System.lineSeparator();
assertThat(sample).isEqualTo(expected);
}
-
}
diff --git a/src/test/java/io/github/diegourban/algorithms/testing/SampleLoaderTest.java b/src/test/java/io/github/diegourban/algorithms/testing/SampleLoaderTest.java
index 6e3e373..b58977d 100644
--- a/src/test/java/io/github/diegourban/algorithms/testing/SampleLoaderTest.java
+++ b/src/test/java/io/github/diegourban/algorithms/testing/SampleLoaderTest.java
@@ -1,10 +1,10 @@
package io.github.diegourban.algorithms.testing;
-import org.junit.jupiter.api.Test;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import org.junit.jupiter.api.Test;
+
class SampleLoaderTest {
private final SampleLoader loader = new SampleLoader("testing/sample-loader");
@@ -38,7 +38,8 @@ void shouldLoadAsInputStream() throws Exception {
@Test
void shouldAcceptTrailingSlash() {
- assertThat(new SampleLoader("testing/sample-loader/").loadAsString("sample.out")).startsWith("1");
+ assertThat(new SampleLoader("testing/sample-loader/").loadAsString("sample.out"))
+ .startsWith("1");
}
@Test