You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestFormulaParser.java 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package org.apache.poi.xslf.geom;
  2. import junit.framework.TestCase;
  3. import org.apache.poi.xslf.model.geom.*;
  4. import org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D;
  5. /**
  6. * Date: 10/24/11
  7. *
  8. * @author Yegor Kozlov
  9. */
  10. public class TestFormulaParser extends TestCase {
  11. public void testParse(){
  12. Formula[] ops = {
  13. new Guide("adj1", "val 100"),
  14. new Guide("adj2", "val 200"),
  15. new Guide("adj3", "val -1"),
  16. new Guide("a1", "*/ adj1 2 adj2"), // a1 = 100*2 / 200
  17. new Guide("a2", "+- adj2 a1 adj1"), // a2 = 200 + a1 - 100
  18. new Guide("a3", "+/ adj1 adj2 adj2"), // a3 = (100 + 200) / 200
  19. new Guide("a4", "?: adj3 adj1 adj2"), // a4 = adj3 > 0 ? adj1 : adj2
  20. new Guide("a5", "abs -2"),
  21. };
  22. CustomGeometry geom = new CustomGeometry(CTCustomGeometry2D.Factory.newInstance());
  23. Context ctx = new Context(geom, null, null);
  24. for(Formula fmla : ops) {
  25. ctx.evaluate(fmla);
  26. }
  27. assertEquals(100.0, ctx.getValue("adj1"));
  28. assertEquals(200.0, ctx.getValue("adj2"));
  29. assertEquals(1.0, ctx.getValue("a1"));
  30. assertEquals(101.0, ctx.getValue("a2"));
  31. assertEquals(1.5, ctx.getValue("a3"));
  32. assertEquals(200.0, ctx.getValue("a4"));
  33. assertEquals(2.0, ctx.getValue("a5"));
  34. }
  35. }