Commit f9da06da authored by konovalovsergey's avatar konovalovsergey

min/max function ignore bool and empty values in cRef and cArea

parent df5ad313
......@@ -800,6 +800,33 @@ $( function () {
oParser = new parserFormula( "MAX(S5:S8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
ws.getRange2( "S5" ).setValue( "#DIV/0!" );
ws.getRange2( "S6" ).setValue( "TRUE" );
ws.getRange2( "S7" ).setValue( "qwe" );
ws.getRange2( "S8" ).setValue( "" );
ws.getRange2( "S9" ).setValue( "-1" );
oParser = new parserFormula( "MAX(S5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#DIV/0!" );
oParser = new parserFormula( "MAX(S6)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "MAX(S7)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "MAX(S8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "MAX(S5:S9)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#DIV/0!" );
oParser = new parserFormula( "MAX(S6:S9)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -1 );
oParser = new parserFormula( "MAX(-1, TRUE)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
} );
test( "Test: \"MAXA\"", function () {
......@@ -812,6 +839,33 @@ $( function () {
oParser = new parserFormula( "MAXA(S5:S8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
ws.getRange2( "S5" ).setValue( "#DIV/0!" );
ws.getRange2( "S6" ).setValue( "TRUE" );
ws.getRange2( "S7" ).setValue( "qwe" );
ws.getRange2( "S8" ).setValue( "" );
ws.getRange2( "S9" ).setValue( "-1" );
oParser = new parserFormula( "MAXA(S5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#DIV/0!" );
oParser = new parserFormula( "MAXA(S6)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula( "MAXA(S7)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "MAXA(S8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "MAXA(S5:S9)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#DIV/0!" );
oParser = new parserFormula( "MAXA(S6:S9)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula( "MAXA(-1, TRUE)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
} );
test( "Test: \"MIN\"", function () {
......@@ -824,6 +878,33 @@ $( function () {
oParser = new parserFormula( "MIN(S5:S8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -1 / Math.fact( 2 ) );
ws.getRange2( "S5" ).setValue( "#DIV/0!" );
ws.getRange2( "S6" ).setValue( "TRUE" );
ws.getRange2( "S7" ).setValue( "qwe" );
ws.getRange2( "S8" ).setValue( "" );
ws.getRange2( "S9" ).setValue( "2" );
oParser = new parserFormula( "MIN(S5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#DIV/0!" );
oParser = new parserFormula( "MIN(S6)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "MIN(S7)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "MIN(S8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "MIN(S5:S9)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#DIV/0!" );
oParser = new parserFormula( "MIN(S6:S9)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
oParser = new parserFormula( "MIN(2, TRUE)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
} );
test( "Test: \"MINA\"", function () {
......@@ -836,6 +917,33 @@ $( function () {
oParser = new parserFormula( "MINA(S5:S8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -1 / Math.fact( 2 ) );
ws.getRange2( "S5" ).setValue( "#DIV/0!" );
ws.getRange2( "S6" ).setValue( "TRUE" );
ws.getRange2( "S7" ).setValue( "qwe" );
ws.getRange2( "S8" ).setValue( "" );
ws.getRange2( "S9" ).setValue( "2" );
oParser = new parserFormula( "MINA(S5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#DIV/0!" );
oParser = new parserFormula( "MINA(S6)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula( "MINA(S7)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "MINA(S8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "MINA(S5:S9)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#DIV/0!" );
oParser = new parserFormula( "MINA(S6:S9)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "MINA(2, TRUE)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
} );
test( "Test: SUM(S7:S9,{1,2,3})", function () {
......@@ -2051,7 +2159,29 @@ $( function () {
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
ws.getRange2( "S5" ).setValue( "#DIV/0!" );
ws.getRange2( "S6" ).setValue( "TRUE" );
ws.getRange2( "S7" ).setValue( "qwe" );
ws.getRange2( "S8" ).setValue( "" );
ws.getRange2( "S9" ).setValue( "2" );
oParser = new parserFormula( "COUNT(S5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "COUNT(S6)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "COUNT(S7)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "COUNT(S8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "COUNT(S5:S9)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula( "COUNT(S6:S9)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
} );
test( "Test: \"COUNTA\"", function () {
......@@ -2078,7 +2208,29 @@ $( function () {
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 2 );
ws.getRange2( "S5" ).setValue( "#DIV/0!" );
ws.getRange2( "S6" ).setValue( "TRUE" );
ws.getRange2( "S7" ).setValue( "qwe" );
ws.getRange2( "S8" ).setValue( "" );
ws.getRange2( "S9" ).setValue( "2" );
oParser = new parserFormula( "COUNTA(S5)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula( "COUNTA(S6)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula( "COUNTA(S7)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 );
oParser = new parserFormula( "COUNTA(S8)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 );
oParser = new parserFormula( "COUNTA(S5:S9)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4 );
oParser = new parserFormula( "COUNTA(S6:S9)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3 );
} );
test( "Test: \"COUNTIF\"", function () {
......
......@@ -2690,7 +2690,7 @@ cMAX.prototype.Calculate = function ( arg ) {
if ( argI instanceof cRef || argI instanceof cRef3D ) {
if ( argIVal instanceof cError )
return this.value = argIVal;
if ( argIVal instanceof cNumber || argIVal instanceof cBool || argIVal instanceof cEmpty ) {
if ( argIVal instanceof cNumber ) {
var v = argIVal.tocNumber();
if ( v.getValue() > max )
max = v.getValue();
......@@ -2699,7 +2699,7 @@ cMAX.prototype.Calculate = function ( arg ) {
else if ( argI instanceof cArea || argI instanceof cArea3D ) {
var argArr = argI.getValue();
for ( var j = 0; j < argArr.length; j++ ) {
if ( argArr[j] instanceof cNumber || argArr[j] instanceof cBool || argArr[j] instanceof cEmpty ) {
if ( argArr[j] instanceof cNumber ) {
var v = argArr[j].tocNumber();
if ( v.getValue() > max )
max = v.getValue();
......@@ -2742,7 +2742,7 @@ cMAX.prototype.Calculate = function ( arg ) {
max = argI.getValue();
}
}
return this.value = ( max.value === Number.NEGATIVE_INFINITY ? new cNumber( 0 ) : new cNumber( max ) );
return this.value = ( max === Number.NEGATIVE_INFINITY ? new cNumber( 0 ) : new cNumber( max ) );
};
cMAX.prototype.getInfo = function () {
return {
......@@ -2832,7 +2832,7 @@ cMAXA.prototype.Calculate = function ( arg ) {
max = argI.getValue();
}
}
return this.value = ( max.value === Number.NEGATIVE_INFINITY ? new cNumber( 0 ) : new cNumber( max ) )
return this.value = ( max === Number.NEGATIVE_INFINITY ? new cNumber( 0 ) : new cNumber( max ) )
};
cMAXA.prototype.getInfo = function () {
return {
......@@ -2954,7 +2954,7 @@ cMIN.prototype.Calculate = function ( arg ) {
if ( argI instanceof cRef || argI instanceof cRef3D ) {
if ( argIVal instanceof cError )
return this.value = argIVal;
if ( argIVal instanceof cNumber || argIVal instanceof cBool || argIVal instanceof cEmpty ) {
if ( argIVal instanceof cNumber ) {
var v = argIVal.tocNumber();
if ( v.getValue() < min )
min = v.getValue();
......@@ -2963,7 +2963,7 @@ cMIN.prototype.Calculate = function ( arg ) {
else if ( argI instanceof cArea || argI instanceof cArea3D ) {
var argArr = argI.getValue();
for ( var j = 0; j < argArr.length; j++ ) {
if ( argArr[j] instanceof cNumber || argArr[j] instanceof cBool || argArr[j] instanceof cEmpty ) {
if ( argArr[j] instanceof cNumber ) {
var v = argArr[j].tocNumber();
if ( v.getValue() < min )
min = v.getValue();
......@@ -3007,7 +3007,7 @@ cMIN.prototype.Calculate = function ( arg ) {
min = argI.getValue();
}
}
return this.value = ( min.value === Number.POSITIVE_INFINITY ? new cNumber( 0 ) : new cNumber( min ) );
return this.value = ( min === Number.POSITIVE_INFINITY ? new cNumber( 0 ) : new cNumber( min ) );
};
cMIN.prototype.getInfo = function () {
return {
......@@ -3099,7 +3099,7 @@ cMINA.prototype.Calculate = function ( arg ) {
min = argI.getValue();
}
}
return this.value = ( min.value === Number.POSITIVE_INFINITY ? new cNumber( 0 ) : new cNumber( min ) );
return this.value = ( min === Number.POSITIVE_INFINITY ? new cNumber( 0 ) : new cNumber( min ) );
};
cMINA.prototype.getInfo = function () {
return {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment