package com.primeFactorizer;

import junit.framework.TestCase;

/**
 * This class tests the bit manipulation functions that we have.
 * @author fpereira
 *
 */
public class TestBitManipulator extends TestCase {
  /**
   * Class constructor.
   * @param name the name of the test.
   */
  public TestBitManipulator(final String name) {
    super(name);
  }

  /**
   * Test if we find zero bits set in the long zero.
   * @throws Exception in case something goes wrong.
   */
  public final void testZero() throws Exception {
    int numSet = BitManipulator.countNumSet(0L);
    assertEquals(numSet, 0);
  }

  /**
   * Test if we find one bit set in the long one.
   * @throws Exception in case something goes wrong.
   */
  public final void testOne() throws Exception {
    int numSet = BitManipulator.countNumSet(1L);
    assertEquals(numSet, 1);
  }

  /**
   * Test if we find one bit set in the long two.
   * @throws Exception in case something goes wrong.
   */
  public final void testTwo() throws Exception {
    int numSet = BitManipulator.countNumSet(2L);
    assertEquals(numSet, 1);
  }

  /**
   * Test if we find one bit set in the long three.
   * @throws Exception in case something goes wrong.
   */
  public final void testThree() throws Exception {
    int numSet = BitManipulator.countNumSet(3L);
    assertEquals(numSet, 2);
  }

  /**
   * Test if we find one bit set in the long four.
   * @throws Exception in case something goes wrong.
   */
  public final void testFour() throws Exception {
    int numSet = BitManipulator.countNumSet(4L);
    assertEquals(numSet, 1);
  }

  /**
   * Test if we find correct answers for the three longs under 8 not tested
   * yet.
   * @throws Exception in case something goes wrong.
   */
  public final void testUnderEight() throws Exception {
    assertEquals(BitManipulator.countNumSet(5L), 2);
    assertEquals(BitManipulator.countNumSet(6L), 2);
    assertEquals(BitManipulator.countNumSet(7L), 3);
  }

  /**
   * Test if we find one bit set in the first eight negative numbers.
   * @throws Exception in case something goes wrong.
   */
  public final void testNegative() throws Exception {
    assertEquals(BitManipulator.countNumSet(-1L), 64);
    assertEquals(BitManipulator.countNumSet(-2L), 63);
    assertEquals(BitManipulator.countNumSet(-3L), 63);
    assertEquals(BitManipulator.countNumSet(-4L), 62);
  }

}
