2021-06-21 13:36:47 -05:00
|
|
|
/******************************************************************************
|
|
|
|
|
* Top contributors (to current version):
|
2022-04-05 13:38:57 -07:00
|
|
|
* Mudathir Mohamed, Andrew Reynolds, Andres Noetzli
|
2021-06-21 13:36:47 -05:00
|
|
|
*
|
|
|
|
|
* This file is part of the cvc5 project.
|
|
|
|
|
*
|
2022-04-05 13:38:57 -07:00
|
|
|
* Copyright (c) 2009-2022 by the authors listed in the file AUTHORS
|
2021-06-21 13:36:47 -05:00
|
|
|
* in the top-level source directory and their institutional affiliations.
|
|
|
|
|
* All rights reserved. See the file COPYING in the top-level source
|
|
|
|
|
* directory for licensing information.
|
|
|
|
|
* ****************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* Black box testing of the guards of the Java API functions.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-22 18:00:06 -05:00
|
|
|
package tests;
|
2022-03-30 21:09:03 -07:00
|
|
|
import static io.github.cvc5.Kind.*;
|
2021-06-21 13:36:47 -05:00
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
|
2022-03-30 21:09:03 -07:00
|
|
|
import io.github.cvc5.*;
|
2021-06-21 13:36:47 -05:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
2021-09-30 12:07:39 -05:00
|
|
|
class GrammarTest
|
|
|
|
|
{
|
2021-06-21 13:36:47 -05:00
|
|
|
private Solver d_solver;
|
|
|
|
|
|
2022-03-30 16:58:08 -05:00
|
|
|
@BeforeEach
|
|
|
|
|
void setUp()
|
2021-09-30 12:07:39 -05:00
|
|
|
{
|
2021-06-21 13:36:47 -05:00
|
|
|
d_solver = new Solver();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-30 16:58:08 -05:00
|
|
|
@AfterEach
|
|
|
|
|
void tearDown()
|
2021-11-03 16:32:10 -05:00
|
|
|
{
|
|
|
|
|
d_solver.close();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 07:55:44 -07:00
|
|
|
@Test
|
|
|
|
|
void testToString()
|
|
|
|
|
{
|
|
|
|
|
d_solver.setOption("sygus", "true");
|
|
|
|
|
Sort bool = d_solver.getBooleanSort();
|
|
|
|
|
Term start = d_solver.mkVar(bool);
|
|
|
|
|
Grammar g = d_solver.mkGrammar(new Term[] {}, new Term[] {start});
|
|
|
|
|
g.addRule(start, d_solver.mkBoolean(false));
|
|
|
|
|
g.toString();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-30 16:58:08 -05:00
|
|
|
@Test
|
|
|
|
|
void addRule()
|
2021-09-30 12:07:39 -05:00
|
|
|
{
|
2022-03-24 21:21:44 -05:00
|
|
|
d_solver.setOption("sygus", "true");
|
2021-06-21 13:36:47 -05:00
|
|
|
Sort bool = d_solver.getBooleanSort();
|
|
|
|
|
Sort integer = d_solver.getIntegerSort();
|
|
|
|
|
|
|
|
|
|
Term nullTerm = d_solver.getNullTerm();
|
|
|
|
|
Term start = d_solver.mkVar(bool);
|
|
|
|
|
Term nts = d_solver.mkVar(bool);
|
|
|
|
|
|
2022-04-02 14:40:41 -05:00
|
|
|
Grammar g = d_solver.mkGrammar(new Term[] {}, new Term[] {start});
|
2021-06-21 13:36:47 -05:00
|
|
|
|
|
|
|
|
assertDoesNotThrow(() -> g.addRule(start, d_solver.mkBoolean(false)));
|
|
|
|
|
|
2021-09-30 12:07:39 -05:00
|
|
|
assertThrows(CVC5ApiException.class, () -> g.addRule(nullTerm, d_solver.mkBoolean(false)));
|
2021-06-21 13:36:47 -05:00
|
|
|
assertThrows(CVC5ApiException.class, () -> g.addRule(start, nullTerm));
|
2021-09-30 12:07:39 -05:00
|
|
|
assertThrows(CVC5ApiException.class, () -> g.addRule(nts, d_solver.mkBoolean(false)));
|
|
|
|
|
assertThrows(CVC5ApiException.class, () -> g.addRule(start, d_solver.mkInteger(0)));
|
2021-06-21 13:36:47 -05:00
|
|
|
assertThrows(CVC5ApiException.class, () -> g.addRule(start, nts));
|
|
|
|
|
|
|
|
|
|
d_solver.synthFun("f", new Term[] {}, bool, g);
|
|
|
|
|
|
2021-09-30 12:07:39 -05:00
|
|
|
assertThrows(CVC5ApiException.class, () -> g.addRule(start, d_solver.mkBoolean(false)));
|
2021-06-21 13:36:47 -05:00
|
|
|
}
|
|
|
|
|
|
2022-03-30 16:58:08 -05:00
|
|
|
@Test
|
|
|
|
|
void addRules()
|
2021-09-30 12:07:39 -05:00
|
|
|
{
|
2022-03-24 21:21:44 -05:00
|
|
|
d_solver.setOption("sygus", "true");
|
2021-06-21 13:36:47 -05:00
|
|
|
Sort bool = d_solver.getBooleanSort();
|
|
|
|
|
Sort integer = d_solver.getIntegerSort();
|
|
|
|
|
|
|
|
|
|
Term nullTerm = d_solver.getNullTerm();
|
|
|
|
|
Term start = d_solver.mkVar(bool);
|
|
|
|
|
Term nts = d_solver.mkVar(bool);
|
|
|
|
|
|
2022-04-02 14:40:41 -05:00
|
|
|
Grammar g = d_solver.mkGrammar(new Term[] {}, new Term[] {start});
|
2021-06-21 13:36:47 -05:00
|
|
|
|
2021-09-30 12:07:39 -05:00
|
|
|
assertDoesNotThrow(() -> g.addRules(start, new Term[] {d_solver.mkBoolean(false)}));
|
2021-06-21 13:36:47 -05:00
|
|
|
|
|
|
|
|
assertThrows(
|
2021-09-30 12:07:39 -05:00
|
|
|
CVC5ApiException.class, () -> g.addRules(nullTerm, new Term[] {d_solver.mkBoolean(false)}));
|
|
|
|
|
assertThrows(CVC5ApiException.class, () -> g.addRules(start, new Term[] {nullTerm}));
|
2021-06-21 13:36:47 -05:00
|
|
|
assertThrows(
|
2021-09-30 12:07:39 -05:00
|
|
|
CVC5ApiException.class, () -> g.addRules(nts, new Term[] {d_solver.mkBoolean(false)}));
|
|
|
|
|
assertThrows(
|
|
|
|
|
CVC5ApiException.class, () -> g.addRules(start, new Term[] {d_solver.mkInteger(0)}));
|
|
|
|
|
assertThrows(CVC5ApiException.class, () -> g.addRules(start, new Term[] {nts}));
|
2021-06-21 13:36:47 -05:00
|
|
|
|
|
|
|
|
d_solver.synthFun("f", new Term[] {}, bool, g);
|
|
|
|
|
|
2021-09-30 12:07:39 -05:00
|
|
|
assertThrows(
|
|
|
|
|
CVC5ApiException.class, () -> g.addRules(start, new Term[] {d_solver.mkBoolean(false)}));
|
2021-06-21 13:36:47 -05:00
|
|
|
}
|
|
|
|
|
|
2022-03-30 16:58:08 -05:00
|
|
|
@Test
|
|
|
|
|
void addAnyConstant()
|
2021-09-30 12:07:39 -05:00
|
|
|
{
|
2022-03-24 21:21:44 -05:00
|
|
|
d_solver.setOption("sygus", "true");
|
2021-06-21 13:36:47 -05:00
|
|
|
Sort bool = d_solver.getBooleanSort();
|
|
|
|
|
|
|
|
|
|
Term nullTerm = d_solver.getNullTerm();
|
|
|
|
|
Term start = d_solver.mkVar(bool);
|
|
|
|
|
Term nts = d_solver.mkVar(bool);
|
|
|
|
|
|
2022-04-02 14:40:41 -05:00
|
|
|
Grammar g = d_solver.mkGrammar(new Term[] {}, new Term[] {start});
|
2021-06-21 13:36:47 -05:00
|
|
|
|
|
|
|
|
assertDoesNotThrow(() -> g.addAnyConstant(start));
|
|
|
|
|
assertDoesNotThrow(() -> g.addAnyConstant(start));
|
|
|
|
|
|
|
|
|
|
assertThrows(CVC5ApiException.class, () -> g.addAnyConstant(nullTerm));
|
|
|
|
|
assertThrows(CVC5ApiException.class, () -> g.addAnyConstant(nts));
|
|
|
|
|
|
|
|
|
|
d_solver.synthFun("f", new Term[] {}, bool, g);
|
|
|
|
|
|
|
|
|
|
assertThrows(CVC5ApiException.class, () -> g.addAnyConstant(start));
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-30 16:58:08 -05:00
|
|
|
@Test
|
|
|
|
|
void addAnyVariable()
|
2021-09-30 12:07:39 -05:00
|
|
|
{
|
2022-03-24 21:21:44 -05:00
|
|
|
d_solver.setOption("sygus", "true");
|
2021-06-21 13:36:47 -05:00
|
|
|
Sort bool = d_solver.getBooleanSort();
|
|
|
|
|
|
|
|
|
|
Term nullTerm = d_solver.getNullTerm();
|
|
|
|
|
Term x = d_solver.mkVar(bool);
|
|
|
|
|
Term start = d_solver.mkVar(bool);
|
|
|
|
|
Term nts = d_solver.mkVar(bool);
|
|
|
|
|
|
2022-04-02 14:40:41 -05:00
|
|
|
Grammar g1 = d_solver.mkGrammar(new Term[] {x}, new Term[] {start});
|
|
|
|
|
Grammar g2 = d_solver.mkGrammar(new Term[] {}, new Term[] {start});
|
2021-06-21 13:36:47 -05:00
|
|
|
|
|
|
|
|
assertDoesNotThrow(() -> g1.addAnyVariable(start));
|
|
|
|
|
assertDoesNotThrow(() -> g1.addAnyVariable(start));
|
|
|
|
|
assertDoesNotThrow(() -> g2.addAnyVariable(start));
|
|
|
|
|
|
|
|
|
|
assertThrows(CVC5ApiException.class, () -> g1.addAnyVariable(nullTerm));
|
|
|
|
|
assertThrows(CVC5ApiException.class, () -> g1.addAnyVariable(nts));
|
|
|
|
|
|
|
|
|
|
d_solver.synthFun("f", new Term[] {}, bool, g1);
|
|
|
|
|
|
|
|
|
|
assertThrows(CVC5ApiException.class, () -> g1.addAnyVariable(start));
|
|
|
|
|
}
|
|
|
|
|
}
|