Skip to content

Commit 32f0107

Browse files
authored
Add files via upload
Adding matrix identity
1 parent 6949403 commit 32f0107

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.jwetherell.algorithms.mathematics;
2+
3+
public class MatrixIdentity {
4+
5+
public static int[][] getMatrixIdentity(int size){
6+
int[][] matrix = new int[size][size];
7+
for(int i = 0; i < size; ++i){
8+
matrix[i][i] = 1;
9+
}
10+
return matrix;
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.jwetherell.algorithms.mathematics.test;
2+
3+
import static org.junit.Assert.*;
4+
5+
import org.junit.Test;
6+
7+
import com.jwetherell.algorithms.mathematics.MatrixIdentity;
8+
9+
public class MatrixIdentityTest {
10+
11+
@Test
12+
public void test1() {
13+
int[][] matrix = MatrixIdentity.getMatrixIdentity(3);
14+
15+
assertEquals(1, matrix[0][0]);
16+
assertEquals(1, matrix[1][1]);
17+
assertEquals(1, matrix[2][2]);
18+
}
19+
20+
}

0 commit comments

Comments
 (0)