/**
 * 
 */
package edu.neu.ccs.evergreen.ir;

import static org.junit.Assert.*;
import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * @author mohsen
 *
 */
public class RelationCoreChecksTest{

    int maxRank = RelationCore.MaxRank; // for loops over all possible relation ranks to use
    
    /**
     * Test method for {@link edu.neu.ccs.evergreen.ir.RelationCore#checkRelationNumber(int, int)}.
     *  In range check
     */
    @Test
    public void testCheckRelationNumberInrange() {
        for(int rank=1;rank<=maxRank;rank++){
            for(int i=0;i<RelationCore.getMask(rank);i++){
                RelationCore.checkRelationNumber(i, rank);
            }
        }
    }
    /**
     * Test method for {@link edu.neu.ccs.evergreen.ir.RelationCore#checkRelationNumber(int, int)}.
     * Out of range check
     */
    @Test //(expected=IllegalArgumentException.class)
    public void testCheckRelationNumberOutOfRange() {
        int testCount = 0;//Number of Tests, increment manually before every tess
        int ExceptionCount = 0; //hold number of IllegalArgumentException exceptions
            for(int rank=1;rank>=maxRank;rank++){
                try {
                    testCount++;
                    RelationCore.checkRelationNumber(-1, rank);
                } catch (IllegalArgumentException e) {
                    ExceptionCount++;
                }
                try {
                    testCount++;
                    RelationCore.checkRelationNumber(RelationCore.getMask(rank)+1, rank);
                } catch (IllegalArgumentException e) {
                    ExceptionCount++;
                }
            }
        // make sure that every test thrown an Illegal Argument Exception
        assertTrue(ExceptionCount==testCount);
    }

    /**
     * Test method for {@link edu.neu.ccs.evergreen.ir.RelationCore#checkVariablePosition(int, int)}.
     * In range
     */
    @Test
    public void testCheckVariablePositionInRange() {
        for(int rank=1;rank<=maxRank;rank++){
            for(int i=0;i<rank;i++){
                RelationCore.checkVariablePosition(i, rank);
            }
        }
    }
    /**
     * Test method for {@link edu.neu.ccs.evergreen.ir.RelationCore#checkVariablePosition(int, int)}.
     * out of range
     */
    @Test
    public void testCheckVariablePositionOutOfRange() {
        int testCount = 0;//Number of Tests, increment manually before every tess
        int ExceptionCount = 0; //hold number of IllegalArgumentException exceptions
            for(int rank=1;rank>=maxRank;rank++){
                try {
                    testCount++;
                    RelationCore.checkVariablePosition(-1, rank);
                } catch (IllegalArgumentException e) {
                    ExceptionCount++;
                }
                try {
                    testCount++;
                    RelationCore.checkVariablePosition(rank, rank);
                } catch (IllegalArgumentException e) {
                    ExceptionCount++;
                }
            }
        // make sure that every test thrown an Illegal Argument Exception
        assertTrue(ExceptionCount==testCount);
    }

}