The method checks whether the array element is not an alphabetic character.

public static char[] checkLetterInWord(char[] checkWord, int firsLetter, int lastLetter){ while(firsLetter<lastLetter) { if(!Character.isLetter(checkWord[firsLetter])){ firsLetter++; } else if(!Character.isLetter(checkWord[lastLetter])){ lastLetter--; } else { exchangeCharInWord(checkWord, firsLetter, lastLetter); firsLetter++; lastLetter--; } } return checkWord; } 

How to test individual pieces of code, and is it possible at all.

 if(!Character.isLetter(checkWord[firsLetter])){ firsLetter++; } 

Similarly

 else if(!Character.isLetter(checkWord[lastLetter])){ lastLetter--; } 

and

 else { exchangeCharInWord(checkWord, firsLetter, lastLetter); firsLetter++; lastLetter--; } 
  • You had a question about git yesterday. Solved the problem? - Nick Volynkin

2 answers 2

  1. Re-read the previous answer about what tests should be.
  2. After re-reading, think carefully and make a list of test cases for the checkLetterInWord method.
  3. Making a correct list of test cases, you will understand that all branches of your method are already covered with tests.

It works that way. The programmer is usually not given the idea of ​​"testing this piece of code here," especially if the code is written in the TDD style. The whole method is being tested, but at different angles, so to speak.

Push off test cases, write tests, then perform and look at the method coverage. And if you suddenly see that some branch is not covered, then you have missed some test case.

    Not. As you imagine, you can refer to the part of the method from another method, based on the java specification The right way is to write right away so that it is convenient to test. Write a separate test for each condition, and then see how you can fill up your code: an infinite loop, zero references, etc. And if it makes sense within your application, write tests for them too.