Skip to content

Commit

Permalink
Update tests to use assertj (#2510)
Browse files Browse the repository at this point in the history
* Update tests to use assertj

* Fix style check in DominoesTest

* Fix style check

* Revert changes in deprecated exercise
  • Loading branch information
pavanbaloju authored Oct 5, 2023
1 parent 633956b commit edb5725
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 147 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;

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

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

public class CollatzCalculatorTest {

private CollatzCalculator collatzCalculator = new CollatzCalculator();

@Test
public void testZeroStepsRequiredWhenStartingFrom1() {
assertEquals(0, collatzCalculator.computeStepCount(1));
assertThat(collatzCalculator.computeStepCount(1)).isEqualTo(0);
}

@Ignore("Remove to run test")
@Test
public void testCorrectNumberOfStepsWhenAllStepsAreDivisions() {
assertEquals(4, collatzCalculator.computeStepCount(16));
assertThat(collatzCalculator.computeStepCount(16)).isEqualTo(4);
}

@Ignore("Remove to run test")
@Test
public void testCorrectNumberOfStepsWhenBothStepTypesAreNeeded() {
assertEquals(9, collatzCalculator.computeStepCount(12));
assertThat(collatzCalculator.computeStepCount(12)).isEqualTo(9);
}

@Ignore("Remove to run test")
@Test
public void testAVeryLargeInput() {
assertEquals(152, collatzCalculator.computeStepCount(1000000));
assertThat(collatzCalculator.computeStepCount(1000000)).isEqualTo(152);
}

@Ignore("Remove to run test")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

public class CryptoSquareTest {

Expand All @@ -10,7 +10,7 @@ public void emptyPlaintextResultsInEmptyCiphertext() {
CryptoSquare cryptoSquare = new CryptoSquare("");
String expectedOutput = "";

assertEquals(expectedOutput, cryptoSquare.getCiphertext());
assertThat(cryptoSquare.getCiphertext()).isEqualTo(expectedOutput);
}

@Ignore("Remove to run test")
Expand All @@ -19,7 +19,7 @@ public void lettersAreLowerCasedDuringEncryption() {
CryptoSquare cryptoSquare = new CryptoSquare("A");
String expectedOutput = "a";

assertEquals(expectedOutput, cryptoSquare.getCiphertext());
assertThat(cryptoSquare.getCiphertext()).isEqualTo(expectedOutput);
}

@Ignore("Remove to run test")
Expand All @@ -28,7 +28,7 @@ public void spacesAreRemovedDuringEncryption() {
CryptoSquare cryptoSquare = new CryptoSquare(" b ");
String expectedOutput = "b";

assertEquals(expectedOutput, cryptoSquare.getCiphertext());
assertThat(cryptoSquare.getCiphertext()).isEqualTo(expectedOutput);
}

@Ignore("Remove to run test")
Expand All @@ -37,7 +37,7 @@ public void punctuationIsRemovedDuringEncryption() {
CryptoSquare cryptoSquare = new CryptoSquare("@1,%!");
String expectedOutput = "1";

assertEquals(expectedOutput, cryptoSquare.getCiphertext());
assertThat(cryptoSquare.getCiphertext()).isEqualTo(expectedOutput);
}

@Ignore("Remove to run test")
Expand All @@ -46,7 +46,7 @@ public void nineCharacterPlaintextResultsInThreeChunksOfThreeCharacters() {
CryptoSquare cryptoSquare = new CryptoSquare("This is fun!");
String expectedOutput = "tsf hiu isn";

assertEquals(expectedOutput, cryptoSquare.getCiphertext());
assertThat(cryptoSquare.getCiphertext()).isEqualTo(expectedOutput);
}

@Ignore("Remove to run test")
Expand All @@ -55,7 +55,7 @@ public void eightCharacterPlaintextResultsInThreeChunksWithATrailingSpace() {
CryptoSquare cryptoSquare = new CryptoSquare("Chill out.");
String expectedOutput = "clu hlt io ";

assertEquals(expectedOutput, cryptoSquare.getCiphertext());
assertThat(cryptoSquare.getCiphertext()).isEqualTo(expectedOutput);
}

@Ignore("Remove to run test")
Expand All @@ -65,6 +65,6 @@ public void fiftyFourCharacterPlaintextResultsInSevenChunksWithTrailingSpaces()
"given us roots.");
String expectedOutput = "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau ";

assertEquals(expectedOutput, cryptoSquare.getCiphertext());
assertThat(cryptoSquare.getCiphertext()).isEqualTo(expectedOutput);
}
}
28 changes: 14 additions & 14 deletions exercises/practice/darts/src/test/java/DartsTest.java
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

