/**
 *
 */
package org.chocosolver.solver.variables.impl;

import org.chocosolver.solver.Model;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.variables.SetVar;
import org.testng.Assert;
import org.testng.annotations.Test;

/**
 * @author Guillaume Le Louët [guillaume.lelouet@gmail.com] 2016
 */
public class SetVarImplTest {

	@Test
	public void testSetVarInstantiated() {
		Model m = new Model();
		Assert.assertTrue(m.setVar("var", new int[] { -1, -2, 3, 18 }).getCard().isInstantiatedTo(4));
		Assert.assertTrue(m.setVar("var", new int[] { -1, -1, -1, 0 }).getCard().isInstantiatedTo(2));
		Assert.assertTrue(m.setVar("var").getCard().isInstantiatedTo(0));
	}

	@Test
	public void testPropagate() {
		Model m = new Model();
		SetVar s = m.setVar("var", new int[] {}, new int[] { 0, 1, 2, 3 });
		IntVar a = m.intVar("a", 0), b = m.intVar("b", 0, 3), c = m.intVar("c", 0, 3), d = m.intVar("d", 0, 3);
		m.member(a, s).reifyWith(m.member(b, s).getOpposite().reify());// a in s XOR b in s
		m.member(c, s).reifyWith(m.member(d, s).getOpposite().reify());// c in s XOR d in s
		m.allDifferent(a, b, c, d).post();
		// 4 different variables, among them two belong to s so c = 2. Which of a or b belong to s makes o difference
		s.setCard(c);
		Assert.assertTrue(m.solve());
		Assert.assertTrue(c.isInstantiatedTo(2), "" + c);
	}

}

@@ -1,15 +1,1748 @@
 /**%0A *
+ Copyright (c) 2015, Ecole des Mines de Nantes%0A * All rights reserved.%0A *%0A * Redistribution and use in source and binary forms, with or without%0A * modification, are permitted provided that the following conditions are met:%0A * 1. Redistributions of source code must retain the above copyright%0A *    notice, this list of conditions and the following disclaimer.%0A * 2. Redistributions in binary form must reproduce the above copyright%0A *    notice, this list of conditions and the following disclaimer in the%0A *    documentation and/or other materials provided with the distribution.%0A * 3. All advertising materials mentioning features or use of this software%0A *    must display the following acknowledgement:%0A *    This product includes software developed by the %3Corganization%3E.%0A * 4. Neither the name of the %3Corganization%3E nor the%0A *    names of its contributors may be used to endorse or promote products%0A *    derived from this software without specific prior written permission.%0A *%0A * THIS SOFTWARE IS PROVIDED BY %3CCOPYRIGHT HOLDER%3E ''AS IS'' AND ANY%0A * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED%0A * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE%0A * DISCLAIMED. IN NO EVENT SHALL %3CCOPYRIGHT HOLDER%3E BE LIABLE FOR ANY%0A * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES%0A * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;%0A * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND%0A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT%0A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS%0A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 %0A
-
  */%0Apack
@@ -2083,32 +2083,60 @@
 plTest %7B%0A%0A%09@Test
+(groups=%221s%22, timeOut=60000)
 %0A%09public void te
@@ -2457,16 +2457,44 @@
 %0A%0A%09@Test
+(groups=%221s%22, timeOut=60000)
 %0A%09public
@@ -3055,16 +3055,16 @@
 ard(c);%0A
-
 %09%09Assert
@@ -3077,16 +3077,28 @@
 tTrue(m.
+getSolver().
 solve())

fix test