package solver; import static org.junit.Assert.*; import org.junit.Test; /** * */ /** * @author mohsen * */ public class TestRelation { /** * Test method for {@link Relation#rename(int, int, int)}. */ @Test public void testRename() { for(int i=0;i<256;i++){ for(int j=0;j<3;j++){ System.out.println("i"+i); int t = Relation.rename(i, j); System.out.println("t"+t); int s = Relation.rename(t, j); System.out.println("s"+s); assertTrue(s==i); } } } /** * Test method for {@link Relation#reduce(int, int, int)}. */ @Test public void testReduce() { System.out.println("Rel:\tX2=0\tX2=1\tX1=0\tX1=1\tX0=0\tX0=1"); for (int i = 0; i < 256; i++) { System.out.print(""+i+":"); for (int k=2;k>=0;k--){ for(int j=0; j<=1;j++){ int newR = Relation.reduce(i, k, j); System.out.print("\t"+newR); assertTrue((newR<=255)&&(newR>=0)); } } System.out.println(""); } } /** * Test method for {@link Relation#isVariableNotInRelation(int, int)}. */ @Test public void testIsVariableNotInRelation() { for(int i=0;i<256;i++){ for(int j=0;j<3;j++){ assertTrue(isVariableNotInRelation(i, j) == Relation.isVariableNotInRelation(i, j)); } } } //Redundant Testing Box boolean isVariableNotInRelation(int relationNumber, int variableNumber){ int r0 = Relation.reduce(relationNumber,variableNumber,0); int r1 = Relation.reduce(relationNumber,variableNumber,1); return (r0==r1); } /** * Test method for {@link Relation#rank(int)}. */ @Test public void testRank() { int[] ranks = new int [4]; ranks[1]=ranks[2]=ranks[3]=0; for(int i=0;i<256;i++){ ranks[Relation.rank(i)]++; } for(int i=1;i<=3;i++){ System.out.println("There are "+ranks[i]+" Relations of Rank "+i); } //TODO Add some assertion } /** * Test method for {@link Relation#q(int, int)} and {@link Relation#ones(int)}. */ @Test public void testQ_And_Ones() { System.out.println("ones in R: q0 q1 q2 q3"); for(int i=0;i<256;i++){ int q0 = Relation.q(i, 0); int q1 = Relation.q(i, 1); int q2 = Relation.q(i, 2); int q3 = Relation.q(i, 3); int t = q0+q1+q2+q3; int o = Relation.ones(i); System.out.println("ones in "+i+"= "+q0+" "+q1+" "+q2+" "+q3); assertTrue(t==o); } } /** * Test method for {@link Relation#isForced(int, int)}. */ @Test public void testIsForced() { int forced0,forced1; forced0=forced1=0; for(int i=0;i<256;i++){ System.out.println("Relation # "+i+" of Rank "+Relation.rank(i)+" with "+Relation.ones(i)+" Ones"); for(int j=0;j<3;j++){ int forced = Relation.isForced(i, j); if(((forced==0)||(forced==1))){ System.out.println("\t Variable Number "+j+" is forced to "+forced); if(forced==0) forced0++; else forced1++; } } } System.out.println("There are "+forced0+" Variables forced to 0"); System.out.println("There are "+forced1+" Variables forced to 1"); // TODO Add some assertion } }