Ptidej-v5.2-master/Ptidej Solver Tests/src/ptidej/solver/test/java/simple/StrictInheritance.java
/*******************************************************************************
 * Copyright (c) 2001-2014 Yann-Gal Guhneuc and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Yann-Gal Guhneuc and others, see in file; API and its implementation
 ******************************************************************************/
package ptidej.solver.test.java.simple;

import junit.framework.Assert;
import ptidej.solver.Occurrence;
import ptidej.solver.test.data.problem.StrictInheritanceTest;
import ptidej.solver.test.data.source.InheritanceTest;
import ptidej.solver.test.java.Primitive;

public final class StrictInheritance extends Primitive {
	private static Occurrence[] BuiltSolutions;

	public StrictInheritance(final String name) {
		super(name);
	}
	protected void setUp() {
		if (StrictInheritance.BuiltSolutions == null) {
			StrictInheritance.BuiltSolutions =
				Primitive.automaticSolve(
					StrictInheritanceTest.class,
					InheritanceTest.class);
		}
	}
	public void testNumberOfSolutions() {
		Assert.assertEquals(
			"Number of solutions",
			6,
			StrictInheritance.BuiltSolutions.length);
	}
	public void testSolution1() {
		Assert.assertEquals(
			"A -|>- java.lang.Object",
			"java.lang.Object",
			StrictInheritance.BuiltSolutions[0].getComponent(
				StrictInheritanceTest.SUPER_ENTITY).getDisplayValue());
		Assert.assertEquals(
			"A -|>- java.lang.Object",
			"A",
			StrictInheritance.BuiltSolutions[0].getComponent(
				StrictInheritanceTest.SUB_ENTITY).getDisplayValue());
	}
	public void testSolution2() {
		Assert.assertEquals(
			"B -|>- A",
			"A",
			StrictInheritance.BuiltSolutions[1].getComponent(
				StrictInheritanceTest.SUPER_ENTITY).getDisplayValue());
		Assert.assertEquals(
			"B -|>- A",
			"B",
			StrictInheritance.BuiltSolutions[1].getComponent(
				StrictInheritanceTest.SUB_ENTITY).getDisplayValue());
	}
	public void testSolution3() {
		Assert.assertEquals(
			"C -|>- B",
			"B",
			StrictInheritance.BuiltSolutions[2].getComponent(
				StrictInheritanceTest.SUPER_ENTITY).getDisplayValue());
		Assert.assertEquals(
			"C -|>- B",
			"C",
			StrictInheritance.BuiltSolutions[2].getComponent(
				StrictInheritanceTest.SUB_ENTITY).getDisplayValue());
	}
	public void testSolution4() {
		Assert.assertEquals(
			"D -|>- java.lang.Object",
			"java.lang.Object",
			StrictInheritance.BuiltSolutions[3].getComponent(
				StrictInheritanceTest.SUPER_ENTITY).getDisplayValue());
		Assert.assertEquals(
			"D -|>- java.lang.Object",
			"D",
			StrictInheritance.BuiltSolutions[3].getComponent(
				StrictInheritanceTest.SUB_ENTITY).getDisplayValue());
	}
	public void testSolution5() {
		Assert.assertEquals(
			"E -|>- D",
			"D",
			StrictInheritance.BuiltSolutions[4].getComponent(
				StrictInheritanceTest.SUPER_ENTITY).getDisplayValue());
		Assert.assertEquals(
			"E -|>- D",
			"E",
			StrictInheritance.BuiltSolutions[4].getComponent(
				StrictInheritanceTest.SUB_ENTITY).getDisplayValue());
	}
	public void testSolution6() {
		Assert.assertEquals(
			"F -|>- java.lang.Object",
			"java.lang.Object",
			StrictInheritance.BuiltSolutions[5].getComponent(
				StrictInheritanceTest.SUPER_ENTITY).getDisplayValue());
		Assert.assertEquals(
			"F -|>- java.lang.Object",
			"F",
			StrictInheritance.BuiltSolutions[5].getComponent(
				StrictInheritanceTest.SUB_ENTITY).getDisplayValue());
	}
	public void testSolutionPercentage() {
		for (int i = 0; i < StrictInheritance.BuiltSolutions.length; i++) {
			Assert.assertEquals(
				"Solution with all constraints",
				100,
				StrictInheritance.BuiltSolutions[i].getConfidence());
		}
	}
}
