/****************************************************************************
* Author: Isai Damier
* Title: Intersection
* Project: geekviewpoint
* Package: algorithms
*
* Statement:
* Given two sets of bits, x and y, find their intersection.
*
* Sample Input: 0101100 and 0110101
* Sample Output: 0100100
*
* Technical Details: The intersection of two sets is the subset comprising
* only the elements that appear in both sets. For example if
* s1 = [a,b,f,h,k] and s2 = [b,c,d,f,h,i] then the intersection of s1 and
* s2 is [b,f,h]. For two sets of bits the intersection is simply the
* bitwise AND of the two sets. For example if x = 0110101 and y=0101100
* then the intersection of x and y is x U y = 0100100.
*
****************************************************************************/
public int intersection(int x, int y) {//LAST ONE ADDED TO DATASTORE
return x & y;
}
import org.junit.Test;
import static org.junit.Assert.*;
public class BitwiseTest {
/**
* Test of intersection method, of class Bitwise.
*/
@Test
public void testIntersection() {
System.out.println(""intersection"");
Bitwise bits = new Bitwise();
int x = Integer.parseInt(""0101100"", 2);
int y = Integer.parseInt(""0110101"", 2);
int u = Integer.parseInt(""0100100"", 2);
assertEquals(u, bits.intersection(x, y));
x = Integer.parseInt(""0101100"", 2);
y = Integer.parseInt(""0110101"", 2);
u = Integer.parseInt(""0100100"", 2);
assertEquals(u, bits.intersection(y, x));
}
}