-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolutionTest.java
More file actions
55 lines (44 loc) · 1.59 KB
/
SolutionTest.java
File metadata and controls
55 lines (44 loc) · 1.59 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
package math.power;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
class SolutionTest {
private final Solution solution = new Solution();
@Test
void powerNaive_FiveCubed_ExpectedResult() {
long result = solution.powerNaive(5, 4);
assertThat(result).isEqualTo(625);
}
@Test
void powerEfficient_ZeroExponent_AlwaysOne() {
long result = solution.powerEfficient(111, 0);
assertThat(result).isEqualTo(1);
}
@Test
void powerEfficient_ExponentDivisionAlwaysEven_ExpectedResult() {
long result = solution.powerEfficient(2, 8);
assertThat(result).isEqualTo(32);
}
@Test
void powerEfficient_ExponentDivisionHasOdd_ExpectedResult() {
long result = solution.powerEfficient(3, 5);
assertThat(result).isEqualTo(243); // 3 ^ 5 -> 9 ^ 2 * 3 -> 81 ^ 1 * 3
}
/**
* @see <a href="https://www.math.utah.edu/~pa/math/0to0.html">What is 0 to the power 0?</a>
*/
@Test
void powerEfficient_ZeroToZero_UndefinedBehaviorReturnOne() {
long result = solution.powerEfficient(0, 0);
assertThat(result).isEqualTo(1);
}
@Test
void powerEfficientBinOperators_TwoToFive_ExpectedResult() {
long result = solution.powerEfficientBinOperators(2, 5);
assertThat(result).isEqualTo(32);
}
@Test
void powerEfficientRecursive_EightToEight_ExpectedResult() {
long result = solution.powerEfficientRecursive(8, 8);
assertThat(result).isEqualTo(16_777_216); // 8 ^ 8 -> 64 ^ 4 -> 4096 ^ 2 -> 16777216 ^ 1
}
}