forked from exercism/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargestSeriesProductCalculatorTest.java
More file actions
150 lines (114 loc) · 5.98 KB
/
Copy pathLargestSeriesProductCalculatorTest.java
File metadata and controls
150 lines (114 loc) · 5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
public class LargestSeriesProductCalculatorTest {
@Test
@DisplayName("finds the largest product if span equals length")
public void testCorrectlyCalculatesLargestProductWhenSeriesLengthEqualsStringToSearchLength() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("29");
long expectedProduct = 18;
long actualProduct = calculator.calculateLargestProductForSeriesLength(2);
assertThat(actualProduct).isEqualTo(expectedProduct);
}
@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;
long actualProduct = calculator.calculateLargestProductForSeriesLength(2);
assertThat(actualProduct).isEqualTo(expectedProduct);
}
@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;
long actualProduct = calculator.calculateLargestProductForSeriesLength(2);
assertThat(actualProduct).isEqualTo(expectedProduct);
}
@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;
long actualProduct = calculator.calculateLargestProductForSeriesLength(3);
assertThat(actualProduct).isEqualTo(expectedProduct);
}
@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;
long actualProduct = calculator.calculateLargestProductForSeriesLength(3);
assertThat(actualProduct).isEqualTo(expectedProduct);
}
@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;
long actualProduct = calculator.calculateLargestProductForSeriesLength(5);
assertThat(actualProduct).isEqualTo(expectedProduct);
}
@Disabled("Remove to run test")
@Test
@DisplayName("can get the largest product of a big number")
public void testCorrectlyCalculatesLargestProductInLongStringToSearchV1() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator(
"73167176531330624919225119674426574742355349194934");
long expectedProduct = 23520;
long actualProduct = calculator.calculateLargestProductForSeriesLength(6);
assertThat(actualProduct).isEqualTo(expectedProduct);
}
@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;
long actualProduct = calculator.calculateLargestProductForSeriesLength(2);
assertThat(actualProduct).isEqualTo(expectedProduct);
}
@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;
long actualProduct = calculator.calculateLargestProductForSeriesLength(3);
assertThat(actualProduct).isEqualTo(expectedProduct);
}
@Disabled("Remove to run test")
@Test
@DisplayName("rejects span longer than string length")
public void testSeriesLengthLongerThanLengthOfStringToTestIsRejected() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("123");
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> calculator.calculateLargestProductForSeriesLength(4))
.withMessage("Series length must be less than or equal to the length of the string to search.");
}
@Disabled("Remove to run test")
@Test
@DisplayName("rejects invalid character in digits")
public void testStringToSearchContainingNonDigitCharacterIsRejected() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> new LargestSeriesProductCalculator("1234a5"))
.withMessage("String to search may only contain digits.");
}
@Disabled("Remove to run test")
@Test
@DisplayName("integer overflow")
public void testForIntegerOverflow() {
LargestSeriesProductCalculator calculator = new LargestSeriesProductCalculator("9999999999");
long expectedProduct = 3486784401L;
long actualProduct = calculator.calculateLargestProductForSeriesLength(10);
assertThat(actualProduct).isEqualTo(expectedProduct);
}
}