- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathMatrixChainRecursiveTopDownMemoisationTest.java
68 lines (60 loc) · 2.57 KB
/
MatrixChainRecursiveTopDownMemoisationTest.java
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
packagecom.thealgorithms.dynamicprogramming;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importorg.junit.jupiter.api.Test;
classMatrixChainRecursiveTopDownMemoisationTest {
/**
* Test case for four matrices with dimensions 1x2, 2x3, 3x4, and 4x5.
* The expected minimum number of multiplications is 38.
*/
@Test
voidtestFourMatrices() {
int[] dimensions = {1, 2, 3, 4, 5};
intexpected = 38;
intactual = MatrixChainRecursiveTopDownMemoisation.memoizedMatrixChain(dimensions);
assertEquals(expected, actual, "The minimum number of multiplications should be 38.");
}
/**
* Test case for three matrices with dimensions 10x20, 20x30, and 30x40.
* The expected minimum number of multiplications is 6000.
*/
@Test
voidtestThreeMatrices() {
int[] dimensions = {10, 20, 30, 40};
intexpected = 18000;
intactual = MatrixChainRecursiveTopDownMemoisation.memoizedMatrixChain(dimensions);
assertEquals(expected, actual, "The minimum number of multiplications should be 18000.");
}
/**
* Test case for two matrices with dimensions 5x10 and 10x20.
* The expected minimum number of multiplications is 1000.
*/
@Test
voidtestTwoMatrices() {
int[] dimensions = {5, 10, 20};
intexpected = 1000;
intactual = MatrixChainRecursiveTopDownMemoisation.memoizedMatrixChain(dimensions);
assertEquals(expected, actual, "The minimum number of multiplications should be 1000.");
}
/**
* Test case for a single matrix.
* The expected minimum number of multiplications is 0, as there are no multiplications needed.
*/
@Test
voidtestSingleMatrix() {
int[] dimensions = {10, 20}; // Single matrix dimensions
intexpected = 0;
intactual = MatrixChainRecursiveTopDownMemoisation.memoizedMatrixChain(dimensions);
assertEquals(expected, actual, "The minimum number of multiplications should be 0.");
}
/**
* Test case for matrices with varying dimensions.
* The expected minimum number of multiplications is calculated based on the dimensions provided.
*/
@Test
voidtestVaryingDimensions() {
int[] dimensions = {2, 3, 4, 5, 6}; // Dimensions for 4 matrices
intexpected = 124; // Expected value needs to be calculated based on the problem
intactual = MatrixChainRecursiveTopDownMemoisation.memoizedMatrixChain(dimensions);
assertEquals(expected, actual, "The minimum number of multiplications should be 124.");
}
}