Search in sources :

Example 1 with FormulaValidator

use of org.activityinfo.analysis.FormulaValidator in project activityinfo by bedatadriven.

the class FormulaValidatorTest method booleanEnumReference.

@Test
public void booleanEnumReference() {
    FormulaValidator validator = validate("Gender.Female || Gender.Male");
    assertThat(validator.getErrors(), hasSize(0));
    assertTrue(validator.isValid());
    assertThat(validator.getResultType(), equalTo(BooleanType.INSTANCE));
}
Also used : FormulaValidator(org.activityinfo.analysis.FormulaValidator) Test(org.junit.Test)

Example 2 with FormulaValidator

use of org.activityinfo.analysis.FormulaValidator in project activityinfo by bedatadriven.

the class FormulaValidatorTest method badNumberOfArguments.

@Test
public void badNumberOfArguments() {
    FormulaValidator validator = validate("IF(1)");
    assertThat(validator.getErrors(), hasSize(1));
    assertThat(validator.getErrors().get(0).getSourceRange(), equalTo(new SourceRange(new SourcePos(0, 0), 5)));
}
Also used : FormulaValidator(org.activityinfo.analysis.FormulaValidator) SourceRange(org.activityinfo.model.formula.SourceRange) SourcePos(org.activityinfo.model.formula.SourcePos) Test(org.junit.Test)

Example 3 with FormulaValidator

use of org.activityinfo.analysis.FormulaValidator in project activityinfo by bedatadriven.

the class FormulaValidatorTest method invalidFormSchema.

@Test
public void invalidFormSchema() {
    FormClass formClass = new FormClass(ResourceId.valueOf("XYZ"));
    formClass.addField(ResourceId.valueOf("F1")).setCode("A").setLabel("Field A1").setType(TextType.SIMPLE);
    formClass.addField(ResourceId.valueOf("F2")).setCode("A").setLabel("Field A2").setType(TextType.SIMPLE);
    TestBatchFormClassProvider formProvider = new TestBatchFormClassProvider();
    formProvider.add(formClass);
    FormTreeBuilder formTreeBuilder = new FormTreeBuilder(formProvider);
    FormTree formTree = formTreeBuilder.queryTree(formClass.getId());
    FormulaValidator validator = new FormulaValidator(formTree);
    assertFalse(validator.validate(FormulaParser.parse("A")));
    assertThat(validator.getErrors(), hasSize(1));
}
Also used : FormulaValidator(org.activityinfo.analysis.FormulaValidator) FormTree(org.activityinfo.model.formTree.FormTree) FormClass(org.activityinfo.model.form.FormClass) TestBatchFormClassProvider(org.activityinfo.model.formTree.TestBatchFormClassProvider) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) Test(org.junit.Test)

Example 4 with FormulaValidator

use of org.activityinfo.analysis.FormulaValidator in project activityinfo by bedatadriven.

the class FormulaValidatorTest method goodSymbols.

@Test
public void goodSymbols() {
    FormulaValidator validator = validate("AGE");
    assertThat(validator.getErrors(), hasSize(0));
    assertTrue(validator.isValid());
    assertThat(validator.getResultType(), instanceOf(QuantityType.class));
}
Also used : FormulaValidator(org.activityinfo.analysis.FormulaValidator) QuantityType(org.activityinfo.model.type.number.QuantityType) Test(org.junit.Test)

Example 5 with FormulaValidator

use of org.activityinfo.analysis.FormulaValidator in project activityinfo by bedatadriven.

the class FormulaValidatorTest method validTypeArguments.

@Test
public void validTypeArguments() {
    FormulaValidator validator = validate("IF(TRUE, 1, 0)");
    assertThat(validator.getErrors(), hasSize(0));
    assertTrue(validator.isValid());
    assertThat(validator.getResultType(), instanceOf(QuantityType.class));
}
Also used : FormulaValidator(org.activityinfo.analysis.FormulaValidator) QuantityType(org.activityinfo.model.type.number.QuantityType) Test(org.junit.Test)

Aggregations

FormulaValidator (org.activityinfo.analysis.FormulaValidator)8 Test (org.junit.Test)7 QuantityType (org.activityinfo.model.type.number.QuantityType)2 FormClass (org.activityinfo.model.form.FormClass)1 FormTree (org.activityinfo.model.formTree.FormTree)1 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)1 TestBatchFormClassProvider (org.activityinfo.model.formTree.TestBatchFormClassProvider)1 FormulaError (org.activityinfo.model.formula.FormulaError)1 SourcePos (org.activityinfo.model.formula.SourcePos)1 SourceRange (org.activityinfo.model.formula.SourceRange)1 Survey (org.activityinfo.store.testing.Survey)1