Skip to content
Permalink
Browse files

expressions array_majority/minority renamed parameter first to any

  • Loading branch information
domi4484 committed Feb 17, 2021
1 parent 76f09fd commit 5a9782de29932b2d97836a0855f86466c722992f
@@ -5,12 +5,12 @@
"description": "Returns the most common values in an array.",
"arguments": [
{"arg":"array","description":"an array"},
{"arg":"option='all'", "optional":true, "description":"a string specifying the return values handling. Valid options are:<br /><ul><li>all: Default, all most common values are returned in an array.</li><li>first: Returns the first of the most common values.</li><li>median: Returns the median of the most common values. Non arithmetic values are ignored.</li><li>real_majority: Returns the value which occurs more than half the size of the array.</li></ul>"}
{"arg":"option='all'", "optional":true, "description":"a string specifying the return values handling. Valid options are:<br /><ul><li>all: Default, all most common values are returned in an array.</li><li>any: Returns one of the most common values.</li><li>median: Returns the median of the most common values. Non arithmetic values are ignored.</li><li>real_majority: Returns the value which occurs more than half the size of the array.</li></ul>"}
],
"examples": [
{ "expression":"array_majority(array(0,1,42,42,43), 'all')", "returns":"[ 42 ]"},
{ "expression":"array_majority(array(0,1,42,42,43,1), 'all')", "returns":"[ 42, 1 ]"},
{ "expression":"array_majority(array(0,1,42,42,43,1), 'first')", "returns":"42"},
{ "expression":"array_majority(array(0,1,42,42,43,1), 'any')", "returns":"1 or 42"},
{ "expression":"array_majority(array(0,1,1,2,2), 'median')", "returns":"1.5"},
{ "expression":"array_majority(array(0,1,42,42,43), 'real_majority')", "returns":"NULL"},
{ "expression":"array_majority(array(0,1,42,42,43,42), 'real_majority')", "returns":"NULL"},
@@ -5,12 +5,12 @@
"description": "Returns the less common values in an array.",
"arguments": [
{"arg":"array","description":"an array"},
{"arg":"option='all'", "optional":true, "description":"a string specifying the return values handling. Valid options are:<br /><ul><li>all: Default, all less common values are returned in an array.</li><li>first: Returns the first of the less common values.</li><li>median: Returns the median of the less common values. Non arithmetic values are ignored.</li><li>real_minority: Returns values which occur less than half the size of the array.</li></ul>"}
{"arg":"option='all'", "optional":true, "description":"a string specifying the return values handling. Valid options are:<br /><ul><li>all: Default, all less common values are returned in an array.</li><li>any: Returns one of the less common values.</li><li>median: Returns the median of the less common values. Non arithmetic values are ignored.</li><li>real_minority: Returns values which occur less than half the size of the array.</li></ul>"}
],
"examples": [
{ "expression":"array_minority(array(0,42,42), 'all')", "returns":"[ 0 ]"},
{ "expression":"array_minority(array(0,1,42,42), 'all')", "returns":"[ 0, 1 ]"},
{ "expression":"array_minority(array(0,1,42,42,43,1), 'first')", "returns":"43"},
{ "expression":"array_minority(array(0,1,42,42,43,1), 'any')", "returns":"0 or 43"},
{ "expression":"array_minority(array(1,2,3,3), 'median')", "returns":"1.5"},
{ "expression":"array_minority(array(0,1,42,42,43), 'real_minority')", "returns":"[ 42, 43, 0, 1 ]"},
{ "expression":"array_minority(array(0,1,42,42,43,42), 'real_minority')", "returns":"[ 42, 43, 0, 1 ]"},
@@ -5457,7 +5457,7 @@ static QVariant fcnArrayMajority( const QVariantList &values, const QgsExpressio
{
return convertToSameType( hash.keys( maxValue ), values.at( 0 ).type() );
}
else if ( option.compare( QLatin1String( "first" ), Qt::CaseInsensitive ) == 0 )
else if ( option.compare( QLatin1String( "any" ), Qt::CaseInsensitive ) == 0 )
{
if ( hash.isEmpty() )
return QVariant();
@@ -5498,7 +5498,7 @@ static QVariant fcnArrayMinority( const QVariantList &values, const QgsExpressio
{
return convertToSameType( hash.keys( minValue ), values.at( 0 ).type() );
}
else if ( option.compare( QLatin1String( "first" ), Qt::CaseInsensitive ) == 0 )
else if ( option.compare( QLatin1String( "any" ), Qt::CaseInsensitive ) == 0 )
{
if ( hash.isEmpty() )
return QVariant();
@@ -1667,7 +1667,7 @@ class TestQgsExpression: public QObject
QTest::newRow( "array_majority(array(0,1,42,42,43), 'all')" ) << QStringLiteral( "array_majority(array(0,1,42,42,43), 'all')" ) << false << QVariant( QVariantList() << 42 );
QTest::newRow( "array_majority(array(0,1,43,'a','a','b'), 'all')" ) << QStringLiteral( "array_majority(array(0,1,43,'a','a','b'), 'all')" ) << false << QVariant( QVariantList() << "a" );
QTest::newRow( "array_majority(array(0,1,42,42,43,1)" ) << QStringLiteral( "array_sort(array_majority(array(0,1,42,42,43,1)))" ) << false << QVariant( QVariantList() << 1 << 42 );
QTest::newRow( "array_majority(array(0,1,42,42,43), 'first')" ) << QStringLiteral( "array_majority(array(0,1,42,42,43), 'first')" ) << false << QVariant( 42 );
QTest::newRow( "array_majority(array(0,1,42,42,43), 'any')" ) << QStringLiteral( "array_majority(array(0,1,42,42,43), 'any')" ) << false << QVariant( 42 );
QTest::newRow( "array_majority(array(0,1,1,2,2,42), 'median')" ) << QStringLiteral( "array_majority(array(0,1,1,2,2,42), 'median')" ) << false << QVariant( 1.5 );
QTest::newRow( "array_majority(array(0,1,1,2,2,42,'a','b'), 'median')" ) << QStringLiteral( "array_majority(array(0,1,1,2,2,42,'a','b'), 'median')" ) << false << QVariant( 1.5 );
QTest::newRow( "array_majority(array(0,1,2,42,'a','b','a'), 'median')" ) << QStringLiteral( "array_majority(array(0,1,2,42,'a','b','a'), 'median')" ) << false << QVariant();
@@ -1680,7 +1680,7 @@ class TestQgsExpression: public QObject
QTest::newRow( "array_minority(array(0,42,42), 'all')" ) << QStringLiteral( "array_minority(array(0,42,42), 'all')" ) << false << QVariant( QVariantList() << 0 );
QTest::newRow( "array_minority(array(42,42,'a'), 'all')" ) << QStringLiteral( "array_minority(array(42,42,'a'), 'all')" ) << false << QVariant( QVariantList() << "a" );
QTest::newRow( "array_minority(array(0,1,42,42))" ) << QStringLiteral( "array_sort(array_minority(array(0,1,42,42)))" ) << false << QVariant( QVariantList() << 0 << 1 );
QTest::newRow( "array_minority(array(0,42,42), 'first')" ) << QStringLiteral( "array_minority(array(0,42,42), 'first')" ) << false << QVariant( 0 );
QTest::newRow( "array_minority(array(0,42,42), 'any')" ) << QStringLiteral( "array_minority(array(0,42,42), 'any')" ) << false << QVariant( 0 );
QTest::newRow( "array_minority(array(1,2,3,3), 'median')" ) << QStringLiteral( "array_minority(array(1,2,3,3), 'median')" ) << false << QVariant( 1.5 );
QTest::newRow( "array_minority(array(1,2,3,3,'a'), 'median')" ) << QStringLiteral( "array_minority(array(1,2,3,3,'a'), 'median')" ) << false << QVariant( 1.5 );
QTest::newRow( "array_minority(array(1,1,3,3,'a'), 'median')" ) << QStringLiteral( "array_minority(array(1,1,3,3,'a'), 'median')" ) << false << QVariant();

0 comments on commit 5a9782d

Please sign in to comment.