Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package utils;
- public class Calculation {
- public static int findMax(int arr[]){
- int max = 0;
- if(arr != null) {
- for (int i = 0; i < arr.length; i++) {
- if (max < arr[i]) {
- max = arr[i];
- }
- }
- }
- return max;
- }
- public static int cube(int n){
- if (n > 0) {
- return n * n * n;
- }
- else{
- return 0;
- }
- }
- }
- //////////////////////////////////////////
- package test;
- import static org.junit.jupiter.api.Assertions.*;
- import org.junit.jupiter.api.BeforeAll;
- import org.junit.jupiter.api.DisplayName;
- import org.junit.jupiter.api.Test;
- import utils.Calculation;
- class CalculationTests {
- private static int[] value;
- @BeforeAll
- static void setUpBeforeClass() throws Exception {
- value = new int[]{2, -4, -8, 5, 8, 2, 1, 0};
- }
- @Test
- @DisplayName("Test find max providing diff nums")
- void testMax1() {
- assertEquals(8, Calculation.findMax(value));
- }
- @Test
- @DisplayName("Test find max providing null")
- void testMax2() {
- assertEquals(0, Calculation.findMax(null));
- }
- @Test
- @DisplayName("Test cube volume providing 0")
- void testCube1(){
- assertEquals(0, Calculation.cube(0));
- }
- @Test
- @DisplayName("Test cube volume providing positive num")
- void testCube2(){
- assertEquals(27, Calculation.cube(3));
- }
- @Test
- @DisplayName("Test cube volume providing negative num")
- void testCube3(){
- assertEquals(0, Calculation.cube(-4));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment