Skip to content
Permalink
Browse files

Avoid ambiguous test data, force minimum of 1 decimal place for scien…

…tific notation format to avoid undefined results
  • Loading branch information
nyalldawson committed Jan 6, 2020
1 parent e91f26d commit ec3763521adcc0dac4fa05c5e6765e4be2b0bb5b
@@ -54,9 +54,9 @@ Returns the maximum number of decimal places to show.
.. seealso:: :py:func:`showTrailingZeros`
%End

void setNumberDecimalPlaces( int numberDecimalPlaces );
virtual void setNumberDecimalPlaces( int places );
%Docstring
Sets the maximum number of decimal places to show.
Sets the maximum number of decimal ``places`` to show.

.. seealso:: :py:func:`numberDecimalPlaces`

@@ -70,7 +70,7 @@ Returns ``True`` if the thousands grouping separator will be shown.
.. seealso:: :py:func:`setShowThousandsSeparator`
%End

void setShowThousandsSeparator( bool showThousandsSeparator );
void setShowThousandsSeparator( bool show );
%Docstring
Sets whether the thousands grouping separator will be shown.

@@ -84,7 +84,7 @@ Returns ``True`` if a leading plus sign will be shown for positive values.
.. seealso:: :py:func:`setShowPlusSign`
%End

void setShowPlusSign( bool showPlusSign );
void setShowPlusSign( bool show );
%Docstring
Sets whether a leading plus sign will be shown for positive values.

@@ -101,7 +101,7 @@ numberDecimalPlaces()).
.. seealso:: :py:func:`numberDecimalPlaces`
%End

void setShowTrailingZeros( bool showTrailingZeros );
void setShowTrailingZeros( bool show );
%Docstring
Sets whether trailing zeros will be shown (up to the specified
numberDecimalPlaces()).
@@ -40,6 +40,18 @@ QgsScientificNumericFormat cannot be copied
virtual QVariantMap configuration() const;


virtual void setNumberDecimalPlaces( int places );

%Docstring
Sets the maximum number of decimal ``places`` to show.

The ``places`` argument must be at least 1.

.. seealso:: :py:func:`numberDecimalPlaces`

.. seealso:: :py:func:`setShowTrailingZeros`
%End

private:
QgsScientificNumericFormat( const QgsScientificNumericFormat &other );
};
@@ -62,12 +62,12 @@ class CORE_EXPORT QgsBasicNumericFormat : public QgsNumericFormat
int numberDecimalPlaces() const;

/**
* Sets the maximum number of decimal places to show.
* Sets the maximum number of decimal \a places to show.
*
* \see numberDecimalPlaces()
* \see setShowTrailingZeros()
*/
void setNumberDecimalPlaces( int numberDecimalPlaces );
virtual void setNumberDecimalPlaces( int places );

/**
* Returns TRUE if the thousands grouping separator will be shown.
@@ -79,7 +79,7 @@ class CORE_EXPORT QgsBasicNumericFormat : public QgsNumericFormat
* Sets whether the thousands grouping separator will be shown.
* \see showThousandsSeparator()
*/
void setShowThousandsSeparator( bool showThousandsSeparator );
void setShowThousandsSeparator( bool show );

/**
* Returns TRUE if a leading plus sign will be shown for positive values.
@@ -91,7 +91,7 @@ class CORE_EXPORT QgsBasicNumericFormat : public QgsNumericFormat
* Sets whether a leading plus sign will be shown for positive values.
* \see showPlusSign()
*/
void setShowPlusSign( bool showPlusSign );
void setShowPlusSign( bool show );

/**
* Returns TRUE if trailing zeros will be shown (up to the specified
@@ -109,7 +109,7 @@ class CORE_EXPORT QgsBasicNumericFormat : public QgsNumericFormat
* \see showTrailingZeros()
* \see setNumberDecimalPlaces()
*/
void setShowTrailingZeros( bool showTrailingZeros );
void setShowTrailingZeros( bool show );

protected:

@@ -50,3 +50,8 @@ QVariantMap QgsScientificNumericFormat::configuration() const
QVariantMap res = QgsBasicNumericFormat::configuration();
return res;
}

void QgsScientificNumericFormat::setNumberDecimalPlaces( int numberDecimalPlaces )
{
QgsBasicNumericFormat::setNumberDecimalPlaces( std::max( numberDecimalPlaces, 1 ) );
}
@@ -45,6 +45,16 @@ class CORE_EXPORT QgsScientificNumericFormat : public QgsBasicNumericFormat
QgsNumericFormat *create( const QVariantMap &configuration ) const override SIP_FACTORY;
QVariantMap configuration() const override;

/**
* Sets the maximum number of decimal \a places to show.
*
* The \a places argument must be at least 1.
*
* \see numberDecimalPlaces()
* \see setShowTrailingZeros()
*/
void setNumberDecimalPlaces( int places ) override;

private:

#ifdef SIP_RUN
@@ -263,7 +263,7 @@ def testBearingFormat(self):
f.setNumberDecimalPlaces(0)
self.assertEqual(f.formatDouble(0, context), '0°')
self.assertEqual(f.formatDouble(5.5, context), '6°')
self.assertEqual(f.formatDouble(-5.5, context), '354°')
self.assertEqual(f.formatDouble(-5.4, context), '355°')
self.assertEqual(f.formatDouble(180, context), '180°')
f.setNumberDecimalPlaces(3)
self.assertEqual(f.formatDouble(0, context), '0°')
@@ -398,13 +398,17 @@ def testScientificFormat(self):
self.assertEqual(f.formatDouble(-5.5, context), '-5x5e+00')
self.assertEqual(f.formatDouble(-55555555.5, context), '-5x555556e+07')
context.setDecimalSeparator('.')

# places must be at least 1 for scientific notation!
f.setNumberDecimalPlaces(0)
self.assertEqual(f.numberDecimalPlaces(), 1)
self.assertEqual(f.formatDouble(0, context), '0e+00')
self.assertEqual(f.formatDouble(5.5, context), '6e+00')
self.assertEqual(f.formatDouble(55555555.5, context), '6e+07')
self.assertEqual(f.formatDouble(55555555.123456, context), '6e+07')
self.assertEqual(f.formatDouble(-5.5, context), '-6e+00')
self.assertEqual(f.formatDouble(-55555555.5, context), '-6e+07')
self.assertEqual(f.formatDouble(5.5, context), '5.5e+00')
self.assertEqual(f.formatDouble(55555555.5, context), '5.6e+07')
self.assertEqual(f.formatDouble(55555555.123456, context), '5.6e+07')
self.assertEqual(f.formatDouble(-5.5, context), '-5.5e+00')
self.assertEqual(f.formatDouble(-55555555.5, context), '-5.6e+07')

f.setNumberDecimalPlaces(3)
self.assertEqual(f.formatDouble(0, context), '0e+00')
self.assertEqual(f.formatDouble(5.5, context), '5.5e+00')

0 comments on commit ec37635

Please sign in to comment.
You can’t perform that action at this time.