0

How do you fix this??

For the following line in my program JaCoCo shows: "1 of 2 branches missed"

if(ia.length() < i+1){

Also for the following line i get: "1 of 4 branches missed"

if(ia.length() <= i+1 && ib.length() <= i+1){

the whole code:

public static int convertBits(int a, int b) {
      String ia = Integer.toBinaryString(a);
      String ib = Integer.toBinaryString(b);
      int s = 0;
      for(int i = 0;;i++){
        char a1 = '0';
        char a2 = '0';

        if(ia.length() < i+1){
          a1 = '0';
        }else{
          a1 = ia.charAt(ia.length() - i - 1);
          }
        if(ib.length() < i+1){
          a2 = '0';
        }else{
          a2 = ib.charAt(ib.length() - i - 1);
          }
        if(a1 != a2){
          s++;
        }
        if(ia.length() <= i+1 && ib.length() <= i+1){
          break;
        }
      }
4
  • And what is the question? Commented Feb 25, 2017 at 14:45
  • @Godin how do you fix it Commented Feb 26, 2017 at 1:05
  • Write missing tests? Commented Feb 26, 2017 at 1:12
  • @ArtsArts and where is the test code against the above code? Commented Feb 26, 2017 at 7:17

1 Answer 1

2

JaCoCo is a code coverage tool that generates coverage report of your code after its execution. Could be after manual execution, but typically after execution of tests, thus doing assistance in their creation.

Condition if (ia.length() < i + 1) { has two branches:

  1. ia.length() < i + 1 == false
  2. ia.length() < i + 1 == true

So

1 out of 2 branches

means that one of those branches was executed, while another was not.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.