Timkor

testUpgradeJava

Mar 15th, 2021 (edited)
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. package Learningjava.Examplesfortest;
  2.  
  3. import java.util.Arrays;
  4.  
  5. class Test3 {
  6.     public static int Nameofmethod(int first, int second, int third) {
  7.         if ((first == second) && second != third & first != third) {
  8.             return third;
  9.         }
  10.         else if ((first == third) && first != second & third != second) {
  11.             return second;
  12.         }
  13.         else if ((second == third) && second != first & third !=first) {
  14.             return first;
  15.         }
  16.         else {
  17.             return -1;
  18.         }
  19.     }
  20.  
  21.     public static void main(String[] args) {
  22.         String OK_COLOR_GREEN = "\033[0;32m";
  23.  
  24.         int[][] testArrays = {{1, 1, 1, -1}, {1, 1, 2, 2}, {1, 2, 1, 2}, {2, 1, 1, 2}, {1, 2, 2, 2}, {2, 1, 2, 2}, {2, 2, 1, 2},
  25.                 {1, 2, 3, 3}, {1, 3, 2, 3}, {3, 1, 2, 3}, {2, 1, 3, 3}, {3, 2, 1, 3}, {2, 3, 1, 3},};
  26.         /*int[] correctAnswers = {-1, 2, 2, 2, 2, 2, 2,
  27.                 3, 3, 3, 3, 3, 3};*/ // не портібен, бо відповідь йде четвертим елементом (якщо за індексом то третім) у тестовому масиві.)
  28.         // int counter = 0; - не портібен, якщо не хочемо рахувати тести
  29.         int result;
  30.         for (int[] currentTestParams : testArrays) {
  31.             //
  32.             if ((result = Nameofmethod(currentTestParams[0], currentTestParams[1], currentTestParams[2])) == currentTestParams[3]) {
  33.                 System.out.println(OK_COLOR_GREEN + " ok  returned " + result + " " + Arrays.toString(Arrays.copyOf(currentTestParams,3)) + " expected " + currentTestParams[3]);
  34.             } else {
  35.                 System.err.println(" fail returned " + result + " " + Arrays.toString(Arrays.copyOf(currentTestParams,3)) + " expected " + currentTestParams[3]);
  36.             }
  37.         }
  38.     }
  39. }
  40.  
Add Comment
Please, Sign In to add comment