Summarizing the result of several logical tests in a single result

0

Good afternoon,

I have some strings that come from testing. Example:

            String teste2 = (nB < 0.0 && m1 <= j ? "OK" : "Não passa!");
            String teste3 = (nB < 0.0 && m2 <= j ? "OK" : "Não passa!");
            String teste4 = (nB > 0.0 && m2 <= 35.0 ? "OK" : "Não passa!");
            String teste5 = (nB > 0.0 && m2 <= 35.0 ? "OK" : "Não passa!");

I would like to summarize everything in a single string. In this case, if any of the tests showed the message "Do not go!" my summary string would return "Do not pass!" otherwise it would return "OK". The problem is that with the following code it always returns "Do not go!".

String resultado = (teste2.equals("Não passa!") || teste3.equals("Não passa!") || teste4.equals("Não passa!") || teste5.equals("Não passa!") || teste6.equals("Não passa!") || teste7.equals("Não passa!") || teste8.equals("Não passa!") || teste9.equals("Não passa!") || teste10.equals("Não passa!") ? "Não passa!" : "OK");

What am I doing wrong? Thankful.

    
asked by anonymous 01.10.2017 / 19:17

1 answer

2

You can do this:

        boolean teste2 = nB < 0.0 && m1 <= j;
        boolean teste3 = nB < 0.0 && m2 <= j;
        boolean teste4 = nB > 0.0 && m1 <= 35.0;
        boolean teste5 = nB > 0.0 && m2 <= 35.0;

        // ...

        boolean resultado = teste2 && teste3 && teste4 && teste5
                && teste6 && teste7 && teste8 && teste9 && teste10;

Avoid using strings oriented programming . This is a bad programming practice.

In addition, note that the nb < 0.0 condition of teste2 and teste3 is the nb > 0.0 of teste4 and teste5 . There is no way these two conditions can be true simultaneously because% w_ of% can not be greater and less than zero at the same time. Therefore, there is no way that nb is true.

So some of these tests should be checking for incorrect conditions or there is some bore in the logic of what you are testing.

    
01.10.2017 / 19:33