atanasovetr

Calculations and Testing

Feb 17th, 2021
1,161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. package utils;
  2.  
  3. public class Calculation {
  4.     public static int findMax(int arr[]){
  5.         int max = 0;
  6.         if(arr != null) {
  7.             for (int i = 0; i < arr.length; i++) {
  8.                 if (max < arr[i]) {
  9.                     max = arr[i];
  10.                 }
  11.             }
  12.         }
  13.         return max;
  14.     }
  15.  
  16.     public static int cube(int n){
  17.         if (n > 0) {
  18.             return n * n * n;
  19.         }
  20.         else{
  21.             return 0;
  22.         }
  23.     }
  24.  
  25. }
  26.  
  27. //////////////////////////////////////////
  28.  
  29. package test;
  30.  
  31. import static org.junit.jupiter.api.Assertions.*;
  32.  
  33. import org.junit.jupiter.api.BeforeAll;
  34. import org.junit.jupiter.api.DisplayName;
  35. import org.junit.jupiter.api.Test;
  36.  
  37. import utils.Calculation;
  38.  
  39. class CalculationTests {
  40.     private static int[] value;
  41.  
  42.     @BeforeAll
  43.     static void setUpBeforeClass() throws Exception {
  44.         value = new int[]{2, -4, -8, 5, 8, 2, 1, 0};
  45.     }
  46.  
  47.     @Test
  48.     @DisplayName("Test find max providing diff nums")
  49.     void testMax1() {
  50.         assertEquals(8, Calculation.findMax(value));
  51.     }
  52.  
  53.     @Test
  54.     @DisplayName("Test find max providing null")
  55.     void testMax2() {
  56.         assertEquals(0, Calculation.findMax(null));
  57.     }
  58.  
  59.     @Test
  60.     @DisplayName("Test cube volume providing 0")
  61.     void testCube1(){
  62.         assertEquals(0, Calculation.cube(0));
  63.     }
  64.  
  65.     @Test
  66.     @DisplayName("Test cube volume providing positive num")
  67.     void testCube2(){
  68.         assertEquals(27, Calculation.cube(3));
  69.     }
  70.  
  71.     @Test
  72.     @DisplayName("Test cube volume providing negative num")
  73.     void testCube3(){
  74.         assertEquals(0, Calculation.cube(-4));
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment