Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions exercises/practice/pov/src/test/java/PovTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.List;
Expand All @@ -9,6 +10,7 @@
public class PovTest {

@Test
@DisplayName("Results in the same tree if the input tree is a singleton")
public void testFromPovGivenSingletonTree() {
Tree tree = Tree.of("x");
Tree expected = Tree.of("x");
Expand All @@ -17,6 +19,7 @@ public void testFromPovGivenSingletonTree() {

@Disabled("Remove to run test")
@Test
@DisplayName("Can reroot a tree with a parent and one sibling")
public void testFromPovGivenTreeWithParentAndOneSibling() {
Tree tree = Tree.of("parent",
List.of(Tree.of("x"),
Expand All @@ -30,6 +33,7 @@ public void testFromPovGivenTreeWithParentAndOneSibling() {

@Disabled("Remove to run test")
@Test
@DisplayName("Can reroot a tree with a parent and many siblings")
public void testFromPovGivenTreeWithParentAndManySibling() {
Tree tree = Tree.of("parent",
List.of(Tree.of("x"),
Expand All @@ -48,6 +52,7 @@ public void testFromPovGivenTreeWithParentAndManySibling() {

@Disabled("Remove to run test")
@Test
@DisplayName("an reroot a tree with new root deeply nested in the tree")
public void testFromPovGivenTreeWithNewRootDeeplyNested() {
Tree tree = Tree.of("level-0",
List.of(Tree.of("level-1",
Expand All @@ -66,6 +71,7 @@ public void testFromPovGivenTreeWithNewRootDeeplyNested() {

@Disabled("Remove to run test")
@Test
@DisplayName("Moves children of the new root to same level as former parent")
public void testFromPovGivenMovesChildrenOfNewRootToSameLevelAsFormerParent() {
Tree tree = Tree.of("parent",
List.of(Tree.of("x",
Expand All @@ -82,6 +88,7 @@ public void testFromPovGivenMovesChildrenOfNewRootToSameLevelAsFormerParent() {

@Disabled("Remove to run test")
@Test
@DisplayName("Can reroot a complex tree with cousins")
public void testFromPovGivenComplexTreeWithCousins() {
Tree tree = Tree.of("grandparent",
List.of(Tree.of("parent",
Expand Down Expand Up @@ -110,6 +117,7 @@ public void testFromPovGivenComplexTreeWithCousins() {

@Disabled("Remove to run test")
@Test
@DisplayName("Errors if target does not exist in a singleton tree")
public void testFromPovGivenNonExistentTargetInSingletonTree() {
Tree tree = Tree.of("x");
assertThatExceptionOfType(UnsupportedOperationException.class)
Expand All @@ -119,6 +127,7 @@ public void testFromPovGivenNonExistentTargetInSingletonTree() {

@Disabled("Remove to run test")
@Test
@DisplayName("Errors if target does not exist in a larger tree")
public void testFromPovGivenNonExistentTargetInLargeTree() {
Tree tree = Tree.of("parent",
List.of(Tree.of("x",
Expand All @@ -134,6 +143,7 @@ public void testFromPovGivenNonExistentTargetInLargeTree() {

@Disabled("Remove to run test")
@Test
@DisplayName("Can find path to parent")
public void testPathToCanFindPathToParent() {
Tree tree = Tree.of("parent",
List.of(Tree.of("x"),
Expand All @@ -158,6 +168,7 @@ public void testPathToCanFindPathToSibling() {

@Disabled("Remove to run test")
@Test
@DisplayName("Can find path to cousin")
public void testPathToCanFindPathToCousin() {
Tree tree = Tree.of("grandparent",
List.of(Tree.of("parent",
Expand All @@ -176,6 +187,7 @@ public void testPathToCanFindPathToCousin() {

@Disabled("Remove to run test")
@Test
@DisplayName("Can find path not involving root")
public void testPathToCanFindPathNotEnvolvingRoot() {
Tree tree = Tree.of("grandparent",
List.of(Tree.of("parent",
Expand All @@ -189,6 +201,7 @@ public void testPathToCanFindPathNotEnvolvingRoot() {

@Disabled("Remove to run test")
@Test
@DisplayName("Can find path from nodes other than x")
public void testPathToCanFindPathFromNodesOtherThanX() {
Tree tree = Tree.of("parent",
List.of(Tree.of("a"),
Expand All @@ -202,6 +215,7 @@ public void testPathToCanFindPathFromNodesOtherThanX() {

@Disabled("Remove to run test")
@Test
@DisplayName("Errors if destination does not exist")
public void testPathWhenDestinationDoesNotExist() {
Tree tree = Tree.of("parent",
List.of(Tree.of("x",
Expand All @@ -217,6 +231,7 @@ public void testPathWhenDestinationDoesNotExist() {

@Disabled("Remove to run test")
@Test
@DisplayName("Errors if source does not exist")
public void testPathWhenSourceDoesNotExist() {
Tree tree = Tree.of("parent",
List.of(Tree.of("x",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -14,72 +15,84 @@ public void setUp() {
}

@Test
@DisplayName("no factors")
public void testNoFactors() {
assertThat(primeFactorsCalculator.calculatePrimeFactorsOf(1L)).isEmpty();
}

@Disabled("Remove to run test")
@Test
@DisplayName("prime number")
public void testPrimeNumber() {
assertThat(primeFactorsCalculator.calculatePrimeFactorsOf(2L)).containsExactly(2L);
}

@Disabled("Remove to run test")
@Test
@DisplayName("another prime number")
public void testAnotherPrimeNumber() {
assertThat(primeFactorsCalculator.calculatePrimeFactorsOf(3L)).containsExactly(3L);
}

@Disabled("Remove to run test")
@Test
@DisplayName("square of a prime")
public void testSquareOfAPrime() {
assertThat(primeFactorsCalculator.calculatePrimeFactorsOf(9L)).containsExactly(3L, 3L);
}

@Disabled("Remove to run test")
@Test
@DisplayName("product of first prime")
public void testProductOfFirstPrime() {
assertThat(primeFactorsCalculator.calculatePrimeFactorsOf(4L)).containsExactly(2L, 2L);
}

@Disabled("Remove to run test")
@Test
@DisplayName("cube of a prime")
public void testCubeOfAPrime() {
assertThat(primeFactorsCalculator.calculatePrimeFactorsOf(8L)).containsExactly(2L, 2L, 2L);
}

@Disabled("Remove to run test")
@Test
@DisplayName("product of second prime")
public void testProductOfSecondPrime() {
assertThat(primeFactorsCalculator.calculatePrimeFactorsOf(625L)).containsExactly(5L, 5L, 5L, 5L);
}

@Disabled("Remove to run test")
@Test
@DisplayName("product of third prime")
public void testProductOfThirdPrime() {
assertThat(primeFactorsCalculator.calculatePrimeFactorsOf(27L)).containsExactly(3L, 3L, 3L);
}

@Disabled("Remove to run test")
@Test
@DisplayName("product of first and second prime")
public void testProductOfFirstAndSecondPrime() {
assertThat(primeFactorsCalculator.calculatePrimeFactorsOf(6L)).containsExactly(2L, 3L);
}

@Disabled("Remove to run test")
@Test
@DisplayName("product of primes and non-primes")
public void testProductOfPrimesAndNonPrimes() {
assertThat(primeFactorsCalculator.calculatePrimeFactorsOf(12L)).containsExactly(2L, 2L, 3L);
}

@Disabled("Remove to run test")
@Test
@DisplayName("product of primes")
public void testProductOfPrimes() {
assertThat(primeFactorsCalculator.calculatePrimeFactorsOf(901255L)).containsExactly(5L, 17L, 23L, 461L);
}

@Disabled("Remove to run test")
@Test
@DisplayName("factors include a large prime")
public void testFactorsIncludingALargePrime() {
assertThat(primeFactorsCalculator.calculatePrimeFactorsOf(93819012551L)).containsExactly(11L, 9539L, 894119L);
}
Expand Down
Loading