use of org.apache.poi.ss.formula.ptg.FuncVarPtg in project poi by apache.
the class TestFormulaRecord method testWithConcat.
public void testWithConcat() {
// =CHOOSE(2,A2,A3,A4)
byte[] data = { 1, 0, 1, 0, 15, 0, 0, 0, 0, 0, 0, 0, 57, 64, 0, 0, 12, 0, 12, -4, 46, 0, // Int - 2
30, // Int - 2
2, // Int - 2
0, // Attr
25, // Attr
4, // Attr
3, // Attr
0, // jumpTable
8, // jumpTable
0, // jumpTable
17, // jumpTable
0, // jumpTable
26, // jumpTable
0, // chooseOffset
35, // chooseOffset
0, // Ref - A2
36, // Ref - A2
1, // Ref - A2
0, // Ref - A2
0, // Ref - A2
-64, // Attr
25, // Attr
8, // Attr
21, // Attr
0, // Ref - A3
36, // Ref - A3
2, // Ref - A3
0, // Ref - A3
0, // Ref - A3
-64, // Attr
25, // Attr
8, // Attr
12, // Attr
0, // Ref - A4
36, // Ref - A4
3, // Ref - A4
0, // Ref - A4
0, // Ref - A4
-64, // Attr
25, // Attr
8, // Attr
3, // Attr
0, // CHOOSE
66, // CHOOSE
4, // CHOOSE
100, // CHOOSE
0 };
RecordInputStream inp = TestcaseRecordInputStream.create(FormatRecord.sid, data);
FormulaRecord fr = new FormulaRecord(inp);
Ptg[] ptgs = fr.getParsedExpression();
assertEquals(9, ptgs.length);
assertEquals(IntPtg.class, ptgs[0].getClass());
assertEquals(AttrPtg.class, ptgs[1].getClass());
assertEquals(RefPtg.class, ptgs[2].getClass());
assertEquals(AttrPtg.class, ptgs[3].getClass());
assertEquals(RefPtg.class, ptgs[4].getClass());
assertEquals(AttrPtg.class, ptgs[5].getClass());
assertEquals(RefPtg.class, ptgs[6].getClass());
assertEquals(AttrPtg.class, ptgs[7].getClass());
assertEquals(FuncVarPtg.class, ptgs[8].getClass());
FuncVarPtg choose = (FuncVarPtg) ptgs[8];
assertEquals("CHOOSE", choose.getName());
}
use of org.apache.poi.ss.formula.ptg.FuncVarPtg in project poi by apache.
the class TestFormulaParserIf method testNestedFunctionIf.
/**
* Make sure the ptgs are generated properly with two functions embedded
*
*/
public void testNestedFunctionIf() {
Ptg[] ptgs = parseFormula("IF(A1=B1,AVERAGE(A1:B1),AVERAGE(A2:B2))");
assertEquals(11, ptgs.length);
assertTrue("IF Attr set correctly", (ptgs[3] instanceof AttrPtg));
AttrPtg ifFunc = (AttrPtg) ptgs[3];
assertTrue("It is not an if", ifFunc.isOptimizedIf());
assertTrue("Average Function set correctly", (ptgs[5] instanceof FuncVarPtg));
}
use of org.apache.poi.ss.formula.ptg.FuncVarPtg in project poi by apache.
the class TestFormulaParserIf method testIfSingleCondition.
public void testIfSingleCondition() {
Ptg[] ptgs = parseFormula("IF(1=1,10)");
assertEquals(7, ptgs.length);
assertTrue("IF Attr set correctly", (ptgs[3] instanceof AttrPtg));
AttrPtg ifFunc = (AttrPtg) ptgs[3];
assertTrue("It is not an if", ifFunc.isOptimizedIf());
assertTrue("Single Value is not an IntPtg", (ptgs[4] instanceof IntPtg));
IntPtg intPtg = (IntPtg) ptgs[4];
assertEquals("Result", (short) 10, intPtg.getValue());
assertTrue("Ptg is not a Variable Function", (ptgs[6] instanceof FuncVarPtg));
FuncVarPtg funcPtg = (FuncVarPtg) ptgs[6];
assertEquals("Arguments", 2, funcPtg.getNumberOfOperands());
}
Aggregations