Skip to content
Snippets Groups Projects
Commit 741f5afb authored by Jenny Zhang's avatar Jenny Zhang
Browse files

finished astsToString function with tests

parent 0b43b9b0
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,21 @@ const precedence = { ...@@ -20,6 +20,21 @@ const precedence = {
'false': 5 'false': 5
}; };
function astsToString(nodes){
const leftList = nodes[0];
const rightList = nodes[1];
if (leftList.length > 0) {
const leftFormulas = leftList.map(ast => astToString(ast)).join(",");
const rightFormulas = rightList.map(ast => astToString(ast)).join(",");
return `${leftFormulas}|-${rightFormulas}`;
}
const rightFormulas = rightList.map(ast => astToString(ast)).join(",");
return `|-${rightFormulas}`;
}
function astToString(node, parentPrecedence = 0) { function astToString(node, parentPrecedence = 0) {
if (!node) return ""; if (!node) return "";
...@@ -134,5 +149,6 @@ ast.False = Node.bind(null, 'false'); ...@@ -134,5 +149,6 @@ ast.False = Node.bind(null, 'false');
ast.astToString = astToString; ast.astToString = astToString;
ast.astToLaTeX = astToLaTeX; ast.astToLaTeX = astToLaTeX;
ast.astsToLateX = astsToLateX; ast.astsToLateX = astsToLateX;
ast.astsToString = astsToString;
module.exports = ast; // Export the AST module module.exports = ast; // Export the AST module
\ No newline at end of file
...@@ -106,6 +106,21 @@ test('astToString could work correctly for complex expression', () => { ...@@ -106,6 +106,21 @@ test('astToString could work correctly for complex expression', () => {
expect(output).toEqual(inputString); expect(output).toEqual(inputString);
}); });
// astsToString test for sequent
test('astsToLateX could work correctly for complex expression', () => {
const inputString = "|-!(A->B||C&D)";
const input = parse(inputString);
const output = ast.astsToString(input);
expect(output).toEqual(inputString);
});
test('astsToLateX could work correctly for complex expression', () => {
const inputString = "A,B|-X&(Y->Z),C";
const input = parse(inputString);
const output = ast.astsToString(input);
expect(output).toEqual(inputString);
});
// astToLaTeX test for expression // astToLaTeX test for expression
test('astToLaTeX could work correctly for and expression', () => { test('astToLaTeX could work correctly for and expression', () => {
const inputString = "A & B"; const inputString = "A & B";
...@@ -156,7 +171,7 @@ test('astToLaTeX could work correctly for complex expression', () => { ...@@ -156,7 +171,7 @@ test('astToLaTeX could work correctly for complex expression', () => {
expect(output).toEqual("\\mathit{X} \\land (\\mathit{Y} \\rightarrow \\mathit{Z})"); expect(output).toEqual("\\mathit{X} \\land (\\mathit{Y} \\rightarrow \\mathit{Z})");
}); });
// astsToLateX test // astsToLateX test for sequent
test('astsToLateX could work correctly for complex expression', () => { test('astsToLateX could work correctly for complex expression', () => {
const inputString = "|- X & (Y -> Z)"; const inputString = "|- X & (Y -> Z)";
const input = parse(inputString); const input = parse(inputString);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment