ctkRangeWidgetValueProxyTest.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QApplication>
  16. #include <QTest>
  17. // CTK includes
  18. #include "ctkDoubleSpinBox.h"
  19. #include "ctkLinearValueProxy.h"
  20. #include "ctkRangeWidget.h"
  21. #include "ctkTest.h"
  22. #include "ctkValueProxy.h"
  23. namespace
  24. {
  25. //-----------------------------------------------------------------------------
  26. void getSpyReport(QSignalSpy& spy, double expectedValue)
  27. {
  28. QCOMPARE(spy.count(), 1);
  29. QList<QVariant> arguments = spy.takeFirst(); // take the first signal
  30. ctkTest::COMPARE(arguments.at(0).toDouble(), expectedValue);
  31. }
  32. //-----------------------------------------------------------------------------
  33. class CustomSpy : public QObject
  34. {
  35. Q_OBJECT
  36. public:
  37. CustomSpy()
  38. {
  39. this->AcknowledgedSignals = 0;
  40. }
  41. public slots:
  42. void onValuesChanged(double min, double max)
  43. {
  44. ++this->AcknowledgedSignals;
  45. this->MinSpyData.append(min);
  46. this->MaxSpyData.append(max);
  47. }
  48. public:
  49. void getSpyReport(double min, double max)
  50. {
  51. QCOMPARE(this->AcknowledgedSignals, 1);
  52. QCOMPARE(this->MinSpyData.size(), 1);
  53. ctkTest::COMPARE(this->MinSpyData[0], min);
  54. QCOMPARE(this->MaxSpyData.size(), 1);
  55. ctkTest::COMPARE(this->MaxSpyData[0], max);
  56. }
  57. QList<double> MinSpyData;
  58. QList<double> MaxSpyData;
  59. int AcknowledgedSignals;
  60. };
  61. } // end namespace
  62. //-----------------------------------------------------------------------------
  63. class ctkRangeWidgetValueProxyTester: public QObject
  64. {
  65. Q_OBJECT
  66. private slots:
  67. void testSetValues();
  68. void testSetValues_data();
  69. void testSetMinValue();
  70. void testSetMinValue_data();
  71. void testSetMaxValue();
  72. void testSetMaxValue_data();
  73. void testSetCoefficient();
  74. void testSetCoefficient_data();
  75. private:
  76. void testSetValueCommonData();
  77. void testSetPositionCommonData();
  78. };
  79. //-----------------------------------------------------------------------------
  80. void ctkRangeWidgetValueProxyTester::testSetValues()
  81. {
  82. // Setup
  83. ctkRangeWidget ranger;
  84. ranger.setRange(-200., 200.);
  85. ranger.setSingleStep(0.01);
  86. ranger.setValues(-32.6, 32.6);
  87. QFETCH(double, coefficient);
  88. QFETCH(double, offset);
  89. ctkLinearValueProxy proxy;
  90. proxy.setCoefficient(coefficient);
  91. proxy.setOffset(offset);
  92. ranger.setValueProxy(&proxy);
  93. // \todo when valuesChanged is fixed
  94. // Spy
  95. //CustomSpy valuesSpy;
  96. //QObject::connect(&ranger, SIGNAL(valuesChanged(double, double)),
  97. // &valuesSpy, SLOT(onValuesChanged(double, double)));
  98. // Test
  99. QFETCH(double, min);
  100. QFETCH(double, max);
  101. ranger.setValues(min, max);
  102. QFETCH(double, expectedMin);
  103. QFETCH(double, expectedMax);
  104. //valuesSpy.getSpyReport(expectedMin, expectedMax);
  105. ctkTest::COMPARE(ranger.minimumValue(), expectedMin);
  106. ctkTest::COMPARE(ranger.maximumValue(), expectedMax);
  107. }
  108. //-----------------------------------------------------------------------------
  109. void ctkRangeWidgetValueProxyTester::testSetValues_data()
  110. {
  111. QTest::addColumn<double>("coefficient");
  112. QTest::addColumn<double>("offset");
  113. QTest::addColumn<double>("min");
  114. QTest::addColumn<double>("expectedMin");
  115. QTest::addColumn<double>("max");
  116. QTest::addColumn<double>("expectedMax");
  117. const double max = std::numeric_limits<double>::max();
  118. const double inf = std::numeric_limits<double>::infinity();
  119. const double NaN = std::numeric_limits<double>::quiet_NaN();
  120. //---------------------------------------------------------------------------
  121. // Offset
  122. QTest::newRow("Offset only") << 1.0 << 49.19 << 0.1 << 0.1 << 0.2 << 0.2;
  123. QTest::newRow("Offset only: max+offset < min+offset < -200")
  124. << 1.0 << -42.19 << -160.0 << -157.81 << -190.9 << -157.81;
  125. QTest::newRow("Offset only: max+offset < -200 < min+offset")
  126. << 1.0 << -42.19 << -0.1 << -157.81 << -160.9 << -0.1;
  127. QTest::newRow("Offset only: -200 < max+offset < min+offset")
  128. << 1.0 << 42.19<< -0.1 << -130.9 << -130.9 << -0.1;
  129. QTest::newRow("Offset only: 200 < max+offset < min+offset")
  130. << 1.0 << 42.19 << 160.0 << 157.81 << 190.9 << 157.81;
  131. QTest::newRow("Offset only: max+offset < 200 < min+offset")
  132. << 1.0 << 42.19 << 160.9 << -0.9 << -0.9 << 157.81;
  133. QTest::newRow("Offset only: max+offset < min+offset < 200")
  134. << 1.0 << 42.19 << 130.6 << -13.9 << -13.9 << 130.6;
  135. QTest::newRow("Offset only: 200 < max = max_double = min = max_double")
  136. << 1.0 << 42.19 << max << 157.81 << max << 157.81;
  137. QTest::newRow("Offset only: max = -max_double < -200 < 200 < min = max_double")
  138. << 1.0 << 42.19 << max << -242.19 << -max << 157.81;
  139. QTest::newRow("Offset only: max = -max_double = min = -max_double < -200")
  140. << 1.0 << 42.19 << -max << -242.19 << -max << -242.19;
  141. QTest::newRow("Offset only: 200 < max = infinity = min = infinity")
  142. << 1.0 << 42.19 << inf << 157.81 << inf << 157.81;
  143. QTest::newRow("Offset only: max = -infinity < -200 < 200 < min = infinity")
  144. << 1.0 << 42.19 << inf << -242.19 << -inf << 157.81;
  145. QTest::newRow("Offset only: max = -infinity = min = -infinity < -200")
  146. << 1.0 << 42.19 << - inf << -242.19 << - inf << -242.19;
  147. QTest::newRow("Offset only: max = min = NaN")
  148. << 1.0 << 42.19 << NaN << 157.81 << NaN << 157.81;
  149. QTest::newRow("Offset only: max = NaN && min > 200")
  150. << 1.0 << 42.19 << 630.0 << 157.81 << NaN << 157.81;
  151. QTest::newRow("Offset only: min = NaN && max < -200")
  152. << 1.0 << 42.19 << NaN << -32.6 << -794348.12 << -32.6;
  153. //---------------------------------------------------------------------------
  154. // Coefficient
  155. QTest::newRow("Coeff only") << 5.0 << 0.0 << 0.1 << 0.1 << 0.2 << 0.2;
  156. QTest::newRow("Coeff only: max*coeff < min*coeff < -200")
  157. << 5.0 << 0.0 << -160.0 << -40.0 << -190.9 << -40.0;
  158. QTest::newRow("Coeff only: max*coeff < -200 < min*coeff")
  159. << 5.0 << 0.0 << -0.1 << -40.0 << -160.9 << -0.1;
  160. QTest::newRow("Coeff only: -200 < max*coeff < min*coeff")
  161. << 5.0 << 0.0 << -0.1 << -20.9 << -20.9 << -0.1;
  162. QTest::newRow("Coeff only: 200 < max*coeff < min*coeff")
  163. << 5.0 << 0.0 << 160.0 << 40.0 << 190.9 << 40.0;
  164. QTest::newRow("Coeff only: max*coeff < 200 < min*coeff")
  165. << 5.0 << 0.0 << 160.9 << -0.9 << -0.9 << 40.00;
  166. QTest::newRow("Coeff only: max*coeff < min*coeff < 200")
  167. << 5.0 << 0.0 << 13.6 << -13.9 << -13.9 << 13.6;
  168. QTest::newRow("Coeff only: 200 < max = max_double = min = max_double")
  169. << 5.0 << 0.0 << max << 40.0 << max << 40.0;
  170. QTest::newRow("Coeff only: max = -max_double < -200 < 200 < min = max_double")
  171. << 5.0 << 0.0 << max << -40.0 << - max << 40.0;
  172. QTest::newRow("Coeff only: max = -max_double = min = -max_double < -200")
  173. << 5.0 << 0.0 << -max << -40.0 << -max << -40.0;
  174. QTest::newRow("Coeff only: 200 < max = infinity = min = infinity")
  175. << 5.0 << 0.0 << inf << 40.0 << inf << 40.0;
  176. QTest::newRow("Coeff only: max = -infinity < -200 < 200 < min = infinity")
  177. << 5.0 << 0.0 << inf << -40.0 << -inf << 40.0;
  178. QTest::newRow("Coeff only: max = -infinity = min = -infinity < -200")
  179. << 5.0 << 0.0 << - inf << -40.0 << - inf << -40.0;
  180. QTest::newRow("Coeff only: max = min = NaN")
  181. << 5.0 << 0.0 << NaN << 40.0 << NaN << 40.0;
  182. QTest::newRow("Coeff only: max = NaN && min > 200")
  183. << 5.0 << 0.0 << 630.0 << 40.0 << NaN << 40.0;
  184. QTest::newRow("Coeff only: min = NaN && max < -200")
  185. << 5.0 << 0.0 << NaN << -32.6 << -794348.12 << -32.6;
  186. //---------------------------------------------------------------------------
  187. // Linear
  188. QTest::newRow("Linear") << 5.0 << 12.0 << 0.1 << 0.1 << 0.2 << 0.2;
  189. QTest::newRow("Linear:f(max) < f(min) < -200")
  190. << 5.0 << 12.0 << -160.0 << -42.4 << -190.9 << -42.4;
  191. QTest::newRow("Linear: f(max) < -200 < f(min)")
  192. << 5.0 << 12.0 << -0.1 << -42.4 << -160.9 << -0.1;
  193. QTest::newRow("Linear: -200 < f(max) < f(min)")
  194. << 5.0 << 12.0 << -0.1 << -20.9 << -20.9 << -0.1;
  195. QTest::newRow("Linear: 200 < f(max) < f(min)")
  196. << 5.0 << 12.0 << 160.0 << 37.6 << 190.9 << 37.6;
  197. QTest::newRow("Linear: f(max) < 200 < f(min)")
  198. << 5.0 << 12.0 << 160.9 << -0.9 << -0.9 << 37.6;
  199. QTest::newRow("Linear: f(max) < f(min) < 200")
  200. << 5.0 << 12.0 << 13.6 << -13.9 << -13.9 << 13.6;
  201. QTest::newRow("Linear: 200 < max = max_double = min = max_double")
  202. << 5.0 << 12.0 << max << 37.6 << max << 37.6;
  203. QTest::newRow("Linear: max = -max_double < -200 < 200 < min = max_double")
  204. << 5.0 << 12.0 << max << -42.4 << - max << 37.6;
  205. QTest::newRow("Linear: max = -max_double = min = -max_double < -200")
  206. << 5.0 << 12.0 << -max << -42.4 << -max << -42.4;
  207. QTest::newRow("Linear: 200 < max = infinity = min = infinity")
  208. << 5.0 << 12.0 << inf << 37.6 << inf << 37.6;
  209. QTest::newRow("Linear: max = -infinity < -200 < 200 < min = infinity")
  210. << 5.0 << 12.0 << inf << -42.4 << -inf << 37.6;
  211. QTest::newRow("Linear: max = -infinity = min = -infinity < -200")
  212. << 5.0 << 12.0 << - inf << -42.4 << - inf << -42.4;
  213. QTest::newRow("Linear: max = min = NaN")
  214. << 5.0 << 12.0 << NaN << 37.6 << NaN << 37.6;
  215. QTest::newRow("Linear: max = NaN && f(min) > 200")
  216. << 5.0 << 12.0 << 630.0 << 37.6 << NaN << 37.6;
  217. QTest::newRow("Linear: min = NaN && f(max) < -200")
  218. << 5.0 << 12.0 << NaN << -32.6 << -794348.12 << -32.6;
  219. }
  220. //-----------------------------------------------------------------------------
  221. void ctkRangeWidgetValueProxyTester::testSetMinValue()
  222. {
  223. // Setup
  224. ctkRangeWidget ranger;
  225. ranger.setRange(-200., 200.);
  226. ranger.setSingleStep(0.01);
  227. ranger.setMinimumValue(-32.6);
  228. QFETCH(double, coefficient);
  229. QFETCH(double, offset);
  230. ctkLinearValueProxy proxy;
  231. proxy.setCoefficient(coefficient);
  232. proxy.setOffset(offset);
  233. ranger.setValueProxy(&proxy);
  234. // \todo when valuesChanged is fixed
  235. // Spy
  236. //QSignalSpy valueSpy(&ranger, SIGNAL(minimumValueChanged(double)));
  237. // Test
  238. QFETCH(double, value);
  239. ranger.setMinimumValue(value);
  240. QFETCH(double, expectedValue);
  241. //getSpyReport(valueSpy, expectedValue);
  242. ctkTest::COMPARE(ranger.minimumValue(), expectedValue);
  243. }
  244. //-----------------------------------------------------------------------------
  245. void ctkRangeWidgetValueProxyTester::testSetMinValue_data()
  246. {
  247. QTest::addColumn<double>("coefficient");
  248. QTest::addColumn<double>("offset");
  249. QTest::addColumn<double>("value");
  250. QTest::addColumn<double>("expectedValue");
  251. //---------------------------------------------------------------------------
  252. // Offset
  253. QTest::newRow("Offset only") << 1.0 << 42.19 << 0.1 << 0.1;
  254. QTest::newRow("Offset only: less than min")
  255. << 1.0 << 42.19 << -510.0 << -242.19;
  256. QTest::newRow("Offset only: less than min but ok with offset")
  257. << 1.0 << 42.19 << -230.0 << -230.0;
  258. QTest::newRow("Offset only: less than min with offset")
  259. << 1.0 << -42.19 << -190.0 << -157.81;
  260. QTest::newRow("Offset only: more than max with offset")
  261. << 1.0 << 42.19 << 160.0 << 99.;
  262. QTest::newRow("Offset only: more than max")
  263. << 1.0 << -42.19 << 65010.0 << 99.;
  264. QTest::newRow("Offset only: max")
  265. << 1.0 << 42.19 << std::numeric_limits<double>::max() << 99.;
  266. QTest::newRow("Offset only: min")
  267. << 1.0 << 42.19 << -std::numeric_limits<double>::max() << -242.19;
  268. QTest::newRow("Offset only: infinity")
  269. << 1.0 << 42.19 << std::numeric_limits<double>::infinity() << 99.;
  270. QTest::newRow("Offset only: - infinity")
  271. << 1.0 << 42.19 << -std::numeric_limits<double>::infinity() << -242.19;
  272. QTest::newRow("Offset only: Nan")
  273. << 1.0 << 42.19 << std::numeric_limits<double>::quiet_NaN() << 99.;
  274. //---------------------------------------------------------------------------
  275. // Coefficient
  276. QTest::newRow("Coeff only") << 5.0 << 0.0 << 0.1 << 0.1;
  277. QTest::newRow("Coeff only: less than min")
  278. << 5.0 << 0.0 << -510.0 << -40.0;
  279. QTest::newRow("Coeff only: less than min but ok with coeff")
  280. << 0.5 << 0.0 << -230.0 << -230.0;
  281. QTest::newRow("Coeff only: less than min with coeff")
  282. << 5.0 << 0.0 << -190.0 << -40.0;
  283. QTest::newRow("Coeff only: more than max with coeff")
  284. << 5.0 << 0.0 << 160.0 << 40.0;
  285. QTest::newRow("Coeff only: more than max")
  286. << 5.0 << 0.0 << 65010.0 << 40.0;
  287. QTest::newRow("Coeff only: less than max but ok with coeff")
  288. << 0.5 << 0.0 << 229.2 << 99.;
  289. QTest::newRow("Coeff only: max")
  290. << 5.0 << 0.0 << std::numeric_limits<double>::max() << 40.0;
  291. QTest::newRow("Coeff only: min")
  292. << 5.0 << 0.0 << -std::numeric_limits<double>::max() << -40.0;
  293. QTest::newRow("Coeff only: infinity")
  294. << 5.0 << 0.0 << std::numeric_limits<double>::infinity() << 40.0;
  295. QTest::newRow("Coeff only: - infinity")
  296. << 5.0 << 0.0 << -std::numeric_limits<double>::infinity() << -40.0;
  297. QTest::newRow("Coeff only: Nan")
  298. << 5.0 << 0.0 << std::numeric_limits<double>::quiet_NaN() << 40.0;
  299. //---------------------------------------------------------------------------
  300. // Linear
  301. QTest::newRow("Linear") << 5.0 << 0.0 << 0.1 << 0.1;
  302. QTest::newRow("Linear: less than min")
  303. << 5.0 << 12.0 << -510.0 << -42.4;
  304. QTest::newRow("Linear: less than min but ok with function")
  305. << 0.5 << 12.0 << -230.0 << -230.0;
  306. QTest::newRow("Linear: less than min with function")
  307. << 5.0 << 12.0 << -61.5 << -42.4;
  308. QTest::newRow("Linear: more than max with function")
  309. << 5.0 << 12.0 << 160.0 << 37.6;
  310. QTest::newRow("Linear: more than max")
  311. << 5.0 << 12.0 << 65010.0 << 37.6;
  312. QTest::newRow("Linear: less than max but ok with function")
  313. << 0.5 << 12.0 << 229.2 << 99.;
  314. QTest::newRow("Linear: max")
  315. << 5.0 << 12.0 << std::numeric_limits<double>::max() << 37.6;
  316. QTest::newRow("Linear: min")
  317. << 5.0 << 12.0 << -std::numeric_limits<double>::max() << -42.4;
  318. QTest::newRow("Linear: infinity")
  319. << 5.0 << 12.0 << std::numeric_limits<double>::infinity() << 37.6;
  320. QTest::newRow("Linear: - infinity")
  321. << 5.0 << 12.0 << -std::numeric_limits<double>::infinity() << -42.4;
  322. QTest::newRow("Linear: Nan")
  323. << 5.0 << 12.0 << std::numeric_limits<double>::quiet_NaN() << 37.6;
  324. }
  325. //-----------------------------------------------------------------------------
  326. void ctkRangeWidgetValueProxyTester::testSetMaxValue()
  327. {
  328. // Setup
  329. ctkRangeWidget ranger;
  330. ranger.setMinimum(-200);
  331. ranger.setMaximum(200);
  332. ranger.setSingleStep(0.01);
  333. ranger.setMaximumValue(-32.6);
  334. QFETCH(double, coefficient);
  335. QFETCH(double, offset);
  336. ctkLinearValueProxy proxy;
  337. proxy.setCoefficient(coefficient);
  338. proxy.setOffset(offset);
  339. ranger.setValueProxy(&proxy);
  340. // \todo when valuesChanged is fixed
  341. // Spy
  342. //QSignalSpy valueSpy(&ranger, SIGNAL(maximumValueChanged(double)));
  343. // Test
  344. QFETCH(double, value);
  345. ranger.setMaximumValue(value);
  346. QFETCH(double, expectedValue);
  347. //getSpyReport(valueSpy, expectedValue);
  348. ctkTest::COMPARE(ranger.maximumValue(), expectedValue);
  349. }
  350. //-----------------------------------------------------------------------------
  351. void ctkRangeWidgetValueProxyTester::testSetMaxValue_data()
  352. {
  353. QTest::addColumn<double>("coefficient");
  354. QTest::addColumn<double>("offset");
  355. QTest::addColumn<double>("value");
  356. QTest::addColumn<double>("expectedValue");
  357. //---------------------------------------------------------------------------
  358. // Offset
  359. QTest::newRow("Offset only") << 1.0 << 42.19 << 0.1 << 0.1;
  360. QTest::newRow("Offset only: less than min")
  361. << 1.0 << 42.19 << -510.0 << -32.6;
  362. QTest::newRow("Offset only: less than min but ok with offset")
  363. << 1.0 << 42.19 << -230.0 << -32.6;
  364. QTest::newRow("Offset only: less than min with offset")
  365. << 1.0 << -42.19 << -190.0 << -32.6;
  366. QTest::newRow("Offset only: more than max with offset")
  367. << 1.0 << 42.19 << 160.0 << 157.81;
  368. QTest::newRow("Offset only: more than max")
  369. << 1.0 << -42.19 << 65010.0 << 242.19;
  370. QTest::newRow("Offset only: less than max but ok with offset")
  371. << 1.0 << -42.19 << 229.1 << 229.1;
  372. QTest::newRow("Offset only: max")
  373. << 1.0 << 42.19 << std::numeric_limits<double>::max() << 157.81;
  374. QTest::newRow("Offset only: min")
  375. << 1.0 << 42.19 << -std::numeric_limits<double>::max() << -32.6;
  376. QTest::newRow("Offset only: infinity")
  377. << 1.0 << 42.19 << std::numeric_limits<double>::infinity() << 157.81;
  378. QTest::newRow("Offset only: -infinity")
  379. << 1.0 << 42.19 << -std::numeric_limits<double>::infinity() << -32.6;
  380. QTest::newRow("Offset only: Nan")
  381. << 1.0 << 42.19 << std::numeric_limits<double>::quiet_NaN() << 157.81;
  382. //---------------------------------------------------------------------------
  383. // Coefficient
  384. QTest::newRow("Coeff only") << 5.0 << 0.0 << 0.1 << 0.1;
  385. QTest::newRow("Coeff only: less than min")
  386. << 5.0 << 0.0 << -510.0 << -32.6;
  387. QTest::newRow("Coeff only: less than min but ok with coeff")
  388. << 0.5 << 0.0 << -230.0 << -32.6;;
  389. QTest::newRow("Coeff only: less than min with coeff")
  390. << 5.0 << 0.0 << -190.0 << -32.6;
  391. QTest::newRow("Coeff only: more than max with coeff")
  392. << 5.0 << 0.0 << 160.0 << 40.0;
  393. QTest::newRow("Coeff only: more than max")
  394. << 5.0 << 0.0 << 65010.0 << 40.0;
  395. QTest::newRow("Offset only: less than max but ok with coeff")
  396. << 0.5 << 0.0 << 229.2 << 229.2;
  397. QTest::newRow("Coeff only: max")
  398. << 5.0 << 0.0 << std::numeric_limits<double>::max() << 40.0;
  399. QTest::newRow("Coeff only: min")
  400. << 5.0 << 0.0 << -std::numeric_limits<double>::max() << -32.6;
  401. QTest::newRow("Coeff only: infinity")
  402. << 5.0 << 0.0 << std::numeric_limits<double>::infinity() << 40.0;
  403. QTest::newRow("Coeff only: -infinity")
  404. << 5.0 << 0.0 << -std::numeric_limits<double>::infinity() << -32.6;
  405. QTest::newRow("Coeff only: Nan")
  406. << 5.0 << 0.0 << std::numeric_limits<double>::quiet_NaN() << 40.0;
  407. //---------------------------------------------------------------------------
  408. // Linear
  409. QTest::newRow("Linear") << 5.0 << 0.0 << 0.1 << 0.1;
  410. QTest::newRow("Linear: less than min")
  411. << 5.0 << 12.0 << -510.0 << -32.6;
  412. QTest::newRow("Linear: less than min but ok with function")
  413. << 0.5 << 12.0 << -230.0 << -32.6;
  414. QTest::newRow("Linear: less than min with function")
  415. << 5.0 << 12.0 << -61.5 << -32.6;
  416. QTest::newRow("Linear: more than max with function")
  417. << 5.0 << 12.0 << 160.0 << 37.6;
  418. QTest::newRow("Linear: more than max")
  419. << 5.0 << 12.0 << 65010.0 << 37.6;
  420. QTest::newRow("Linear: less than max but ok with function")
  421. << 0.5 << 12.0 << 229.2 << 229.2;
  422. QTest::newRow("Linear: max")
  423. << 5.0 << 12.0 << std::numeric_limits<double>::max() << 37.6;
  424. QTest::newRow("Linear: min")
  425. << 5.0 << 12.0 << -std::numeric_limits<double>::max() << -32.6;
  426. QTest::newRow("Linear: infinity")
  427. << 5.0 << 12.0 << std::numeric_limits<double>::infinity() << 37.6;
  428. QTest::newRow("Linear: -infinity")
  429. << 5.0 << 12.0 << -std::numeric_limits<double>::infinity() << -32.6;
  430. QTest::newRow("Linear: Nan")
  431. << 5.0 << 12.0 << std::numeric_limits<double>::quiet_NaN() << 37.6;
  432. }
  433. //-----------------------------------------------------------------------------
  434. void ctkRangeWidgetValueProxyTester::testSetCoefficient()
  435. {
  436. ctkRangeWidget rangeWidget;
  437. rangeWidget.setRange(-10000., 10000.);
  438. rangeWidget.setValues(10., 50.);
  439. ctkLinearValueProxy proxy;
  440. proxy.setCoefficient(10.);
  441. rangeWidget.setValueProxy(&proxy);
  442. ctkTest::COMPARE(rangeWidget.minimumValue(), 10.);
  443. ctkTest::COMPARE(rangeWidget.maximumValue(), 50.);
  444. ctkTest::COMPARE(rangeWidget.minimumSpinBox()->displayedValue(), 100.);
  445. ctkTest::COMPARE(rangeWidget.maximumSpinBox()->displayedValue(), 500.);
  446. QFETCH(double, newCoefficient);
  447. proxy.setCoefficient(newCoefficient);
  448. QFETCH(double, expectedMinimumDisplayedValue);
  449. QFETCH(double, expectedMaximumDisplayedValue);
  450. ctkTest::COMPARE(rangeWidget.minimumValue(), 10.);
  451. ctkTest::COMPARE(rangeWidget.maximumValue(), 50.);
  452. ctkTest::COMPARE(rangeWidget.minimumSpinBox()->displayedValue(),
  453. expectedMinimumDisplayedValue);
  454. ctkTest::COMPARE(rangeWidget.maximumSpinBox()->displayedValue(),
  455. expectedMaximumDisplayedValue);
  456. }
  457. //-----------------------------------------------------------------------------
  458. void ctkRangeWidgetValueProxyTester::testSetCoefficient_data()
  459. {
  460. QTest::addColumn<double>("newCoefficient");
  461. QTest::addColumn<double>("expectedMinimumDisplayedValue");
  462. QTest::addColumn<double>("expectedMaximumDisplayedValue");
  463. QTest::newRow("100") << 100.0 << 1000. << 5000.;
  464. QTest::newRow("10") << 10.0 << 100. << 500.;
  465. QTest::newRow("1") << 1.0 << 10. << 50.;
  466. QTest::newRow("0.10") << 0.1 << 1. << 5.;
  467. QTest::newRow("-10") << -10.0 << -500. << -100.;
  468. }
  469. // ----------------------------------------------------------------------------
  470. CTK_TEST_MAIN(ctkRangeWidgetValueProxyTest)
  471. #include "moc_ctkRangeWidgetValueProxyTest.cpp"