mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-28 15:02:46 +08:00
Add Pascal's Triangle (#2871)
Co-authored-by: Andrii Siriak <siryaka@gmail.com>
This commit is contained in:
@ -0,0 +1,42 @@
|
||||
|
||||
package com.thealgorithms.maths;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class PascalTriangleTest {
|
||||
|
||||
@Test
|
||||
void testForOne()
|
||||
{
|
||||
int[][] result = PascalTriangle.pascal(1);
|
||||
int[][] expected = {{1}};
|
||||
assertArrayEquals(result,expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForTwo()
|
||||
{
|
||||
int[][] result = PascalTriangle.pascal(2);
|
||||
int[][] expected = {{1,0},{1,1}};
|
||||
assertArrayEquals(result,expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForFive()
|
||||
{
|
||||
int[][] result = PascalTriangle.pascal(5);
|
||||
int[][] expected = {{1,0,0,0,0},{1,1,0,0,0},{1,2,1,0,0},{1,3,3,1,0},{1,4,6,4,1}};
|
||||
assertArrayEquals(result,expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForEight() {
|
||||
int[][] result = PascalTriangle.pascal(8);
|
||||
int[][] expected = {{1,0,0,0,0,0,0,0},{1,1,0,0,0,0,0,0},{1,2,1,0,0,0,0,0},{1,3,3,1,0,0,0,0},{1,4,6,4,1,0,0,0},{1,5,10,10,5,1,0,0},{1,6,15,20,15,6,1,0},{1,7,21,35,35,21,7,1}};
|
||||
assertArrayEquals(expected, result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -12,21 +12,21 @@ class ArrayLeftRotationTest {
|
||||
int[] result = ArrayLeftRotation.rotateLeft(arr, 3);
|
||||
assertArrayEquals(arr, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testForZeroStep() {
|
||||
int[] arr = {3, 1, 5, 8, 6};
|
||||
int[] result = ArrayLeftRotation.rotateLeft(arr, 0);
|
||||
assertArrayEquals(arr, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testForEqualSizeStep() {
|
||||
int[] arr = {3, 1, 5, 8, 6};
|
||||
int[] result = ArrayLeftRotation.rotateLeft(arr, 5);
|
||||
assertArrayEquals(arr, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testForLowerSizeStep() {
|
||||
int[] arr = {3, 1, 5, 8, 6};
|
||||
@ -35,7 +35,7 @@ class ArrayLeftRotationTest {
|
||||
int[] result = ArrayLeftRotation.rotateLeft(arr, n);
|
||||
assertArrayEquals(expected, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testForHigherSizeStep() {
|
||||
int[] arr = {3, 1, 5, 8, 6};
|
||||
@ -45,4 +45,4 @@ class ArrayLeftRotationTest {
|
||||
assertArrayEquals(expected, result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user