public class DartsTest {

Darts darts = new Darts();
@Test
public void missedTarget() {
assertEquals(0, darts.score(-9, 9));
assertThat(darts.score(-9, 9)).isEqualTo(0);
}

@Ignore("Remove to run test")
@Test
public void onTheOuterCircle() {
assertEquals(1, darts.score(0, 10));
assertThat(darts.score(0, 10)).isEqualTo(1);
}

@Ignore("Remove to run test")
@Test
public void onTheMiddleCircle() {
assertEquals(5, darts.score(-5, 0));
assertThat(darts.score(-5, 0)).isEqualTo(5);
}

@Ignore("Remove to run test")
@Test
public void onTheInnerCircle() {
assertEquals(10, darts.score(0, -1));
assertThat(darts.score(0, -1)).isEqualTo(10);
}

@Ignore("Remove to run test")
@Test
public void exactlyOnCentre() {
assertEquals(10, darts.score(0, 0));
assertThat(darts.score(0, 0)).isEqualTo(10);
}

@Ignore("Remove to run test")
@Test
public void nearTheCentre() {
assertEquals(10, darts.score(-0.1, -0.1));
assertThat(darts.score(-0.1, -0.1)).isEqualTo(10);
}

@Ignore("Remove to run test")
@Test
public void justWithinTheInnerCircle() {
assertEquals(10, darts.score(0.7, 0.7));
assertThat(darts.score(0.7, 0.7)).isEqualTo(10);
}

@Ignore("Remove to run test")
@Test
public void justOutsideTheInnerCircle() {
assertEquals(5, darts.score(0.8, -0.8));
assertThat(darts.score(0.8, -0.8)).isEqualTo(5);
}

@Ignore("Remove to run test")
@Test
public void justWithinTheMiddleCircle() {
assertEquals(5, darts.score(-3.5, 3.5));
assertThat(darts.score(-3.5, 3.5)).isEqualTo(5);
}

@Ignore("Remove to run test")
@Test
public void justOutsideTheMiddleCircle() {
assertEquals(1, darts.score(-3.6, -3.6));
assertThat(darts.score(-3.6, -3.6)).isEqualTo(1);
}


@Ignore("Remove to run test")
@Test
public void justWithinTheOuterCircle() {
assertEquals(1, darts.score(-7.0, 7.0));
assertThat(darts.score(-7.0, 7.0)).isEqualTo(1);
}

@Ignore("Remove to run test")
@Test
public void justOutsideTheOuterCircle() {
assertEquals(0, darts.score(7.1, -7.1));
assertThat(darts.score(7.1, -7.1)).isEqualTo(0);
}

@Ignore("Remove to run test")
@Test
public void asymmetricPositionBetweenTheInnerAndMiddleCircles() {
assertEquals(5, darts.score(0.5, -4));
assertThat(darts.score(0.5, -4)).isEqualTo(5);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

public class DifferenceOfSquaresCalculatorTest {

Expand All @@ -17,71 +17,71 @@ public void setUp() {
public void testSquareOfSumUpToOne() {
int expected = 1;
int actual = calculator.computeSquareOfSumTo(1);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}

@Ignore("Remove to run test")
@Test
public void testSquareOfSumUpToFive() {
int expected = 225;
int actual = calculator.computeSquareOfSumTo(5);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}

@Ignore("Remove to run test")
@Test
public void testSquareOfSumUpToHundred() {
int expected = 25502500;
int actual = calculator.computeSquareOfSumTo(100);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}

@Ignore("Remove to run test")
@Test
public void testSumOfSquaresUpToOne() {
int expected = 1;
int actual = calculator.computeSumOfSquaresTo(1);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}

@Ignore("Remove to run test")
@Test
public void testSumOfSquaresUpToFive() {
int expected = 55;
int actual = calculator.computeSumOfSquaresTo(5);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}

@Ignore("Remove to run test")
@Test
public void testSumOfSquaresUpToHundred() {
int expected = 338350;
int actual = calculator.computeSumOfSquaresTo(100);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}

@Ignore("Remove to run test")
@Test
public void testDifferenceOfSquaresUpToOne() {
int expected = 0;
int actual = calculator.computeDifferenceOfSquares(1);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}

@Ignore("Remove to run test")
@Test
public void testDifferenceOfSquaresUpToFive() {
int expected = 170;
int actual = calculator.computeDifferenceOfSquares(5);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}

@Ignore("Remove to run test")
@Test
public void testDifferenceOfSquaresUpToHundred() {
int expected = 25164150;
int actual = calculator.computeDifferenceOfSquares(100);
assertEquals(expected, actual);
assertThat(actual).isEqualTo(expected);
}

}
Loading

0 comments on commit edb5725

Please sign in to comment.