Commit b03f9a49 authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@50570 954022d7-b5bf-4e40-9824-e11837661b57
parent abec7f1c
$( function () { $( function () {
function toFixed( n ) { function toFixed( n ) {
return n.toFixed( cExcelSignificantDigits ) - 0; return n//.toFixed( cExcelSignificantDigits ) - 0;
}
function difBetween( a, b ) {
return Math.abs( a - b ) < dif
} }
var ver = 2; var ver = 2;
...@@ -46,96 +50,39 @@ ...@@ -46,96 +50,39 @@
strictEqual( oParser.calculate().getValue(), 6 ); strictEqual( oParser.calculate().getValue(), 6 );
} ) } )
test( "Test: \"1+3\"", function () { test( "Test: \"Arithmetical operations\"", function () {
oParser = new parserFormula( '1+3', "A1", ws ); oParser = new parserFormula( '1+3', "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 4 ); strictEqual( oParser.calculate().getValue(), 4 );
} )
test( "Test: \"(1+2)*4+3\"", function () {
oParser = new parserFormula( '(1+2)*4+3', "A1", ws ); oParser = new parserFormula( '(1+2)*4+3', "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), (1 + 2) * 4 + 3 ); strictEqual( oParser.calculate().getValue(), (1 + 2) * 4 + 3 );
} )
test( "Test: \"2^52\"", function () {
oParser = new parserFormula( '2^52', "A1", ws ); oParser = new parserFormula( '2^52', "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), Math.pow( 2, 52 ) ); strictEqual( oParser.calculate().getValue(), Math.pow( 2, 52 ) );
} )
test( "Test: \"-10\"", function () {
oParser = new parserFormula( '-10', "A1", ws ); oParser = new parserFormula( '-10', "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -10 ); strictEqual( oParser.calculate().getValue(), -10 );
} )
test( "Test: \"-10*2\"", function () {
oParser = new parserFormula( '-10*2', "A1", ws ); oParser = new parserFormula( '-10*2', "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -20 ); strictEqual( oParser.calculate().getValue(), -20 );
} )
test( "Test: \"-10+10\"", function () {
oParser = new parserFormula( '-10+10', "A1", ws ); oParser = new parserFormula( '-10+10', "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0 ); strictEqual( oParser.calculate().getValue(), 0 );
} )
test( "Test: \"12%\"", function () {
oParser = new parserFormula( '12%', "A1", ws ); oParser = new parserFormula( '12%', "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0.12 ); strictEqual( oParser.calculate().getValue(), 0.12 );
} )
test( "Test: \"SIN have wrong arguments count\"", function () {
oParser = new parserFormula( 'SIN(3.1415926,3.1415926*2)', "A1", ws );
ok( !oParser.parse() );
} )
test( "Test: \"sin(3.1415926)\"", function () {
oParser = new parserFormula( 'SIN(3.1415926)', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), parseFloat( Math.sin( 3.1415926 ).toFixed( 15 ) ) );
} )
test( "Test: \"COS(PI()/2)\"", function () {
oParser = new parserFormula( 'COS(PI()/2)', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), parseFloat( Math.cos( Math.PI / 2 ).toFixed( 15 ) ) );
} )
test( "Test: \"SUM(1,2,3)\"", function () {
oParser = new parserFormula( 'SUM(1,2,3)', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 + 2 + 3 );
} )
test( "Test: \"-\"12\"+2\"", function () {
oParser = new parserFormula( "-\"12\"+2", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -10 );
} )
test( "Test: \"-TRUE\"", function () {
oParser = new parserFormula( "-TRUE", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -1 );
} )
test( "Test: \"\"s\"&5\"", function () {
oParser = new parserFormula( "\"s\"&5", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "s5" );
} )
test( "Test: \"2<>\"3\"\"", function () {
oParser = new parserFormula( "2<>\"3\"", "A1", ws ); oParser = new parserFormula( "2<>\"3\"", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "TRUE", "2<>\"3\"" ) strictEqual( oParser.calculate().getValue(), "TRUE", "2<>\"3\"" )
} )
test( "Test: \"2=\"3\"\" & \"2>\"3\"\"", function () {
oParser = new parserFormula( "2=\"3\"", "A1", ws ); oParser = new parserFormula( "2=\"3\"", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "FALSE", "2=\"3\"" ); strictEqual( oParser.calculate().getValue(), "FALSE", "2=\"3\"" );
...@@ -143,9 +90,7 @@ ...@@ -143,9 +90,7 @@
oParser = new parserFormula( "2>\"3\"", "A1", ws ); oParser = new parserFormula( "2>\"3\"", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "FALSE", "2>\"3\"" ); strictEqual( oParser.calculate().getValue(), "FALSE", "2>\"3\"" );
} )
test( "Test: \"\"f\">\"3\"\" & \"\"f\">\"3\"\"", function () {
oParser = new parserFormula( "\"f\">\"3\"", "A1", ws ); oParser = new parserFormula( "\"f\">\"3\"", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "TRUE" ); strictEqual( oParser.calculate().getValue(), "TRUE" );
...@@ -153,24 +98,51 @@ ...@@ -153,24 +98,51 @@
oParser = new parserFormula( "\"f\"<\"3\"", "A1", ws ); oParser = new parserFormula( "\"f\"<\"3\"", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( "FALSE", oParser.calculate().getValue(), "FALSE" ); strictEqual( "FALSE", oParser.calculate().getValue(), "FALSE" );
} )
test( "Test: \"FALSE>=FALSE\"", function () {
oParser = new parserFormula( "FALSE>=FALSE", "A1", ws ); oParser = new parserFormula( "FALSE>=FALSE", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "TRUE" ); strictEqual( oParser.calculate().getValue(), "TRUE" );
} )
test( "Test: \"\"TRUE\"&\"TRUE\"\"", function () {
oParser = new parserFormula( "\"TRUE\"&\"TRUE\"", "A1", ws ); oParser = new parserFormula( "\"TRUE\"&\"TRUE\"", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "TRUETRUE" ); strictEqual( oParser.calculate().getValue(), "TRUETRUE" );
} )
test( "Test: \"10*\"\"\"", function () {
oParser = new parserFormula( "10*\"\"", "A1", ws ); oParser = new parserFormula( "10*\"\"", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "#VALUE!" ); strictEqual( oParser.calculate().getValue(), "#VALUE!" );
oParser = new parserFormula( "-TRUE", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -1 );
} )
test( "Test: \"SIN have wrong arguments count\"", function () {
oParser = new parserFormula( 'SIN(3.1415926,3.1415926*2)', "A1", ws );
ok( !oParser.parse() );
} )
test( "Test: \"SIN(3.1415926)\"", function () {
oParser = new parserFormula( 'SIN(3.1415926)', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), Math.sin( 3.1415926 ) );
} )
test( "Test: \"COS(PI()/2)\"", function () {
oParser = new parserFormula( 'COS(PI()/2)', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), Math.cos( Math.PI / 2 ) );
} )
test( "Test: \"SUM(1,2,3)\"", function () {
oParser = new parserFormula( 'SUM(1,2,3)', "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 + 2 + 3 );
} )
test( "Test: \"\"s\"&5\"", function () {
oParser = new parserFormula( "\"s\"&5", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "s5" );
} ) } )
test( "Test: \"String+Number\"", function () { test( "Test: \"String+Number\"", function () {
...@@ -259,22 +231,38 @@ ...@@ -259,22 +231,38 @@
strictEqual( oParser.calculate().getValue(), 3 ); strictEqual( oParser.calculate().getValue(), 3 );
} ) } )
test( "Test: \"MROUND(10;3)\"", function () { test( "Test: \"MROUND\"", function () {
var multiple;//должен равняться значению второго аргумента
function mroundHelper( num ) {
var multiplier = Math.pow( 10, Math.floor( Math.log( Math.abs( num ) ) / Math.log( 10 ) ) - cExcelSignificantDigits + 1 );
var nolpiat = 0.5 * (num > 0 ? 1 : num < 0 ? -1 : 0) * multiplier;
var y = (num + nolpiat) / multiplier;
y = y / Math.abs( y ) * Math.floor( Math.abs( y ) )
var x = y * multiplier / multiple
// var x = number / multiple;
var nolpiat = 5 * (x / Math.abs( x )) * Math.pow( 10, Math.floor( Math.log( Math.abs( x ) ) / Math.log( 10 ) ) - cExcelSignificantDigits );
x = x + nolpiat;
x = x | x;
return x * multiple;
}
oParser = new parserFormula( "MROUND(10;3)", "A1", ws ); oParser = new parserFormula( "MROUND(10;3)", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 9 ); multiple = 3;
} ) strictEqual( oParser.calculate().getValue(), mroundHelper( 10 + 3 / 2 ) );
test( "Test: \"MROUND(-10;-3)\"", function () {
oParser = new parserFormula( "MROUND(-10;-3)", "A1", ws ); oParser = new parserFormula( "MROUND(-10;-3)", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -9 ); multiple = -3;
} ) strictEqual( oParser.calculate().getValue(), mroundHelper( -10 + -3 / 2 ) );
test( "Test: \"MROUND(1.3;0.2)\"", function () {
oParser = new parserFormula( "MROUND(1.3;0.2)", "A1", ws ); oParser = new parserFormula( "MROUND(1.3;0.2)", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1.4 ); multiple = 0.2;
strictEqual( oParser.calculate().getValue(), mroundHelper( 1.3 + 0.2 / 2 ) );
} ) } )
test( "Test: \"T(\"HELLO\")\"", function () { test( "Test: \"T(\"HELLO\")\"", function () {
...@@ -328,7 +316,7 @@ ...@@ -328,7 +316,7 @@
test( "Test: MONTH #3", function () { test( "Test: MONTH #3", function () {
oParser = new parserFormula( "MONTH(NOW())", "A1", ws ); oParser = new parserFormula( "MONTH(NOW())", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), new Date().getUTCMonth()+1 ); strictEqual( oParser.calculate().getValue(), new Date().getUTCMonth() + 1 );
} ) } )
test( "Test: \"10-3\"", function () { test( "Test: \"10-3\"", function () {
...@@ -597,7 +585,7 @@ ...@@ -597,7 +585,7 @@
oParser = new parserFormula( "DOLLAR(-1234.567,4)", "A2", ws ); oParser = new parserFormula( "DOLLAR(-1234.567,4)", "A2", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), "$-1,234.5670" ); strictEqual( oParser.calculate().getValue(), "($1,234.5670)" );
} ) } )
...@@ -625,7 +613,7 @@ ...@@ -625,7 +613,7 @@
oParser = new parserFormula( "VALUE(\"16:48:00\")-VALUE(\"12:17:12\")", "A2", ws ); oParser = new parserFormula( "VALUE(\"16:48:00\")-VALUE(\"12:17:12\")", "A2", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0.188055555555556 ); strictEqual( oParser.calculate().getValue(), g_oFormatParser.parse( "16:48:00" ).value - g_oFormatParser.parse( "12:17:12" ).value );
} ) } )
...@@ -759,13 +747,23 @@ ...@@ -759,13 +747,23 @@
test( "Test: \"PV\"", function () { test( "Test: \"PV\"", function () {
function pv( rate, nper, pmt, fv, type ) {
if ( rate != 0 ) {
return -1 * ( fv + pmt * (1 + rate * type) * ( (Math.pow( (1 + rate), nper ) - 1) / rate ) ) / Math.pow( 1 + rate, nper )
}
else {
return -1 * ( fv + pmt * nper );
}
}
oParser = new parserFormula( "PV(0.08/12,12*20,500,,0)", "A2", ws ); oParser = new parserFormula( "PV(0.08/12,12*20,500,,0)", "A2", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -59777.14585118638 ); strictEqual( oParser.calculate().getValue(), pv( 0.08 / 12, 12 * 20, 500, 0, 0 ) );
oParser = new parserFormula( "PV(0,12*20,500,,0)", "A2", ws ); oParser = new parserFormula( "PV(0,12*20,500,,0)", "A2", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -120000 ); strictEqual( oParser.calculate().getValue(), pv( 0, 12 * 20, 500, 0, 0 ) );
} ) } )
...@@ -1185,7 +1183,7 @@ ...@@ -1185,7 +1183,7 @@
oParser = new parserFormula( "SINH(1)", "A2", ws ); oParser = new parserFormula( "SINH(1)", "A2", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), ((Math.E - 1 / Math.E) / 2).toFixed( cExcelSignificantDigits ) - 0 ); strictEqual( oParser.calculate().getValue(), ((Math.E - 1 / Math.E) / 2) );
} ) } )
test( "Test: \"COSH\"", function () { test( "Test: \"COSH\"", function () {
...@@ -1196,7 +1194,7 @@ ...@@ -1196,7 +1194,7 @@
oParser = new parserFormula( "COSH(1)", "A2", ws ); oParser = new parserFormula( "COSH(1)", "A2", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), ((Math.E + 1 / Math.E) / 2).toFixed( cExcelSignificantDigits ) - 0 ); strictEqual( oParser.calculate().getValue(), ((Math.E + 1 / Math.E) / 2) );
} ) } )
test( "Test: \"TANH\"", function () { test( "Test: \"TANH\"", function () {
...@@ -1207,7 +1205,7 @@ ...@@ -1207,7 +1205,7 @@
oParser = new parserFormula( "TANH(1)", "A2", ws ); oParser = new parserFormula( "TANH(1)", "A2", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), ((Math.E * Math.E - 1) / (Math.E * Math.E + 1)).toFixed( cExcelSignificantDigits ) - 0 ); strictEqual( difBetween( oParser.calculate().getValue(), ((Math.E * Math.E - 1) / (Math.E * Math.E + 1)) ), true );
} ) } )
test( "Test: \"COMBIN\"", function () { test( "Test: \"COMBIN\"", function () {
...@@ -1496,7 +1494,7 @@ ...@@ -1496,7 +1494,7 @@
oParser = new parserFormula( "AVEDEV(-3.5,1.4,6.9,-4.5,-0.3)", "A1", ws ); oParser = new parserFormula( "AVEDEV(-3.5,1.4,6.9,-4.5,-0.3)", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3.32 ); strictEqual( difBetween( oParser.calculate().getValue(), 3.32 ), true );
} ) } )
...@@ -1584,11 +1582,11 @@ ...@@ -1584,11 +1582,11 @@
oParser = new parserFormula( "CONFIDENCE(0.4,5,12)", "A1", ws ); oParser = new parserFormula( "CONFIDENCE(0.4,5,12)", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1.214775614397568 ); strictEqual( difBetween( oParser.calculate().getValue(), 1.214775614397568 ), true );
oParser = new parserFormula( "CONFIDENCE(0.75,9,7)", "A1", ws ); oParser = new parserFormula( "CONFIDENCE(0.75,9,7)", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1.083909233527114 ); strictEqual( difBetween( oParser.calculate().getValue(), 1.083909233527114 ), true );
} ) } )
...@@ -1596,11 +1594,11 @@ ...@@ -1596,11 +1594,11 @@
oParser = new parserFormula( "CORREL({2.532,5.621;2.1,3.4},{5.32,2.765;5.2,\"f\"})", "A1", ws ); oParser = new parserFormula( "CORREL({2.532,5.621;2.1,3.4},{5.32,2.765;5.2,\"f\"})", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -0.988112020032211 ); strictEqual( difBetween( oParser.calculate().getValue(), -0.988112020032211 ), true );
oParser = new parserFormula( "CORREL({1;2;3},{4;5;\"E\"})", "A1", ws ); oParser = new parserFormula( "CORREL({1;2;3},{4;5;\"E\"})", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1 ); strictEqual( difBetween( oParser.calculate().getValue(), 1 ), true );
oParser = new parserFormula( "CORREL({1,2},{1,\"e\"})", "A1", ws ); oParser = new parserFormula( "CORREL({1,2},{1,\"e\"})", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
...@@ -1705,11 +1703,11 @@ ...@@ -1705,11 +1703,11 @@
oParser = new parserFormula( "COVAR({2.532,5.621;2.1,3.4},{5.32,2.765;5.2,6.7})", "A1", ws ); oParser = new parserFormula( "COVAR({2.532,5.621;2.1,3.4},{5.32,2.765;5.2,6.7})", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), -1.3753740625 ); strictEqual( difBetween( oParser.calculate().getValue(), -1.3753740625 ), true );
oParser = new parserFormula( "COVAR({1,2};{4,5})", "B1", ws ); oParser = new parserFormula( "COVAR({1,2};{4,5})", "B1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0.25 ); strictEqual( difBetween( oParser.calculate().getValue(), 0.25 ), true );
} ) } )
...@@ -1755,19 +1753,19 @@ ...@@ -1755,19 +1753,19 @@
oParser = new parserFormula( "DEVSQ(5.6,8.2,9.2)", "A1", ws ); oParser = new parserFormula( "DEVSQ(5.6,8.2,9.2)", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 6.906666666666665 ); strictEqual( difBetween( oParser.calculate().getValue(), 6.906666666666665 ), true );
oParser = new parserFormula( "DEVSQ({5.6,8.2,9.2})", "A1", ws ); oParser = new parserFormula( "DEVSQ({5.6,8.2,9.2})", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 6.906666666666665 ); strictEqual( difBetween( oParser.calculate().getValue(), 6.906666666666665 ), true );
oParser = new parserFormula( "DEVSQ(5.6,8.2,\"9.2\")", "A1", ws ); oParser = new parserFormula( "DEVSQ(5.6,8.2,\"9.2\")", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 3.379999999999999 ); strictEqual( difBetween( oParser.calculate().getValue(), 3.379999999999999 ), true );
oParser = new parserFormula( "DEVSQ(Лист2!A1:A3)", "A1", ws ); oParser = new parserFormula( "DEVSQ(Лист2!A1:A3)", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 6.906666666666665 ); strictEqual( difBetween( oParser.calculate().getValue(), 6.906666666666665 ), true );
} ) } )
...@@ -1775,11 +1773,11 @@ ...@@ -1775,11 +1773,11 @@
oParser = new parserFormula( "EXPONDIST(0.2,10,FALSE)", "A1", ws ); oParser = new parserFormula( "EXPONDIST(0.2,10,FALSE)", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 1.353352832366127 ); strictEqual( difBetween( oParser.calculate().getValue(), 1.353352832366127 ), true );
oParser = new parserFormula( "EXPONDIST(2.3,1.5,TRUE)", "A1", ws ); oParser = new parserFormula( "EXPONDIST(2.3,1.5,TRUE)", "A1", ws );
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 0.968254363621932 ); strictEqual( difBetween( oParser.calculate().getValue(), 0.968254363621932 ), true );
} ) } )
...@@ -2148,7 +2146,7 @@ ...@@ -2148,7 +2146,7 @@
test( "Test: \"NORMDIST\"", function () { test( "Test: \"NORMDIST\"", function () {
function normdist( x, mue, sigma, kum ) { function normdist( x, mue, sigma, kum ) {
if ( sigma <= 0 || x < 0 || x > 1 ) if ( sigma <= 0 )
return "#NUM!"; return "#NUM!";
else if ( kum == false ) else if ( kum == false )
return toFixed( phi( (x - mue) / sigma ) / sigma ); return toFixed( phi( (x - mue) / sigma ) / sigma );
...@@ -2169,6 +2167,10 @@ ...@@ -2169,6 +2167,10 @@
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), normdist( 42, 40, -1.5, true ) ); strictEqual( oParser.calculate().getValue(), normdist( 42, 40, -1.5, true ) );
oParser = new parserFormula( "NORMDIST(1,40,-1.5,TRUE)", "A1", ws );
ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), normdist( 1, 40, -1.5, true ) );
} ) } )
test( "Test: \"NORMSDIST\"", function () { test( "Test: \"NORMSDIST\"", function () {
...@@ -2747,7 +2749,7 @@ ...@@ -2747,7 +2749,7 @@
for ( var i = 0; i < arguments.length; i++ ) { for ( var i = 0; i < arguments.length; i++ ) {
res += (arguments[i] - average) * (arguments[i] - average); res += (arguments[i] - average) * (arguments[i] - average);
} }
return toFixed(Math.sqrt( res / (arguments.length - 1) )); return toFixed( Math.sqrt( res / (arguments.length - 1) ) );
} }
oParser = new parserFormula( "STDEV(123,134,143,173,112,109)", "A2", ws ); oParser = new parserFormula( "STDEV(123,134,143,173,112,109)", "A2", ws );
...@@ -2777,7 +2779,6 @@ ...@@ -2777,7 +2779,6 @@
ws.getRange2( "E405" ).setValue( "109" ); ws.getRange2( "E405" ).setValue( "109" );
function stdeva() { function stdeva() {
var average = 0, res = 0; var average = 0, res = 0;
for ( var i = 0; i < arguments.length; i++ ) { for ( var i = 0; i < arguments.length; i++ ) {
...@@ -2787,7 +2788,7 @@ ...@@ -2787,7 +2788,7 @@
for ( var i = 0; i < arguments.length; i++ ) { for ( var i = 0; i < arguments.length; i++ ) {
res += (arguments[i] - average) * (arguments[i] - average); res += (arguments[i] - average) * (arguments[i] - average);
} }
return toFixed(Math.sqrt( res / (arguments.length - 1) ) ); return toFixed( Math.sqrt( res / (arguments.length - 1) ) );
} }
oParser = new parserFormula( "STDEVA(123,134,143,173,112,109)", "A2", ws ); oParser = new parserFormula( "STDEVA(123,134,143,173,112,109)", "A2", ws );
......
...@@ -6,33 +6,33 @@ ...@@ -6,33 +6,33 @@
* To change this template use File | Settings | File Templates. * To change this template use File | Settings | File Templates.
*/ */
cFormulaFunction.Cube = { cFormulaFunction.Cube = {
'groupName' : "Cube", 'groupName':"Cube",
'CUBEKPIMEMBER' : function(){ 'CUBEKPIMEMBER':function () {
var r = new cBaseFunction("CUBEKPIMEMBER"); var r = new cBaseFunction( "CUBEKPIMEMBER" );
return r; return r;
}, },
'CUBEMEMBER' : function(){ 'CUBEMEMBER':function () {
var r = new cBaseFunction("CUBEMEMBER"); var r = new cBaseFunction( "CUBEMEMBER" );
return r; return r;
}, },
'CUBEMEMBERPROPERTY' : function(){ 'CUBEMEMBERPROPERTY':function () {
var r = new cBaseFunction("CUBEMEMBERPROPERTY"); var r = new cBaseFunction( "CUBEMEMBERPROPERTY" );
return r; return r;
}, },
'CUBERANKEDMEMBER' : function(){ 'CUBERANKEDMEMBER':function () {
var r = new cBaseFunction("CUBERANKEDMEMBER"); var r = new cBaseFunction( "CUBERANKEDMEMBER" );
return r; return r;
}, },
'CUBESET' : function(){ 'CUBESET':function () {
var r = new cBaseFunction("CUBESET"); var r = new cBaseFunction( "CUBESET" );
return r; return r;
}, },
'CUBESETCOUNT' : function(){ 'CUBESETCOUNT':function () {
var r = new cBaseFunction("CUBESETCOUNT"); var r = new cBaseFunction( "CUBESETCOUNT" );
return r; return r;
}, },
'CUBEVALUE' : function(){ 'CUBEVALUE':function () {
var r = new cBaseFunction("CUBEVALUE"); var r = new cBaseFunction( "CUBEVALUE" );
return r; return r;
} }
} }
\ No newline at end of file
...@@ -6,53 +6,53 @@ ...@@ -6,53 +6,53 @@
* To change this template use File | Settings | File Templates. * To change this template use File | Settings | File Templates.
*/ */
cFormulaFunction.Database = { cFormulaFunction.Database = {
'groupName' : "Database", 'groupName':"Database",
'DAVERAGE' : function(){ 'DAVERAGE':function () {
var r = new cBaseFunction("DAVERAGE"); var r = new cBaseFunction( "DAVERAGE" );
return r; return r;
}, },
'DCOUNT' : function(){ 'DCOUNT':function () {
var r = new cBaseFunction("DCOUNT"); var r = new cBaseFunction( "DCOUNT" );
return r; return r;
}, },
'DCOUNTA' : function(){ 'DCOUNTA':function () {
var r = new cBaseFunction("DCOUNTA"); var r = new cBaseFunction( "DCOUNTA" );
return r; return r;
}, },
'DGET' : function(){ 'DGET':function () {
var r = new cBaseFunction("DGET"); var r = new cBaseFunction( "DGET" );
return r; return r;
}, },
'DMAX' : function(){ 'DMAX':function () {
var r = new cBaseFunction("DMAX"); var r = new cBaseFunction( "DMAX" );
return r; return r;
}, },
'DMIN' : function(){ 'DMIN':function () {
var r = new cBaseFunction("DMIN"); var r = new cBaseFunction( "DMIN" );
return r; return r;
}, },
'DPRODUCT' : function(){ 'DPRODUCT':function () {
var r = new cBaseFunction("DPRODUCT"); var r = new cBaseFunction( "DPRODUCT" );
return r; return r;
}, },
'DSTDEV' : function(){ 'DSTDEV':function () {
var r = new cBaseFunction("DSTDEV"); var r = new cBaseFunction( "DSTDEV" );
return r; return r;
}, },
'DSTDEVP' : function(){ 'DSTDEVP':function () {
var r = new cBaseFunction("DSTDEVP"); var r = new cBaseFunction( "DSTDEVP" );
return r; return r;
}, },
'DSUM' : function(){ 'DSUM':function () {
var r = new cBaseFunction("DSUM"); var r = new cBaseFunction( "DSUM" );
return r; return r;
}, },
'DVAR' : function(){ 'DVAR':function () {
var r = new cBaseFunction("DVAR"); var r = new cBaseFunction( "DVAR" );
return r; return r;
}, },
'DVARP' : function(){ 'DVARP':function () {
var r = new cBaseFunction("DVARP"); var r = new cBaseFunction( "DVARP" );
return r; return r;
} }
} }
...@@ -283,18 +283,18 @@ cFormulaFunction.Statistical = { ...@@ -283,18 +283,18 @@ cFormulaFunction.Statistical = {
} }
valueForSearching = parseNum( search ) ? new cNumber( search ) : new cString( search ); valueForSearching = parseNum( search ) ? new cNumber( search ) : new cString( search );
if ( arg0 instanceof cArea ) { if ( arg0 instanceof cArea ) {
val = arg0.getValue(); var r = arg0.getRange().first.getRow0(), ws = arg0.getWS(), c1 = arg2.getRange().first.getCol0(), i = 0;
for ( var i = 0; i < val.length; i++ ) { arg0.foreach2(function(c){
if ( matching( val[i], valueForSearching, oper ) ) { if ( matching( c, valueForSearching, oper ) ) {
var r = arg0.getRange(), ws = arg0.getWS(), var r1 = r + i,
r1 = r.first.getRow0() + i, c1 = arg2.getRange().first.getCol0(); r2 = new cRef( ws.getRange3( r1, c1, r1, c1 ).getName(), ws );
r = new cRef( ws.getRange3( r1, c1, r1, c1 ).getName(), ws ); if ( r2.getValue() instanceof cNumber ) {
if ( r.getValue() instanceof cNumber ) { _sum += r2.getValue().getValue();
_sum += r.getValue().getValue();
_count++; _count++;
} }
} }
} i++;
})
} }
else { else {
val = arg0.getValue(); val = arg0.getValue();
...@@ -742,13 +742,8 @@ cFormulaFunction.Statistical = { ...@@ -742,13 +742,8 @@ cFormulaFunction.Statistical = {
valueForSearching = parseNum( search ) ? new cNumber( search ) : new cString( search ); valueForSearching = parseNum( search ) ? new cNumber( search ) : new cString( search );
if ( arg0 instanceof cArea ) { if ( arg0 instanceof cArea ) {
arg0.foreach2(function(_val){ arg0.foreach2(function(_val){
// _val
_count += matching( _val, valueForSearching, oper ); _count += matching( _val, valueForSearching, oper );
}) })
/*val = arg0.getValue();
for ( var i = 0; i < val.length; i++ ) {
_count += matching( val[i], valueForSearching, oper );
}*/
} }
else if ( arg0 instanceof cArea3D ) { else if ( arg0 instanceof cArea3D ) {
val = arg0.getValue(); val = arg0.getValue();
......
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