caf = new CellAddressFactory(1);
input = caf.getSpaceForNewRelation(1);//(a)
dupRemOper = new DuplicateRemovalOperator(caf, input);
resultFormulas = dupRemOper.getFormulas();
expectedResult = new Formulas();
expectedResult.put(new Cell('B',1), "IF(ISNA(A1),0,1)");
expectedResult.put(new Cell('C',1), "MATCH(ROW(),$B:$B,0)");
expectedResult.put(new Cell('D',1), "INDEX(A:A,$C1)");
expectedResult.put(new Cell('B',2), "IF(OR(ISNA($A2),COUNTIFS($A$1:$A2,$A2)>1),B1,1+B1)");
expectedResult.put(new Cell('C',2), "MATCH(ROW(),$B:$B,0)");
expectedResult.put(new Cell('D',2), "INDEX(A:A,$C2)");
// System.out.println("expected:");
// System.out.println(expectedResult.toString(caf));
// System.out.println("real");
// System.out.println(resultFormulas.toString(caf));
assertEquals(expectedResult, resultFormulas);
resRelation = dupRemOper.getResultRelation();
assertEquals(new Column('D'), resRelation.getFirstCol());
assertEquals(1, resRelation.getCardinality());
caf = new CellAddressFactory(1);
input = caf.getSpaceForNewRelation(2);//(a,b)
dupRemOper = new DuplicateRemovalOperator(caf, input);
resultFormulas = dupRemOper.getFormulas();
expectedResult = new Formulas();
expectedResult.put(new Cell('C',1), "IF(ISNA(A1),0,1)");
expectedResult.put(new Cell('D',1), "MATCH(ROW(),$C:$C,0)");
expectedResult.put(new Cell('E',1), "INDEX(A:A,$D1)");
expectedResult.put(new Cell('F',1), "INDEX(B:B,$D1)");
expectedResult.put(new Cell('C',2), "IF(OR(ISNA($A2),COUNTIFS($A$1:$A2,$A2,$B$1:$B2,$B2)>1),C1,1+C1)");
expectedResult.put(new Cell('D',2), "MATCH(ROW(),$C:$C,0)");
expectedResult.put(new Cell('E',2), "INDEX(A:A,$D2)");
expectedResult.put(new Cell('F',2), "INDEX(B:B,$D2)");
// System.out.println("expected:");
// System.out.println(expectedResult.toString(caf));
// System.out.println("real");
// System.out.println(resultFormulas.toString(caf));
assertEquals(expectedResult, resultFormulas);
resRelation = dupRemOper.getResultRelation();
assertEquals(new Column('E'), resRelation.getFirstCol());
assertEquals(2, resRelation.getCardinality());
caf = new CellAddressFactory(2);//zaczynamy od B i wypełniamy wiersze 3,4,5
input = caf.getSpaceForNewRelation(3);//(b,c,d)
dupRemOper = new DuplicateRemovalOperator(caf, input);
resultFormulas = dupRemOper.getFormulas();
expectedResult = new Formulas();
expectedResult.put(new Cell('E',1), "IF(ISNA(B1),0,1)");
expectedResult.put(new Cell('F',1), "MATCH(ROW(),$E:$E,0)");
expectedResult.put(new Cell('G',1), "INDEX(B:B,$F1)");
expectedResult.put(new Cell('H',1), "INDEX(C:C,$F1)");
expectedResult.put(new Cell('I',1), "INDEX(D:D,$F1)");
expectedResult.put(new Cell('E',2), "IF(OR(ISNA($B2),COUNTIFS($B$1:$B2,$B2,$C$1:$C2,$C2,$D$1:$D2,$D2)>1),E1,1+E1)");
expectedResult.put(new Cell('F',2), "MATCH(ROW(),$E:$E,0)");
expectedResult.put(new Cell('G',2), "INDEX(B:B,$F2)");
expectedResult.put(new Cell('H',2), "INDEX(C:C,$F2)");
expectedResult.put(new Cell('I',2), "INDEX(D:D,$F2)");
// System.out.println("expected:");
// System.out.println(expectedResult.toString(caf));
// System.out.println("real");
// System.out.println(resultFormulas.toString(caf));
assertEquals(expectedResult, resultFormulas);