BitsToTransform { public int calculate(int numA, int numB) { int differentBits = 0; for (int XOR = numA ^ numB; XOR != 0; XOR = XOR & (XOR - 1)) { differentBits++; } return differentBits; }  int calculate(int numA, int numB);  }
@Test public void shouldReturnZeroIfBothNumbersAreEquals() { int numA = 7; int numB = 7; int numberOfDifferentBits = bitsToTransform.calculate(numA, numB); assertEquals(0, numberOfDifferentBits); }
@Test public void shouldClaculateHappyCase() { int numA = 5; int numB = 1; int numberOfDifferentBits = bitsToTransform.calculate(numA, numB); assertEquals(1, numberOfDifferentBits); }
@Test public void shouldReturnTheNumberOfDifferentBitsWhenNumAIsLower() { int numA = 78; int numB = 99; int numberOfDifferentBits = bitsToTransform.calculate(numA, numB); assertEquals(4, numberOfDifferentBits); }
@Test public void shouldReturnTheNumberOfDifferentBitsWhenNumAIsGreater() { int numA = 99; int numB = 78; int numberOfDifferentBits = bitsToTransform.calculate(numA, numB); assertEquals(4, numberOfDifferentBits); }