package io.jenetics.ext.util;

import java.util.List;

import org.testng.annotations.Test;

public class FormulaParserTest {

	@Test
	public void parse() {
		final FormulaParser<String> formula = FormulaParser.<String>builder()
			.lparen("(")
			.rparen(")")
			.comma(",")
			.unaryOperators("+", "-", "!")
			.binaryOperators(ops -> ops
				.add(11, "+", "-")
				.add(12, "*", "/", "%")
				.add(14, "^", "**"))
			.identifiers("x", "y", "z")
			.functions("pow", "sin", "cos")
			.build();

		final var expr = List.of(
			"x", "*", "x", "+", "sin", "(", "z", ")");
		final var tree = formula.parse(expr);
		System.out.println(tree);

		/*
				new BinaryOperators<>(11, "+", "-"),
				new BinaryOperators<>(12, "*", "/", "%"),
				new BinaryOperators<>(14, "^", "**")
		 */
	}

}

@@ -1,95 +1,991 @@
-package io.jenetics.ext.util;%0A%0Aimport java.util.List;%0A%0Aimport org.testng.annotations.Test;%0A
+/*%0A * Java Genetic Algorithm Library (@__identifier__@).%0A * Copyright (c) @__year__@ Franz Wilhelmst%C3%B6tter%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A *%0A * Author:%0A *    Franz Wilhelmst%C3%B6tter (franz.wilhelmstoetter@gmail.com)%0A */%0Apackage io.jenetics.ext.util;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat;%0A%0Aimport java.util.List;%0A%0Aimport org.testng.annotations.Test;%0A%0A/**%0A * @author %3Ca href=%22mailto:franz.wilhelmstoetter@gmail.com%22%3EFranz Wilhelmst%C3%B6tter%3C/a%3E%0A */
 %0Apub
@@ -1456,15 +1456,103 @@
 %22z%22,
+ %22)%22, %22-%22, %22cos%22, %22(%22, %22x%22, %22)%22,%0A%09%09%09%22+%22, %22y%22, %22/%22, %22z%22, %22-%22, %22pow%22, %22(%22, %22z%22, %22,%22, %22x%22,
  %22)%22);%0A
+%0A
 %09%09fi
@@ -1593,173 +1593,107 @@
 ;%0A%09%09
-System.out.println
+assertThat
 (tree)
-;%0A
 %0A%09%09
-/*%0A%09%09%09%09new BinaryOperators%3C%3E(11, %22+%22, %22-%22),%0A%09%09%09%09new BinaryOperators%3C%3E(12, %22*%22, %22/%22, %22%25%22),%0A%09%09%09%09new BinaryOperators%3C%3E(14, %22%5E%22, %22**%22)%0A%09%09 */
+%09.isEqualTo(TreeNode.parse(%22-(+(-(+(*(x,x),sin(z)),cos(x)),/(y,z)),pow(z,x))%22));
 %0A%09%7D%0A

Implement 'FormulaParserTest'.