Skip to content

Commit

Permalink
6.6.4. Двухмерный массив. Таблица умножения;
Browse files Browse the repository at this point in the history
  • Loading branch information
Temzor committed Oct 3, 2023
1 parent 0564699 commit 7aebab0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/ru/j4j/array/Matrix.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ru.j4j.array;

public class Matrix {
public static int[][] multiple(int size) {
int[][] table = new int[size][size];
for (int row = 0; row < table.length; row++) {
for (int cell = 0; cell < table[row].length; cell++) {
table[row][cell] = (row + 1) * (cell + 1);
}
}
return table;
}
}
32 changes: 32 additions & 0 deletions src/test/java/ru/j4j/array/MatrixTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ru.j4j.array;

import static org.assertj.core.api.Assertions.*;

import org.junit.jupiter.api.Test;

class MatrixTest {
@Test
public void when2on2() {
int size = 2;
int[][] result = Matrix.multiple(size);
int[][] expected = {
{1, 2},
{2, 4}
};
assertThat(result).isDeepEqualTo(expected);
}

@Test
public void when5on5() {
int size = 5;
int[][] result = Matrix.multiple(size);
int[][] expected = {
{1, 2, 3, 4, 5},
{2, 4, 6, 8, 10},
{3, 6, 9, 12, 15},
{4, 8, 12, 16, 20},
{5, 10, 15, 20, 25}
};
assertThat(result).isDeepEqualTo(expected);
}
}

0 comments on commit 7aebab0

Please sign in to comment.