Program: 150518
Project: 150518
Buggy source:
@Test public void testAggregateFunctions() throws Exception {
  Field<BigDecimal> median=median(TBook_ID());
switch (getDialect()) {
case ASE:
case DERBY:
case H2:
case INGRES:
case MYSQL:
case SQLITE:
case SQLSERVER:
case POSTGRES:
case DB2:
    median=avg(TBook_ID());
  break;
}
Result<Record> result=create().select(TBook_AUTHOR_ID(),count(),count(TBook_ID()),countDistinct(TBook_AUTHOR_ID()),sum(TBook_ID()),avg(TBook_ID()),min(TBook_ID()),max(TBook_ID()),median).from(TBook()).groupBy(TBook_AUTHOR_ID()).orderBy(TBook_AUTHOR_ID()).fetch();
assertEquals(2,(int)result.getValueAsInteger(0,1));
assertEquals(2,(int)result.getValueAsInteger(0,2));
assertEquals(1,(int)result.getValueAsInteger(0,3));
assertEquals(3d,result.getValueAsDouble(0,4));
assertEquals(1,(int)result.getValueAsInteger(0,6));
assertEquals(2,(int)result.getValueAsInteger(0,7));
assertEquals(2,(int)result.getValueAsInteger(1,1));
assertEquals(2,(int)result.getValueAsInteger(1,2));
assertEquals(1,(int)result.getValueAsInteger(1,3));
assertEquals(7d,result.getValueAsDouble(1,4));
assertEquals(3,(int)result.getValueAsInteger(1,6));
assertEquals(4,(int)result.getValueAsInteger(1,7));
assertTrue(asList(1.0,1.5,2.0).contains(result.getValueAsDouble(0,5)));
assertTrue(asList(1.0,1.5,2.0).contains(result.getValueAsDouble(0,8)));
assertTrue(asList(3.0,3.5,4.0).contains(result.getValueAsDouble(1,5)));
assertTrue(asList(3.0,3.5,4.0).contains(result.getValueAsDouble(1,8)));
int distinct1=create().select(countDistinct(TBook_AUTHOR_ID())).from(TBook()).fetchOne(0,Integer.class);
int distinct2=create().select(minDistinct(TBook_AUTHOR_ID())).from(TBook()).fetchOne(0,Integer.class);
int distinct3=create().select(maxDistinct(TBook_AUTHOR_ID())).from(TBook()).fetchOne(0,Integer.class);
int distinct4=create().select(sumDistinct(TBook_AUTHOR_ID())).from(TBook()).fetchOne(0,Integer.class);
double distinct5=create().select(avgDistinct(TBook_AUTHOR_ID())).from(TBook()).fetchOne(0,Double.class);
assertEquals(2,distinct1);
assertEquals(1,distinct2);
assertEquals(2,distinct3);
assertEquals(3,distinct4);
assertTrue(asList(1.0,1.5,2.0).contains(distinct5));
switch (getDialect()) {
case DERBY:
case SQLITE:
log.info("String_Node_Str","String_Node_Str");
break;
default :
{
result=create().select(TBook_AUTHOR_ID(),stddevPop(TBook_ID()),stddevSamp(TBook_ID()),varPop(TBook_ID()),varSamp(TBook_ID())).from(TBook()).groupBy(TBook_AUTHOR_ID()).orderBy(TBook_AUTHOR_ID()).fetch();
assertEquals(0.5,result.getValueAsDouble(0,1));
assertEquals(0.25,result.getValueAsDouble(0,3));
assertEquals(0.5,result.getValueAsDouble(1,1));
assertEquals(0.25,result.getValueAsDouble(1,3));
if (getDialect() != SQLDialect.DB2) {
assertEquals("String_Node_Str",result.getValueAsString(0,2).substring(0,5));
assertEquals(0.5,result.getValueAsDouble(0,4));
assertEquals("String_Node_Str",result.getValueAsString(1,2).substring(0,5));
assertEquals(0.5,result.getValueAsDouble(1,4));
}
}
}
result=create().select(TBook_AUTHOR_ID(),max(TBook_ID()),max(TBook_ID())).from(TBook()).groupBy(TBook_AUTHOR_ID()).orderBy(TBook_AUTHOR_ID()).fetch();
assertEquals(2,(int)result.getValueAsInteger(0,1));
assertEquals(2,(int)result.getValueAsInteger(0,2));
assertEquals(4,(int)result.getValueAsInteger(1,1));
assertEquals(4,(int)result.getValueAsInteger(1,2));
}

