BitsCounter { public int countBitsToOneBasedOnString(int n) { int result = 0; String binaryNumber = Integer.toBinaryString(n); for (char c : binaryNumber.toCharArray()) { result += c == '1' ? 1 : 0; } return result; }  int countBitsToOneBasedOnString(int n); int countBitsToOneBasedOnBinaryOperators(int n);  }
@Test public void numberOfBitsInOneIsOne() { assertEquals(1, bitsCounter.countBitsToOneBasedOnString(1)); }
@Test public void numberOfBitsInTwoIsOne() { assertEquals(1, bitsCounter.countBitsToOneBasedOnString(2)); }
@Test public void numberOfBitsInThreeIsTwo() { assertEquals(2, bitsCounter.countBitsToOneBasedOnString(3)); }