Skip to content

Commit

Permalink
Apply ValueProxy to widgets min and max
Browse files Browse the repository at this point in the history
  • Loading branch information
finetjul committed Aug 5, 2013
1 parent bc38808 commit b9d0ab9
Show file tree
Hide file tree
Showing 17 changed files with 762 additions and 871 deletions.
2 changes: 1 addition & 1 deletion Libs/Core/Testing/Cpp/ctkLinearValueProxyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void ctkLinearValueProxyTester::testCoefficient_data()
QTest::addColumn<double>("expectedProxyValue");

QTest::newRow("Null coeff") << 0.0 << 0.0;
QTest::newRow("Very very small coeff") << 1e-26 << 0.0;
QTest::newRow("Very very small coeff") << 1e-26 << 1.32e-25;
QTest::newRow("Not so small coeff") << 1e-6 << 1.32e-5;
QTest::newRow("Normal coeff") << 2.0 << 26.4;
QTest::newRow("Negative coeff") << -2.0 << -26.4;
Expand Down
7 changes: 4 additions & 3 deletions Libs/Core/Testing/Cpp/ctkUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ void ctkUtilsTester::testSignificantDecimals()
void ctkUtilsTester::testSignificantDecimals_data()
{
QTest::addColumn<double>("value");
QTest::addColumn<int>("defaultDecimals");
QTest::addColumn<int>("expectedDecimals");

// Default decimals= -1
Expand Down Expand Up @@ -241,10 +242,10 @@ void ctkUtilsTester::testSignificantDecimals_data()
QTest::newRow("inf -> 0") << std::numeric_limits<double>::infinity() << 3 << 0;
QTest::newRow("-inf -> 0") << -std::numeric_limits<double>::infinity() << 3 << 0;
QTest::newRow("nan -> -1") << std::numeric_limits<double>::quiet_NaN() << 3 << -1;
QTest::newRow("min -> 16") << std::numeric_limits<double>::min() << 3 << 16;
QTest::newRow("min -> 3") << std::numeric_limits<double>::min() << 3 << 3;
QTest::newRow("max -> 0") << std::numeric_limits<double>::max() << 3 << 0;
QTest::newRow("denorm -> 16") << std::numeric_limits<double>::denorm_min()
<< 3 << 16;
QTest::newRow("denorm -> 3") << std::numeric_limits<double>::denorm_min()
<< 3 << 3;

}

Expand Down
165 changes: 68 additions & 97 deletions Libs/Widgets/Testing/Cpp/ctkCoordinatesWidgetValueProxyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ class Spy : public QObject

void getSpyReport(QString coordinatesString)
{
ctkTest::COMPARE(AcknowledgedSignals, 1);
QCOMPARE(AcknowledgedSignals, 1);
AcknowledgedSignals = 0;

QStringList coordinatesList = coordinatesString.split(',');
ctkTest::COMPARE(coordinatesList.count(), this->Coordinates.size());
QCOMPARE(coordinatesList.count(), this->Coordinates.size());
for (int i = 0; i < this->Coordinates.size(); ++i)
{
ctkTest::COMPARE(this->Coordinates[i], coordinatesList[i].toDouble());
QCOMPARE(this->Coordinates[i], coordinatesList[i].toDouble());
}
this->Coordinates.clear();
};
Expand Down Expand Up @@ -87,12 +87,14 @@ private slots:

void testSetValue();
void testSetValue_data();

void testPrecision();
void testPrecision_data();
};

//-----------------------------------------------------------------------------
void ctkCoordinatesWidgetValueProxyTester::testSetValue()
{
// Setup
ctkCoordinatesWidget coordinatesWidget;
coordinatesWidget.setMinimum(-200);
coordinatesWidget.setMaximum(200);
Expand Down Expand Up @@ -129,135 +131,104 @@ void ctkCoordinatesWidgetValueProxyTester::testSetValue_data()

//---------------------------------------------------------------------------
// Offset
QTest::newRow("Offset only") << 1.0 << 42.19 << "0.1,0.2,0.3"
QTest::newRow("Offset only") << 1. << 42.19 << "0.1,0.2,0.3"
<< "0.1,0.2,0.3";

QTest::newRow("Offset only: less than min")
<< 1.0 << 42.19 << "-250.0,-900.0,-3000.0" << "-242.19,-242.19,-242.19";
<< 1. << 42.19 << "-250.,-900.,-3000." << "-200,-200,-200";
QTest::newRow("Offset only: less than min but ok with offset")
<< 1.0 << 42.19 << "-240.3,-232.1,-200.01" << "-240.3,-232.1,-200.01";
<< 1. << 42.19 << "-240.3,-232.1,-200.01" << "-200,-200,-200";
QTest::newRow("Offset only: less than min with offset")
<< 1.0 << -42.19 << "-160.15,-199.99,-159.0" << "-157.81,-157.81,-157.81";
<< 1. << -42.19 << "-160.15,-199.99,-159." << "-160.15,-199.99,-159";

QTest::newRow("Offset only: more than max with offset")
<< 1.0 << 42.19 << "160.0,199.9,163.32" << "157.81,157.81,157.81";
<< 1. << 42.19 << "160.,199.9,163.32" << "160,199.9,163.32";
QTest::newRow("Offset only: more than max")
<< 1.0 << -42.19 << "4830.0,250.01,1e6" << "242.19,242.19,242.19";
<< 1. << -42.19 << "4830.,250.01,1e6" << "200,200,200";
QTest::newRow("Offset only: less than max but ok with offset")
<< 1.0 << -42.19 << "210.3,200.01,241.03" << "210.3,200.01,241.03";

QTest::newRow("Offset only: max")
<< 1.0 << 42.19
<< coordinatesFromValue(std::numeric_limits<double>::max())
<< "157.81,157.81,157.81";

QTest::newRow("Offset only: min")
<< 1.0 << 42.19
<< coordinatesFromValue(- std::numeric_limits<double>::max())
<< "-242.19,-242.19,-242.19";

QTest::newRow("Offset only: infinity")
<< 1.0 << 42.19
<< coordinatesFromValue(std::numeric_limits<double>::infinity())
<< "157.81,157.81,157.81";
<< 1. << -42.19 << "210.3,200.01,241.03" << "200,200,200";

QTest::newRow("Offset only: - infinity")
<< 1.0 << 42.19
<< coordinatesFromValue(- std::numeric_limits<double>::infinity())
<< "-242.19,-242.19,-242.19";

QTest::newRow("Offset only: Nan")
<< 1.0 << 42.19
<< coordinatesFromValue(std::numeric_limits<double>::quiet_NaN())
<< "157.81,157.81,157.81";

//---------------------------------------------------------------------------
// Coefficient
QTest::newRow("Coeff only") << 5.0 << 0.0 << "0.1,0.2,0.3"
<< "0.1,0.2,0.3";

QTest::newRow("Coeff only: less than min")
<< 5.0 << 0.0 << "-510.08,-2000,-1000000." << "-40,-40,-40";
<< 5. << 0. << "-510.08,-2000,-1000000." << "-200,-200,-200";
QTest::newRow("Coeff only: less than min but ok with coeff")
<< 0.5 << 0.0 << "-250.08,-399.99,-120" << "-250.08,-399.99,-120";
<< 0.5 << 0. << "-250.08,-399.99,-120" << "-200,-200,-120";
QTest::newRow("Coeff only: less than min with coeff")
<< 5.0 << 0.0<< "-42.08,-199.99,-40.01" << "-40,-40,-40";
<< 5. << 0.<< "-42.08,-199.99,-40.01" << "-42.08,-199.99,-40.01";

QTest::newRow("Coeff only: more than max with coeff")
<< 5.0 << 0.0 << "160.08,40.01,199.99" << "40,40,40";
<< 5. << 0. << "160.08,40.01,199.99" << "160.08,40.01,199.99";
QTest::newRow("Coeff only: more than max")
<< 5.0 << 0.0 << "510.08,2000,1000000." << "40,40,40";
<< 5. << 0. << "510.08,2000,1000000." << "200,200,200";
QTest::newRow("Offset only: more than max but ok with coeff")
<< 0.5 << 0.0 << "380.08,399.99,200.01" << "380.08,399.99,200.01";

QTest::newRow("Offset only: max")
<< 5.0 << 0.0
<< coordinatesFromValue(std::numeric_limits<double>::max())
<< "40,40,40";

QTest::newRow("Offset only: min")
<< 5.0 << 0.0
<< coordinatesFromValue(- std::numeric_limits<double>::max())
<< "-40,-40,-40";

QTest::newRow("Offset only: infinity")
<< 5.0 << 0.0
<< coordinatesFromValue(std::numeric_limits<double>::infinity())
<< "40,40,40";
<< 0.5 << 0. << "380.08,399.99,200.01" << "200,200,200";

QTest::newRow("Offset only: - infinity")
<< 5.0 << 0.0
<< coordinatesFromValue(- std::numeric_limits<double>::infinity())
<< "-40,-40,-40";

QTest::newRow("Offset only: Nan")
<< 5.0 << 0.0
<< coordinatesFromValue(std::numeric_limits<double>::quiet_NaN())
<< "40,40,40";

//---------------------------------------------------------------------------
// Linear
QTest::newRow("Linear") << 5.0 << 12.0 << "0.1,0.2,0.3"
<< "0.1,0.2,0.3";

QTest::newRow("Linear: less than min")
<< 5.0 << 12.0 << "-510.08,-2000,-1000000." << "-42.4,-42.4,-42.4";
<< 5.0 << 12.0 << "-510.08,-2000,-1000000." << "-200,-200,-200";
QTest::newRow("Linear: less than min but ok with function")
<< 0.5 << 12.0 << "-250.08,-411.99,-120" << "-250.08,-411.99,-120";
<< 0.5 << 12.0 << "-250.08,-411.99,-120" << "-200,-200,-120";
QTest::newRow("Linear: less than min with function")
<< 5.0 << 12.0 << "-64.08,-199.99,-52.01" << "-42.4,-42.4,-42.4";
<< 5.0 << 12.0 << "-64.08,-199.99,-52.01" << "-64.08,-199.99,-52.01";

QTest::newRow("Linear: more than max with function")
<< 5.0 << 12.0 << "64.08,189.99,37.61" << "37.6,37.6,37.6";
<< 5.0 << 12.0 << "64.08,189.99,37.61" << "64.08,189.99,37.61";
QTest::newRow("Linear: more than max")
<< 5.0 << 12.0 << "200.01,900000.0,411.99" << "37.6,37.6,37.6";
QTest::newRow("Offset only: more than max but ok with function")
<< 0.5 << 12.0 << "209.01,356.9,350.9" << "209.01,356.9,350.9";

QTest::newRow("Linear: max")
<< 5.0 << 12.0
<< coordinatesFromValue(std::numeric_limits<double>::max())
<< "37.6,37.6,37.6";

QTest::newRow("Offset only: min")
<< 5.0 << 12.0
<< coordinatesFromValue(- std::numeric_limits<double>::max())
<< "-42.4,-42.4,-42.4";

QTest::newRow("Offset only: infinity")
<< 5.0 << 12.0
<< coordinatesFromValue(std::numeric_limits<double>::infinity())
<< "37.6,37.6,37.6";

QTest::newRow("Offset only: - infinity")
<< 5.0 << 12.0
<< coordinatesFromValue(- std::numeric_limits<double>::infinity())
<< "-42.4,-42.4,-42.4";

QTest::newRow("Offset only: Nan")
<< 5.0 << 12.0
<< coordinatesFromValue(std::numeric_limits<double>::quiet_NaN())
<< "37.6,37.6,37.6";
<< 5.0 << 12.0 << "200.01,900000.0,411.99" << "200,200,200";
QTest::newRow("Linear: more than max but ok with function")
<< 0.5 << 12.0 << "209.01,356.9,350.9" << "200,200,200";
}

//-----------------------------------------------------------------------------
void ctkCoordinatesWidgetValueProxyTester::testPrecision()
{
ctkCoordinatesWidget coordinatesWidget;
coordinatesWidget.setDecimalsOption(ctkDoubleSpinBox::DecimalsByValue);
double coordinates[3] = {0., 0., 0.};
coordinatesWidget.setCoordinates(coordinates);
coordinatesWidget.setDecimals(3);
coordinatesWidget.setSingleStep(0.001);
coordinatesWidget.setRange(-10000., 10000.);
coordinatesWidget.setDecimals(3);
coordinatesWidget.setSingleStep(0.001);


coordinates[0] = 1.;
coordinates[1] = 1.;
coordinates[1] = 1.;
// coordinatesWidget.setCoordinates(coordinates);

QFETCH(double, coefficient);

ctkLinearValueProxy proxy;
proxy.setCoefficient(coefficient);
coordinatesWidget.setValueProxy(&proxy);

coordinatesWidget.setCoordinates(coordinates);
coordinates[2] = 1.3;
coordinatesWidget.setCoordinates(coordinates);
const double* res = coordinatesWidget.coordinates();

QCOMPARE(coordinates[0], res[0]);
QCOMPARE(coordinates[1], res[1]);
QCOMPARE(coordinates[2], res[2]);
}

//-----------------------------------------------------------------------------
void ctkCoordinatesWidgetValueProxyTester::testPrecision_data()
{
QTest::addColumn<double>("coefficient");
QTest::newRow("1000000.") << 1000000.;
}

// ----------------------------------------------------------------------------
Expand Down
23 changes: 22 additions & 1 deletion Libs/Widgets/Testing/Cpp/ctkDoubleSliderValueProxyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,38 @@ class ctkDoubleSliderValueProxyTester: public QObject
Q_OBJECT
private slots:

void testSetValueProxy();

void testSetValue();
void testSetValue_data();

void testSetSliderPosition();
void testSetSliderPosition_data();

};

//-----------------------------------------------------------------------------
void ctkDoubleSliderValueProxyTester::testSetValueProxy()
{
ctkDoubleSlider slider;
slider.setRange(-200., 200.);
slider.setValue(-32.6);

ctkLinearValueProxy proxy;
proxy.setCoefficient(-1.);
proxy.setOffset(20.);

QSignalSpy valueSpy(&slider, SIGNAL(valueChanged(double)));
QSignalSpy rangeSpy(&slider, SIGNAL(rangeChanged(double,double)));
slider.setValueProxy(&proxy);

QCOMPARE(valueSpy.count(), 0);
QCOMPARE(rangeSpy.count(), 0);
}

//-----------------------------------------------------------------------------
void ctkDoubleSliderValueProxyTester::testSetValue()
{
// Setup
ctkDoubleSlider slider;
slider.setRange(-200., 200.);
slider.setSingleStep(0.01);
Expand Down
Loading

0 comments on commit b9d0ab9

Please sign in to comment.