Fixed version (ground truth):
@Test public void testAggregateFunctions() throws Exception {
  Field<BigDecimal> median=median(TBook_ID());
switch (getDialect()) {
case ASE:
case CUBRID:
case DERBY:
case H2:
case INGRES:
case MYSQL:
case SQLITE:
case SQLSERVER:
case POSTGRES:
case DB2:
    median=avg(TBook_ID());
  break;
}
Result<Record> result=create().select(TBook_AUTHOR_ID(),count(),count(TBook_ID()),countDistinct(TBook_AUTHOR_ID()),sum(TBook_ID()),avg(TBook_ID()),min(TBook_ID()),max(TBook_ID()),median).from(TBook()).groupBy(TBook_AUTHOR_ID()).orderBy(TBook_AUTHOR_ID()).fetch();
assertEquals(2,(int)result.getValueAsInteger(0,1));
assertEquals(2,(int)result.getValueAsInteger(0,2));
assertEquals(1,(int)result.getValueAsInteger(0,3));
assertEquals(3d,result.getValueAsDouble(0,4));
assertEquals(1,(int)result.getValueAsInteger(0,6));
assertEquals(2,(int)result.getValueAsInteger(0,7));
assertEquals(2,(int)result.getValueAsInteger(1,1));
assertEquals(2,(int)result.getValueAsInteger(1,2));
assertEquals(1,(int)result.getValueAsInteger(1,3));
assertEquals(7d,result.getValueAsDouble(1,4));
assertEquals(3,(int)result.getValueAsInteger(1,6));
assertEquals(4,(int)result.getValueAsInteger(1,7));
assertTrue(asList(1.0,1.5,2.0).contains(result.getValueAsDouble(0,5)));
assertTrue(asList(1.0,1.5,2.0).contains(result.getValueAsDouble(0,8)));
assertTrue(asList(3.0,3.5,4.0).contains(result.getValueAsDouble(1,5)));
assertTrue(asList(3.0,3.5,4.0).contains(result.getValueAsDouble(1,8)));
int distinct1=create().select(countDistinct(TBook_AUTHOR_ID())).from(TBook()).fetchOne(0,Integer.class);
int distinct2=create().select(minDistinct(TBook_AUTHOR_ID())).from(TBook()).fetchOne(0,Integer.class);
int distinct3=create().select(maxDistinct(TBook_AUTHOR_ID())).from(TBook()).fetchOne(0,Integer.class);
int distinct4=create().select(sumDistinct(TBook_AUTHOR_ID())).from(TBook()).fetchOne(0,Integer.class);
double distinct5=create().select(avgDistinct(TBook_AUTHOR_ID())).from(TBook()).fetchOne(0,Double.class);
assertEquals(2,distinct1);
assertEquals(1,distinct2);
assertEquals(2,distinct3);
assertEquals(3,distinct4);
assertTrue(asList(1.0,1.5,2.0).contains(distinct5));
switch (getDialect()) {
case DERBY:
case SQLITE:
log.info("String_Node_Str","String_Node_Str");
break;
default :
{
result=create().select(TBook_AUTHOR_ID(),stddevPop(TBook_ID()),stddevSamp(TBook_ID()),varPop(TBook_ID()),varSamp(TBook_ID())).from(TBook()).groupBy(TBook_AUTHOR_ID()).orderBy(TBook_AUTHOR_ID()).fetch();
assertEquals(0.5,result.getValueAsDouble(0,1));
assertEquals(0.25,result.getValueAsDouble(0,3));
assertEquals(0.5,result.getValueAsDouble(1,1));
assertEquals(0.25,result.getValueAsDouble(1,3));
if (getDialect() != SQLDialect.DB2) {
assertEquals("String_Node_Str",result.getValueAsString(0,2).substring(0,5));
assertEquals(0.5,result.getValueAsDouble(0,4));
assertEquals("String_Node_Str",result.getValueAsString(1,2).substring(0,5));
assertEquals(0.5,result.getValueAsDouble(1,4));
}
}
}
result=create().select(TBook_AUTHOR_ID(),max(TBook_ID()),max(TBook_ID())).from(TBook()).groupBy(TBook_AUTHOR_ID()).orderBy(TBook_AUTHOR_ID()).fetch();
assertEquals(2,(int)result.getValueAsInteger(0,1));
assertEquals(2,(int)result.getValueAsInteger(0,2));
assertEquals(4,(int)result.getValueAsInteger(1,1));
assertEquals(4,(int)result.getValueAsInteger(1,2));
}