Search in sources :

Example 66 with Node

use of suite.node.Node in project suite by stupidsing.

the class TextTest method testSh.

@Test
public void testSh() throws IOException {
    Node node = Suite.applyPerform(Suite.parse("sh {\"git status\"} {}"), Atom.of("any"));
    StringWriter writer = new StringWriter();
    Suite.evaluateFunToWriter(Suite.fcc(Suite.applyWriter(node)), writer);
    String out = writer.toString();
    System.out.println(out);
    assertNotNull(out);
}
Also used : StringWriter(java.io.StringWriter) Node(suite.node.Node) Test(org.junit.Test)

Example 67 with Node

use of suite.node.Node in project suite by stupidsing.

the class IntrinsicTest method testCharsReplace.

@Test
public void testCharsReplace() {
    String fp = "cs-replace {\"abc\" | cs-from-string} {\"def\" | cs-from-string}  {\"012abcdefghi\" | cs-from-string} | cs-to-string";
    Node expect = Suite.evaluateFun("\"012defdefghi\"", true);
    Node actual = Suite.evaluateFun(fp, true);
    assertTrue(Comparer.comparer.compare(expect, actual) == 0);
}
Also used : Node(suite.node.Node) Test(org.junit.Test)

Example 68 with Node

use of suite.node.Node in project suite by stupidsing.

the class FunCreatorTest method testExpression.

@Test
public void testExpression() {
    Int N1 = Int.of(1);
    @SuppressWarnings({ "rawtypes", "unchecked" }) FunCreator<Source<Node>> fc = (FunCreator) FunCreator.of(Source.class);
    assertEquals(Suite.parse("1"), fc.create(() -> f.object(N1)).apply(void_).source());
    assertEquals(Suite.parse("1 + 1"), fc.create(() -> // 
    f.invokeStatic(// 
    Tree.class, // 
    "of", // 
    f.object(TermOp.PLUS__), // 
    f.object(N1).cast_(Node.class), // 
    f.object(N1).cast_(Node.class))).apply(// 
    void_).source());
}
Also used : Node(suite.node.Node) Int(suite.node.Int) Int_Int(suite.primitive.Int_Int) Source(suite.util.FunUtil.Source) IntSource(suite.primitive.IntPrimitives.IntSource) Test(org.junit.Test)

Example 69 with Node

use of suite.node.Node in project suite by stupidsing.

the class LogicCompilerLevel1Test method testCompileFunProgram.

/**
 * Compiles the functional compiler and use it to compile a simple functional
 * program.
 */
@Test
public void testCompileFunProgram() {
    RuleSet rs = Suite.newRuleSet(List.of("auto.sl", "fc/fc.sl"));
    String gs = // 
    "" + // 
    "source .in" + // 
    ", compile-function .0 .in .out" + ", sink .out";
    Node goal = new Specializer().specialize(Suite.substitute(gs, Atom.of("LAZY")));
    Node input = Suite.parse("1 + 2");
    Node result = FindUtil.collectSingle(finder(rs, goal), input);
    System.out.println(result);
    assertNotNull(result);
}
Also used : RuleSet(suite.lp.kb.RuleSet) Specializer(suite.lp.doer.Specializer) Node(suite.node.Node) Test(org.junit.Test)

Example 70 with Node

use of suite.node.Node in project suite by stupidsing.

the class LogicCompilerLevel1Test method testTailCalls.

/**
 * This test might fail in some poor tail recursion optimization
 * implementations, as some variables are not unbounded when backtracking.
 */
@Test
public void testTailCalls() {
    RuleSet rs = Suite.newRuleSet();
    Suite.addRule(rs, "ab a");
    Suite.addRule(rs, "ab b");
    Node goal = Suite.parse("ab .a, ab .b, sink (.a, .b,)");
    List<Node> results = FindUtil.collectList(finder(rs, goal), Atom.NIL);
    System.out.println(results);
    assertTrue(results.size() == 4);
}
Also used : RuleSet(suite.lp.kb.RuleSet) Node(suite.node.Node) Test(org.junit.Test)

Aggregations

Node (suite.node.Node)139 Tree (suite.node.Tree)50 Reference (suite.node.Reference)41 Atom (suite.node.Atom)37 Int (suite.node.Int)33 ArrayList (java.util.ArrayList)32 Pair (suite.adt.pair.Pair)25 List (java.util.List)24 TermOp (suite.node.io.TermOp)21 Read (suite.streamlet.Read)21 Test (org.junit.Test)20 Map (java.util.Map)19 Suite (suite.Suite)18 Generalizer (suite.lp.doer.Generalizer)18 Fail (suite.util.Fail)18 Fun (suite.util.FunUtil.Fun)18 Str (suite.node.Str)17 Trail (suite.lp.Trail)16 RuleSet (suite.lp.kb.RuleSet)16 Tuple (suite.node.Tuple)16