Skip to content

Commit

Permalink
Update tests to use assertj (exercism#2147)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavanbaloju committed Oct 5, 2023
1 parent 438b3ed commit f703a80
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 158 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);
}

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

import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;

import java.math.BigInteger;
import java.util.*;
import java.util.ArrayList;
import java.util.List;

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

public class DiffieHellmanTest {

Expand All @@ -27,8 +26,8 @@ public void testPrivateKeyInRange() {
}

for (BigInteger privateKey : privateKeys) {
assertTrue(privateKey.compareTo(BigInteger.ONE) >= 0);
assertTrue(privateKey.compareTo(prime) < 0);
assertThat(privateKey.compareTo(BigInteger.ONE)).isGreaterThanOrEqualTo(0);
assertThat(privateKey.compareTo(prime)).isLessThan(0);
}
}

Expand All @@ -41,7 +40,7 @@ public void testPrivateKeyRandomlyGenerated() {
BigInteger privateKeyA = diffieHellman.privateKey(prime);
BigInteger privateKeyB = diffieHellman.privateKey(prime);

assertNotEquals(privateKeyA, privateKeyB);
assertThat(privateKeyA).isNotEqualTo(privateKeyB);
}

@Ignore("Remove to run test")
Expand All @@ -52,7 +51,7 @@ public void testPublicKeyCorrectlyCalculated() {
BigInteger privateKey = BigInteger.valueOf(6);
BigInteger expected = BigInteger.valueOf(8);

assertEquals(expected, diffieHellman.publicKey(primeA, primeB, privateKey));
assertThat(diffieHellman.publicKey(primeA, primeB, privateKey)).isEqualTo(expected);
}

@Ignore("Remove to run test")
Expand All @@ -63,7 +62,7 @@ public void testSecretKeyCorrectlyCalculated() {
BigInteger privateKey = BigInteger.valueOf(6);
BigInteger expected = BigInteger.valueOf(2);

assertEquals(expected, diffieHellman.secret(prime, publicKey, privateKey));
assertThat(diffieHellman.secret(prime, publicKey, privateKey)).isEqualTo(expected);
}

@Ignore("Remove to run test")
Expand All @@ -81,7 +80,7 @@ public void testExchange() {
BigInteger secretA = diffieHellman.secret(primeA, bobPublicKey, alicePrivateKey);
BigInteger secretB = diffieHellman.secret(primeA, alicePublicKey, bobPrivateKey);

assertEquals(secretA, secretB);
assertThat(secretA).isEqualTo(secretB);
}

}
Loading

0 comments on commit f703a80

Please sign in to comment.