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
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

import org.junit.jupiter.api.Test;
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;

public class KindergartenGardenTest {

@Test
@DisplayName("garden with single student")
public void singleStudent() {
String garden = "RC\nGG";
String student = "Alice";
Expand All @@ -17,6 +17,7 @@ public void singleStudent() {

@Disabled("Remove to run test")
@Test
@DisplayName("different garden with single student")
public void singleStudent2() {
String garden = "VC\nRC";
String student = "Alice";
Expand All @@ -27,6 +28,7 @@ public void singleStudent2() {

@Disabled("Remove to run test")
@Test
@DisplayName("garden with two students")
public void twoStudents() {
String garden = "VVCG\nVVRC";
String student = "Bob";
Expand All @@ -37,6 +39,7 @@ public void twoStudents() {

@Disabled("Remove to run test")
@Test
@DisplayName("second student's garden")
public void oneGardenSecondStudent() {
String garden = "VVCCGG\nVVCCGG";
String student = "Bob";
Expand All @@ -47,6 +50,7 @@ public void oneGardenSecondStudent() {

@Disabled("Remove to run test")
@Test
@DisplayName("third student's garden")
public void oneGardenThirdStudent() {
String garden = "VVCCGG\nVVCCGG";
String student = "Charlie";
Expand All @@ -57,6 +61,7 @@ public void oneGardenThirdStudent() {

@Disabled("Remove to run test")
@Test
@DisplayName("for Alice, first student's garden")
public void fullGardenForAlice() {
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
String student = "Alice";
Expand All @@ -67,6 +72,7 @@ public void fullGardenForAlice() {

@Disabled("Remove to run test")
@Test
@DisplayName("for Bob, second student's garden")
public void fullGardenForBob() {
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
String student = "Bob";
Expand All @@ -77,6 +83,7 @@ public void fullGardenForBob() {

@Disabled("Remove to run test")
@Test
@DisplayName("for Charlie")
public void fullGardenForCharlie() {
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
String student = "Charlie";
Expand All @@ -87,6 +94,7 @@ public void fullGardenForCharlie() {

@Disabled("Remove to run test")
@Test
@DisplayName("for David")
public void fullGardenForDavid() {
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
String student = "David";
Expand All @@ -97,6 +105,7 @@ public void fullGardenForDavid() {

@Disabled("Remove to run test")
@Test
@DisplayName("for Eve")
public void fullGardenForEve() {
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
String student = "Eve";
Expand All @@ -107,6 +116,7 @@ public void fullGardenForEve() {

@Disabled("Remove to run test")
@Test
@DisplayName("for Fred")
public void fullGardenForFred() {
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
String student = "Fred";
Expand All @@ -117,6 +127,7 @@ public void fullGardenForFred() {

@Disabled("Remove to run test")
@Test
@DisplayName("for Ginny")
public void fullGardenForGinny() {
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
String student = "Ginny";
Expand All @@ -127,6 +138,7 @@ public void fullGardenForGinny() {

@Disabled("Remove to run test")
@Test
@DisplayName("for Harriet")
public void fullGardenForHarriet() {
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
String student = "Harriet";
Expand All @@ -137,6 +149,7 @@ public void fullGardenForHarriet() {

@Disabled("Remove to run test")
@Test
@DisplayName("for Ileana")
public void fullGardenForIleana() {
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
String student = "Ileana";
Expand All @@ -147,6 +160,7 @@ public void fullGardenForIleana() {

@Disabled("Remove to run test")
@Test
@DisplayName("for Joseph")
public void fullGardenForJoseph() {
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
String student = "Joseph";
Expand All @@ -157,6 +171,7 @@ public void fullGardenForJoseph() {

@Disabled("Remove to run test")
@Test
@DisplayName("for Kincaid, second to last student's garden")
public void fullGardenForKincaid() {
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
String student = "Kincaid";
Expand All @@ -167,6 +182,7 @@ public void fullGardenForKincaid() {

@Disabled("Remove to run test")
@Test
@DisplayName("for Larry, last student's garden")
public void fullGardenForLarry() {
String garden = "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV";
String student = "Larry";
Expand Down
10 changes: 9 additions & 1 deletion exercises/practice/knapsack/src/test/java/KnapsackTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.junit.jupiter.api.Disabled;
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 java.util.List;
Expand All @@ -17,13 +18,15 @@ public void setup() {
}

@Test
@DisplayName("no items")
public void testNoItems() {
List<Item> items = List.of();
assertThat(knapsack.maximumValue(100, items)).isEqualTo(0);
}

@Disabled("Remove to run test")
@Test
@DisplayName("one item, too heavy")
public void testOneItemTooHeavy() {
List<Item> items = List.of(
new Item(100, 1)
Expand All @@ -34,6 +37,7 @@ public void testOneItemTooHeavy() {

@Disabled("Remove to run test")
@Test
@DisplayName("five items (cannot be greedy by weight)")
public void testFiveItemsCannotBeGreedyByWeight() {
List<Item> items = List.of(
new Item(2, 5),
Expand All @@ -48,6 +52,7 @@ public void testFiveItemsCannotBeGreedyByWeight() {

@Disabled("Remove to run test")
@Test
@DisplayName("five items (cannot be greedy by value)")
public void testFiveItemsCannotBeGreedyByValue() {
List<Item> items = List.of(
new Item(2, 20),
Expand All @@ -62,6 +67,7 @@ public void testFiveItemsCannotBeGreedyByValue() {

@Disabled("Remove to run test")
@Test
@DisplayName("example knapsack")
public void testExampleKnapsack() {
List<Item> items = List.of(
new Item(5, 10),
Expand All @@ -75,6 +81,7 @@ public void testExampleKnapsack() {

@Disabled("Remove to run test")
@Test
@DisplayName("8 items")
public void testEightItems() {
List<Item> items = List.of(
new Item(25, 350),
Expand All @@ -92,6 +99,7 @@ public void testEightItems() {

@Disabled("Remove to run test")
@Test
@DisplayName("15 items")
public void testFifteenItems() {
List<Item> items = List.of(
new Item(70, 135),
Expand Down
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 static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -7,6 +8,7 @@
public class LargestSeriesProductCalculatorTest {

@Test
@DisplayName("finds the largest product if span equals length")
public void testCorrectlyCalculatesLargestProductWhenSeriesLengthEqualsStringToSearchLength() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("29");
long expectedProduct = 18;
Expand All @@ -18,6 +20,7 @@ public void testCorrectlyCalculatesLargestProductWhenSeriesLengthEqualsStringToS

@Disabled("Remove to run test")
@Test
@DisplayName("can find the largest product of 2 with numbers in order")
public void testCorrectlyCalculatesLargestProductOfLengthTwoWithNumbersInOrder() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("0123456789");
long expectedProduct = 72;
Expand All @@ -29,6 +32,7 @@ public void testCorrectlyCalculatesLargestProductOfLengthTwoWithNumbersInOrder()

@Disabled("Remove to run test")
@Test
@DisplayName("can find the largest product of 2")
public void testCorrectlyCalculatesLargestProductOfLengthTwoWithNumbersNotInOrder() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("576802143");
long expectedProduct = 48;
Expand All @@ -40,6 +44,7 @@ public void testCorrectlyCalculatesLargestProductOfLengthTwoWithNumbersNotInOrde

@Disabled("Remove to run test")
@Test
@DisplayName("can find the largest product of 3 with numbers in order")
public void testCorrectlyCalculatesLargestProductOfLengthThreeWithNumbersInOrder() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("0123456789");
long expectedProduct = 504;
Expand All @@ -51,6 +56,7 @@ public void testCorrectlyCalculatesLargestProductOfLengthThreeWithNumbersInOrder

@Disabled("Remove to run test")
@Test
@DisplayName("can find the largest product of 3")
public void testCorrectlyCalculatesLargestProductOfLengthThreeWithNumbersNotInOrder() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("1027839564");
long expectedProduct = 270;
Expand All @@ -62,6 +68,7 @@ public void testCorrectlyCalculatesLargestProductOfLengthThreeWithNumbersNotInOr

@Disabled("Remove to run test")
@Test
@DisplayName("can find the largest product of 5 with numbers in order")
public void testCorrectlyCalculatesLargestProductOfLengthFiveWithNumbersInOrder() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("0123456789");
long expectedProduct = 15120;
Expand All @@ -73,6 +80,7 @@ public void testCorrectlyCalculatesLargestProductOfLengthFiveWithNumbersInOrder(

@Disabled("Remove to run test")
@Test
@DisplayName("can get the largest product of a big number")
public void testCorrectlyCalculatesLargestProductInLongStringToSearchV1() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator(
"73167176531330624919225119674426574742355349194934");
Expand All @@ -86,6 +94,7 @@ public void testCorrectlyCalculatesLargestProductInLongStringToSearchV1() {

@Disabled("Remove to run test")
@Test
@DisplayName("reports zero if the only digits are zero")
public void testCorrectlyCalculatesLargestProductOfZeroIfAllDigitsAreZeroes() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("0000");
long expectedProduct = 0;
Expand All @@ -97,6 +106,7 @@ public void testCorrectlyCalculatesLargestProductOfZeroIfAllDigitsAreZeroes() {

@Disabled("Remove to run test")
@Test
@DisplayName("reports zero if all spans include zero")
public void testCorrectlyCalculatesLargestProductOfZeroIfAllSeriesOfGivenLengthContainZero() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("99099");
long expectedProduct = 0;
Expand All @@ -108,6 +118,7 @@ public void testCorrectlyCalculatesLargestProductOfZeroIfAllSeriesOfGivenLengthC

@Disabled("Remove to run test")
@Test
@DisplayName("rejects span longer than string length")
public void testSeriesLengthLongerThanLengthOfStringToTestIsRejected() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("123");

Expand All @@ -118,6 +129,7 @@ public void testSeriesLengthLongerThanLengthOfStringToTestIsRejected() {

@Disabled("Remove to run test")
@Test
@DisplayName("reports 1 for empty string and empty product (0 span)")
public void testEmptyStringToSearchAndSeriesOfNonZeroLengthIsRejected() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("");

Expand All @@ -128,6 +140,7 @@ public void testEmptyStringToSearchAndSeriesOfNonZeroLengthIsRejected() {

@Disabled("Remove to run test")
@Test
@DisplayName("rejects invalid character in digits")
public void testStringToSearchContainingNonDigitCharacterIsRejected() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> new LargestSeriesProductCalculator("1234a5"))
Expand All @@ -136,6 +149,7 @@ public void testStringToSearchContainingNonDigitCharacterIsRejected() {

@Disabled("Remove to run test")
@Test
@DisplayName("rejects negative span")
public void testNegativeSeriesLengthIsRejected() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("12345");

Expand All @@ -146,6 +160,7 @@ public void testNegativeSeriesLengthIsRejected() {

@Disabled("Remove to run test")
@Test
@DisplayName("integer overflow")
public void testForIntegerOverflow() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("9999999999");
long expectedProduct = 3486784401L;
Expand Down
10 changes: 10 additions & 0 deletions exercises/practice/leap/src/test/java/LeapTest.java
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,54 +15,63 @@ public void setup() {
}

@Test
@DisplayName("year not divisible by 4 in common year")
public void testYearNotDivBy4InCommonYear() {
assertThat(leap.isLeapYear(2015)).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("year divisible by 2, not divisible by 4 in common year\"")
public void testYearDivBy2NotDivBy4InCommonYear() {
assertThat(leap.isLeapYear(1970)).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("year divisible by 4, not divisible by 100 in leap year")
public void testYearDivBy4NotDivBy100InLeapYear() {
assertThat(leap.isLeapYear(1996)).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("year divisible by 4 and 5 is still a leap year")
public void testYearDivBy4And5InLeapYear() {
assertThat(leap.isLeapYear(1960)).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("year divisible by 100, not divisible by 400 in common year")
public void testYearDivBy100NotDivBy400InCommonYear() {
assertThat(leap.isLeapYear(2100)).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("year divisible by 100 but not by 3 is still not a leap year")
public void testYearDivBy100NotDivBy3IsNotLeapYear() {
assertThat(leap.isLeapYear(1900)).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("year divisible by 400 is leap year")
public void testYearDivBy400InLeapYear() {
assertThat(leap.isLeapYear(2000)).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("year divisible by 400 but not by 125 is still a leap year")
public void testYearDivBy400NotDivBy125IsLeapYear() {
assertThat(leap.isLeapYear(2400)).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("year divisible by 200, not divisible by 400 in common year")
public void testYearDivBy200NotDivBy400InCommonYear() {
assertThat(leap.isLeapYear(1800)).isFalse();
}
Expand Down