-
Notifications
You must be signed in to change notification settings - Fork 19.4k
/
MatrixChainRecursiveTopDownMemoisationTest.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
package com.thealgorithms.dynamicprogramming;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class MatrixChainRecursiveTopDownMemoisationTest {
/**
* Test case for four matrices with dimensions 1x2, 2x3, 3x4, and 4x5.
* The expected minimum number of multiplications is 38.
*/
@Test
void testFourMatrices() {
int[] dimensions = {1, 2, 3, 4, 5};
int expected = 38;
int actual = 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
void testThreeMatrices() {
int[] dimensions = {10, 20, 30, 40};
int expected = 18000;
int actual = 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
void testTwoMatrices() {
int[] dimensions = {5, 10, 20};
int expected = 1000;
int actual = 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
void testSingleMatrix() {
int[] dimensions = {10, 20}; // Single matrix dimensions
int expected = 0;
int actual = 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
void testVaryingDimensions() {
int[] dimensions = {2, 3, 4, 5, 6}; // Dimensions for 4 matrices
int expected = 124; // Expected value needs to be calculated based on the problem
int actual = MatrixChainRecursiveTopDownMemoisation.memoizedMatrixChain(dimensions);
assertEquals(expected, actual, "The minimum number of multiplications should be 124.");
}
}