Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Learningjava.Examplesfortest;
- import java.util.Arrays;
- class Test3 {
- public static int Nameofmethod(int first, int second, int third) {
- if ((first == second) && second != third & first != third) {
- return third;
- }
- else if ((first == third) && first != second & third != second) {
- return second;
- }
- else if ((second == third) && second != first & third !=first) {
- return first;
- }
- else {
- return -1;
- }
- }
- public static void main(String[] args) {
- String OK_COLOR_GREEN = "\033[0;32m";
- 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},
- {1, 2, 3, 3}, {1, 3, 2, 3}, {3, 1, 2, 3}, {2, 1, 3, 3}, {3, 2, 1, 3}, {2, 3, 1, 3},};
- /*int[] correctAnswers = {-1, 2, 2, 2, 2, 2, 2,
- 3, 3, 3, 3, 3, 3};*/ // не портібен, бо відповідь йде четвертим елементом (якщо за індексом то третім) у тестовому масиві.)
- // int counter = 0; - не портібен, якщо не хочемо рахувати тести
- int result;
- for (int[] currentTestParams : testArrays) {
- //
- if ((result = Nameofmethod(currentTestParams[0], currentTestParams[1], currentTestParams[2])) == currentTestParams[3]) {
- System.out.println(OK_COLOR_GREEN + " ok returned " + result + " " + Arrays.toString(Arrays.copyOf(currentTestParams,3)) + " expected " + currentTestParams[3]);
- } else {
- System.err.println(" fail returned " + result + " " + Arrays.toString(Arrays.copyOf(currentTestParams,3)) + " expected " + currentTestParams[3]);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment