use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class ExpressionStepSolverToLiteralSplitterStepSolverAdapterTest method testCompoundTheoryWithDifferenceArithmeticWithRandomDisjunctiveFormulas.
@Test
public void testCompoundTheoryWithDifferenceArithmeticWithRandomDisjunctiveFormulas() {
TheoryTestingSupport theoryTestingSupport = 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);
theoryTestingSupport.setVariableNamesAndTypesForTesting(variablesAndTypes);
runRandomDisjunctiveFormulasTest(theoryTestingSupport);
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class TypeTest method testIterator.
@Test
public void testIterator() {
FunctionType fType;
// i.e. 2
fType = new FunctionType(new IntegerInterval(1, 2));
checkTypeIteration(fType, "lambda : 1", "lambda : 2");
// i.e. 2^2
fType = new FunctionType(new IntegerInterval(1, 2), new Categorical("Car", 2));
checkTypeIteration(fType, "lambda A1 in Car : if A1 = car1 then 1 else 1", "lambda A1 in Car : if A1 = car1 then 2 else 1", "lambda A1 in Car : if A1 = car1 then 1 else 2", "lambda A1 in Car : if A1 = car1 then 2 else 2");
// i.e. 2^(2*2)
fType = new FunctionType(new IntegerInterval(1, 2), new Categorical("Car", 2), new Categorical("Bike", 2));
checkTypeIteration(fType, "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 1 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 1 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 1 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 1 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 2 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 2 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 2 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 2 else 1", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 1 else 2", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 1 else 2", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 1 else 2", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 1 else 2", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 2 else 2", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 1 else if (A1 = car1) and (A2 = bike2) then 2 else 2", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 1 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 2 else 2", "lambda A1 in Car, A2 in Bike : if (A1 = car1) and (A2 = bike1) then 2 else if (A1 = car2) and (A2 = bike1) then 2 else if (A1 = car1) and (A2 = bike2) then 2 else 2");
// i.e. 0
TupleType tType = new TupleType();
checkTypeIteration(tType, "()");
// i.e. 3
tType = new TupleType(new IntegerInterval(1, 3));
checkTypeIteration(tType, "tuple(1)", "tuple(2)", "tuple(3)");
// i.e. 2x3
tType = new TupleType(GrinderUtil.BOOLEAN_TYPE, new IntegerInterval(1, 3));
checkTypeIteration(tType, "(true, 1)", "(false, 1)", "(true, 2)", "(false, 2)", "(true, 3)", "(false, 3)");
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class AssignmentsIteratorTest method test2.
@Test
public void test2() {
Registry registry = new DefaultRegistry();
Type myType = new Categorical("People", 2, arrayList(makeSymbol("oscar"), makeSymbol("mary")));
Symbol x = makeSymbol("X");
Symbol y = makeSymbol("Y");
String expected = "{X=oscar, Y=oscar}\n" + "{X=mary, Y=oscar}\n" + "{X=oscar, Y=mary}\n" + "{X=mary, Y=mary}";
Symbol myTypeExpression = makeSymbol(myType.getName());
registry = registry.add(myType);
registry = registry.registerAdditionalSymbolsAndTypes(map(x, myTypeExpression, y, myTypeExpression));
AssignmentsIterator assignmentsIterator = new AssignmentsIterator(list(x, y), registry);
String actual = join("\n", assignmentsIterator);
// System.out.println(actual);
assertEquals(expected, actual);
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class AssignmentsIteratorTest method test3.
@Test
public void test3() {
Registry registry = new DefaultRegistry();
Type peopleType = new Categorical("People", 4, arrayList(makeSymbol("oscar"), makeSymbol("mary")));
Type petsType = new Categorical("Pets", 3, arrayList(makeSymbol("fido"), makeSymbol("purrs")));
Symbol x = makeSymbol("X");
Symbol y = makeSymbol("Y");
String expected = "{X=oscar, Y=fido}\n" + "{X=mary, Y=fido}\n" + "{X=people3, Y=fido}\n" + "{X=people4, Y=fido}\n" + "{X=oscar, Y=purrs}\n" + "{X=mary, Y=purrs}\n" + "{X=people3, Y=purrs}\n" + "{X=people4, Y=purrs}\n" + "{X=oscar, Y=pets3}\n" + "{X=mary, Y=pets3}\n" + "{X=people3, Y=pets3}\n" + "{X=people4, Y=pets3}";
Symbol myPeopleTypeExpression = makeSymbol(peopleType.getName());
Symbol myPetsTypeExpression = makeSymbol(petsType.getName());
registry = registry.add(peopleType);
registry = registry.add(petsType);
registry = registry.registerAdditionalSymbolsAndTypes(map(x, myPeopleTypeExpression, y, myPetsTypeExpression));
AssignmentsIterator assignmentsIterator = new AssignmentsIterator(list(x, y), registry);
String actual = join("\n", assignmentsIterator);
// System.out.println(actual);
assertEquals(expected, actual);
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class AssignmentsSamplingIteratorTest method testSampleOverCategoricalType.
@Test
public void testSampleOverCategoricalType() {
updateContextWithIndexAndType("N", new Categorical("People", 5, parse("p1"), parse("p2"), parse("p3"), parse("p4"), parse("p5")));
Assert.assertEquals("{N=p1}:{N=p3}:{N=p5}", join(":", newSamplingIterator("N", 3, "N != p4")));
Assert.assertEquals("{N=p5}:{N=p5}:{N=p2}:{N=p4}", join(":", newSamplingIterator("N", 4, "N != p1")));
}
Aggregations