use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class GrinderUtilTest method testIsCategoricalTypeSubtypeOf.
@Test
public void testIsCategoricalTypeSubtypeOf() {
Categorical categoricalType = new Categorical("TestCategorical1", 10, parse("a"), parse("b"), parse("c"));
Assert.assertFalse(isTypeSubtypeOf(categoricalType, BOOLEAN_TYPE));
Assert.assertFalse(isTypeSubtypeOf(categoricalType, INTEGER_TYPE));
Assert.assertFalse(isTypeSubtypeOf(categoricalType, REAL_TYPE));
Assert.assertFalse(isTypeSubtypeOf(categoricalType, new IntegerInterval("Integer")));
Assert.assertFalse(isTypeSubtypeOf(categoricalType, new IntegerInterval("0..4")));
Assert.assertFalse(isTypeSubtypeOf(categoricalType, new RealInterval("Real")));
Assert.assertFalse(isTypeSubtypeOf(categoricalType, new RealInterval("[-0.5;4.5]")));
Assert.assertFalse(isTypeSubtypeOf(categoricalType, new FunctionType(categoricalType)));
Assert.assertFalse(isTypeSubtypeOf(categoricalType, new FunctionType(categoricalType, categoricalType)));
// NOTE: Categorical types equality is based on name.
Assert.assertTrue(isTypeSubtypeOf(categoricalType, new Categorical("TestCategorical1", 10, parse("a"), parse("b"), parse("c"))));
Assert.assertTrue(isTypeSubtypeOf(categoricalType, new Categorical("TestCategorical1", 5, parse("x"), parse("y"), parse("z"))));
Assert.assertFalse(isTypeSubtypeOf(categoricalType, new Categorical("TestCategorical2", 10, parse("a"), parse("b"), parse("c"))));
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class SampleCommonInterpreterTest method testCategoricalEg1.
@Test
public void testCategoricalEg1() {
updateContextWithIndexAndType("N", new Categorical("Person", 100));
String intensionalSet = "{{(on I in Person) if I != person1 then 20 else 30 : I != person2 }}";
String[][] functionNamesAndExactValues = new String[][] { { "sum", "1990" }, { "max", "30" }, { "product", "950737950171172051122527404032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" } };
runSampleCompareToExact(100, true, intensionalSet, functionNamesAndExactValues);
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class LambdaBetaReductionSimplifierTest method testSimpleReduction.
@Test
public void testSimpleReduction() {
Type peopleType = new Categorical("People", 4, arrayList(makeSymbol("ann"), makeSymbol("bob")));
Context context = new TrueContext();
context = context.add(peopleType);
Assert.assertEquals(parse("if X = ann then 0 else if X = bob then 0 else 0"), simplifier.apply(parse("(lambda : if X = ann then 0 else if X = bob then 0 else 0)()"), context));
Assert.assertEquals(parse("if ann = ann then 0 else if ann = bob then 0 else 0"), simplifier.apply(parse("(lambda X in People : if X = ann then 0 else if X = bob then 0 else 0)(ann)"), context));
Assert.assertEquals(parse("if ann = ann then 0 else if bob = bob then 0 else 0"), simplifier.apply(parse("(lambda X in People, Y in People : if X = ann then 0 else if Y = bob then 0 else 0)(ann, bob)"), context));
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class SampleCommonInterpreterTest method testSumOverCategoricalDomain.
@Test
public void testSumOverCategoricalDomain() {
updateContextWithIndexAndType("N", new Categorical("People", 5, parse("p1"), parse("p2"), parse("p3"), parse("p4"), parse("p5")));
// NOTE: random picks p1 and p2
runTest(2, true, "sum({{(on N in People) 2}})", "10");
// NOTE: keep this order of calls as the fixed Random will pick p3 and p4
runTest(2, true, "sum({{(on N in People) if N = p3 then 4 else 2}})", "15");
// NOTE: picks p5 and p5
runTest(2, true, "sum({{(on N in People) 2 : N != p2}})", "8");
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class CompoundTheoryWithDifferenceArithmeticTest method makeTheoryTestingSupport.
@Override
protected TheoryTestingSupport makeTheoryTestingSupport() {
TheoryTestingSupport result = TheoryTestingSupport.make(makeRandom(), new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, true), new PropositionalTheory()));
// using different testing variables and types to test distribution of testing information
// to sub constraint theories.
Categorical booleanType = BOOLEAN_TYPE;
Categorical dogsType = new Categorical("Dogs", 4, arrayList(parse("fido"), parse("rex")));
IntegerInterval oneTwoThree = new IntegerInterval(1, 3);
Map<String, Type> variablesAndTypes = map("F", booleanType, "G", booleanType, "R", dogsType, "S", dogsType, "T", oneTwoThree, "U", oneTwoThree);
result.setVariableNamesAndTypesForTesting(variablesAndTypes);
return result;
}
Aggregations