ctkDoubleRangeSliderValueProxyTest.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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 "ctkDoubleRangeSlider.h"
  19. #include "ctkLinearValueProxy.h"
  20. #include "ctkTest.h"
  21. #include "ctkValueProxy.h"
  22. // STD includes
  23. #include <limits>
  24. namespace
  25. {
  26. //-----------------------------------------------------------------------------
  27. void getSpyReport(QSignalSpy& spy, double expectedValue)
  28. {
  29. QCOMPARE(spy.count(), 1);
  30. QList<QVariant> arguments = spy.takeFirst(); // take the first signal
  31. ctkTest::COMPARE(arguments.at(0).toDouble(), expectedValue);
  32. }
  33. //-----------------------------------------------------------------------------
  34. class CustomSpy : public QObject
  35. {
  36. Q_OBJECT
  37. public:
  38. CustomSpy()
  39. {
  40. this->AcknowledgedSignals = 0;
  41. }
  42. public slots:
  43. void onValuesChanged(double min, double max)
  44. {
  45. ++this->AcknowledgedSignals;
  46. this->MinSpyData.append(min);
  47. this->MaxSpyData.append(max);
  48. }
  49. public:
  50. void getSpyReport(double min, double max)
  51. {
  52. QCOMPARE(this->AcknowledgedSignals, 1);
  53. QCOMPARE(this->MinSpyData.size(), 1);
  54. ctkTest::COMPARE(this->MinSpyData[0], min);
  55. QCOMPARE(this->MaxSpyData.size(), 1);
  56. ctkTest::COMPARE(this->MaxSpyData[0], max);
  57. }
  58. QList<double> MinSpyData;
  59. QList<double> MaxSpyData;
  60. int AcknowledgedSignals;
  61. };
  62. } // end namespace
  63. //-----------------------------------------------------------------------------
  64. class ctkDoubleRangeSliderValueProxyTester: public QObject
  65. {
  66. Q_OBJECT
  67. private slots:
  68. void testSetValues();
  69. void testSetValues_data();
  70. void testSetMinValue();
  71. void testSetMinValue_data() { testSetValueCommonData(); };
  72. void testSetMaxValue();
  73. void testSetMaxValue_data(){ testSetValueCommonData(); };
  74. void testSetMinPosition();
  75. void testSetMinPosition_data() { testSetPositionCommonData(); };
  76. void testSetMaxPosition();
  77. void testSetMaxPosition_data() { testSetPositionCommonData(); };
  78. private:
  79. void testSetValueCommonData();
  80. void testSetPositionCommonData();
  81. };
  82. //-----------------------------------------------------------------------------
  83. void ctkDoubleRangeSliderValueProxyTester::testSetValues()
  84. {
  85. // Setup
  86. ctkDoubleRangeSlider slider;
  87. slider.setMinimum(-200);
  88. slider.setMaximum(200);
  89. slider.setSingleStep(0.01);
  90. slider.setMinimumValue(-32.6);
  91. slider.setMaximumValue(32.6);
  92. QFETCH(double, coefficient);
  93. QFETCH(double, offset);
  94. ctkLinearValueProxy proxy;
  95. proxy.setCoefficient(coefficient);
  96. proxy.setOffset(offset);
  97. slider.setValueProxy(&proxy);
  98. // Spy
  99. CustomSpy valuesSpy();
  100. QObject::connect(&slider, SIGNAL(valuesChanged(double, double)),
  101. &valuesSpy, SLOT(onValuesChanged(double, double)));
  102. // Test
  103. QFETCH(double, min);
  104. QFETCH(double, max);
  105. slider.setValues(min, max);
  106. QFETCH(double, expectedMin);
  107. QFETCH(double, expectedMax);
  108. valuesSpy.getSpyReport(expectedMin, expectedMax);
  109. ctkTest::COMPARE(slider.minimumValue(), expectedMin);
  110. ctkTest::COMPARE(slider.maximumValue(), expectedMax);
  111. }
  112. //-----------------------------------------------------------------------------
  113. void ctkDoubleRangeSliderValueProxyTester::testSetValues_data()
  114. {
  115. QTest::addColumn<double>("coefficient");
  116. QTest::addColumn<double>("offset");
  117. QTest::addColumn<double>("min");
  118. QTest::addColumn<double>("expectedMin");
  119. QTest::addColumn<double>("max");
  120. QTest::addColumn<double>("expectedMax");
  121. //---------------------------------------------------------------------------
  122. // Offset
  123. QTest::newRow("Offset only") << 1.0 << 42.19176 << 0.1 << 0.1 << 0.2 << 0.2;
  124. QTest::newRow("Offset only: max+offset < min+offset < -200") << 1.0 << -42.19
  125. << -160.0 << -157.81
  126. << -190.9 << -157.81;
  127. QTest::newRow("Offset only: max+offset < -200 < min+offset") << 1.0 << -42.19
  128. << -0.1 << -157.81
  129. << -160.9 << -0.1;
  130. QTest::newRow("Offset only: -200 < max+offset < min+offset") << 1.0 << 42.19
  131. << -0.1 << -130.9
  132. << -130.9 << -0.1;
  133. QTest::newRow("Offset only: 200 < max+offset < min+offset") << 1.0 << 42.19
  134. << 160.0 << 157.81
  135. << 190.9 << 157.81;
  136. QTest::newRow("Offset only: max+offset < 200 < min+offset") << 1.0 << 42.19
  137. << 160.9 << -0.9
  138. << -0.9 << 157.81;
  139. QTest::newRow("Offset only: max+offset < min+offset < 200") << 1.0 << 42.19
  140. << 130.6 << -13.9
  141. << -13.9 << 130.6;
  142. QTest::newRow("Offset only: 200 < max = max_double = min = max_double")
  143. << 1.0 << 42.19
  144. << std::numeric_limits<double>::max() << 157.81
  145. << std::numeric_limits<double>::max() << 157.81;
  146. QTest::newRow("Offset only: max = -max_double < -200 < 200 < min = max_double")
  147. << 1.0 << 42.19
  148. << std::numeric_limits<double>::max() << -242.19
  149. << -std::numeric_limits<double>::max() << 157.81;
  150. QTest::newRow("Offset only: max = -max_double = min = -max_double < -200")
  151. << 1.0 << 42.19
  152. << - std::numeric_limits<double>::max() << -242.19
  153. << - std::numeric_limits<double>::max() << -242.19;
  154. QTest::newRow("Offset only: 200 < max = infinity = min = infinity")
  155. << 1.0 << 42.19
  156. << std::numeric_limits<double>::infinity() << 157.81
  157. << std::numeric_limits<double>::infinity() << 157.81;
  158. QTest::newRow("Offset only: max = -infinity < -200 < 200 < min = infinity")
  159. << 1.0 << 42.19
  160. << std::numeric_limits<double>::infinity() << -242.19
  161. << -std::numeric_limits<double>::infinity() << 157.81;
  162. QTest::newRow("Offset only: max = -infinity = min = -infinity < -200")
  163. << 1.0 << 42.19
  164. << - std::numeric_limits<double>::infinity() << -242.19
  165. << - std::numeric_limits<double>::infinity() << -242.19;
  166. QTest::newRow("Offset only: max = min = NaN")
  167. << 1.0 << 42.19
  168. << std::numeric_limits<double>::quiet_NaN() << -242.19
  169. << std::numeric_limits<double>::quiet_NaN() << -242.19;
  170. QTest::newRow("Offset only: max = NaN && min > 200")
  171. << 1.0 << 42.19
  172. << 630.0 << -242.19
  173. << std::numeric_limits<double>::quiet_NaN() << 157.81;
  174. QTest::newRow("Offset only: min = NaN && max < -200")
  175. << 1.0 << 42.19
  176. << std::numeric_limits<double>::quiet_NaN() << -242.19
  177. << -794348.12 << -242.19;
  178. //---------------------------------------------------------------------------
  179. // Coefficient
  180. QTest::newRow("Coeff only") << 5.0 << 0.0 << 0.1 << 0.1 << 0.2 << 0.2;
  181. QTest::newRow("Coeff only: max*coeff < min*coeff < -200") << 5.0 << 0.0
  182. << -160.0 << -40.0
  183. << -190.9 << -40.0;
  184. QTest::newRow("Coeff only: max*coeff < -200 < min*coeff") << 5.0 << 0.0
  185. << -0.1 << -40.0
  186. << -160.9 << -0.1;
  187. QTest::newRow("Coeff only: -200 < max*coeff < min*coeff") << 5.0 << 0.0
  188. << -0.1 << -20.9
  189. << -20.9 << -0.1;
  190. QTest::newRow("Coeff only: 200 < max*coeff < min*coeff") << 5.0 << 0.0
  191. << 160.0 << 40.0
  192. << 190.9 << 40.0;
  193. QTest::newRow("Coeff only: max*coeff < 200 < min*coeff") << 5.0 << 0.0
  194. << 160.9 << -0.9
  195. << -0.9 << 40.00;
  196. QTest::newRow("Coeff only: max*coeff < min*coeff < 200") << 5.0 << 0.0
  197. << 13.6 << -13.9
  198. << -13.9 << 13.6;
  199. QTest::newRow("Coeff only: 200 < max = max_double = min = max_double")
  200. << 5.0 << 0.0
  201. << std::numeric_limits<double>::max() << 40.0
  202. << std::numeric_limits<double>::max() << 40.0;
  203. QTest::newRow("Coeff only: max = -max_double < -200 < 200 < min = max_double")
  204. << 5.0 << 0.0
  205. << std::numeric_limits<double>::max() << -40.0
  206. << - std::numeric_limits<double>::max() << 40.0;
  207. QTest::newRow("Coeff only: max = -max_double = min = -max_double < -200")
  208. << 5.0 << 0.0
  209. << -std::numeric_limits<double>::max() << -40.0
  210. << -std::numeric_limits<double>::max() << -40.0;
  211. QTest::newRow("Coeff only: 200 < max = infinity = min = infinity")
  212. << 5.0 << 0.0
  213. << std::numeric_limits<double>::infinity() << 40.0
  214. << std::numeric_limits<double>::infinity() << 40.0;
  215. QTest::newRow("Coeff only: max = -infinity < -200 < 200 < min = infinity")
  216. << 5.0 << 0.0
  217. << std::numeric_limits<double>::infinity() << -40.0
  218. << -std::numeric_limits<double>::infinity() << 40.0;
  219. QTest::newRow("Coeff only: max = -infinity = min = -infinity < -200")
  220. << 5.0 << 0.0
  221. << - std::numeric_limits<double>::infinity() << -40.0
  222. << - std::numeric_limits<double>::infinity() << -40.0;
  223. QTest::newRow("Coeff only: max = min = NaN")
  224. << 5.0 << 0.0
  225. << std::numeric_limits<double>::quiet_NaN() << -40.0
  226. << std::numeric_limits<double>::quiet_NaN() << -40.0;
  227. QTest::newRow("Coeff only: max = NaN && min > 200")
  228. << 5.0 << 0.0
  229. << 630.0 << -40.0
  230. << std::numeric_limits<double>::quiet_NaN() << 40.0;
  231. QTest::newRow("Coeff only: min = NaN && max < -200")
  232. << 5.0 << 0.0
  233. << std::numeric_limits<double>::quiet_NaN() << -40.0
  234. << -794348.12 << -40.0;
  235. //---------------------------------------------------------------------------
  236. // Linear
  237. QTest::newRow("Linear") << 5.0 << 12.0 << 0.1 << 0.1 << 0.2 << 0.2;
  238. QTest::newRow("Linear:f(max) < f(min) < -200") << 5.0 << 12.0
  239. << -160.0 << -42.4
  240. << -190.9 << -42.4;
  241. QTest::newRow("Linear: f(max) < -200 < f(min)") << 5.0 << 12.0
  242. << -0.1 << -42.4
  243. << -160.9 << -0.1;
  244. QTest::newRow("Linear: -200 < f(max) < f(min)") << 5.0 << 12.0
  245. << -0.1 << -20.9
  246. << -20.9 << -0.1;
  247. QTest::newRow("Linear: 200 < f(max) < f(min)") << 5.0 << 12.0
  248. << 160.0 << 37.6
  249. << 190.9 << 37.6;
  250. QTest::newRow("Linear: f(max) < 200 < f(min)") << 5.0 << 12.0
  251. << 160.9 << -0.9
  252. << -0.9 << 37.6;
  253. QTest::newRow("Linear: f(max) < f(min) < 200") << 5.0 << 12.0
  254. << 13.6 << -13.9
  255. << -13.9 << 13.6;
  256. QTest::newRow("Linear: 200 < max = max_double = min = max_double")
  257. << 5.0 << 12.0
  258. << std::numeric_limits<double>::max() << 37.6
  259. << std::numeric_limits<double>::max() << 37.6;
  260. QTest::newRow("Linear: max = -max_double < -200 < 200 < min = max_double")
  261. << 5.0 << 12.0
  262. << std::numeric_limits<double>::max() << -42.4
  263. << - std::numeric_limits<double>::max() << 37.6;
  264. QTest::newRow("Linear: max = -max_double = min = -max_double < -200")
  265. << 5.0 << 12.0
  266. << -std::numeric_limits<double>::max() << -42.4
  267. << -std::numeric_limits<double>::max() << -42.4;
  268. QTest::newRow("Linear: 200 < max = infinity = min = infinity")
  269. << 5.0 << 12.0
  270. << std::numeric_limits<double>::infinity() << 37.6
  271. << std::numeric_limits<double>::infinity() << 37.6;
  272. QTest::newRow("Linear: max = -infinity < -200 < 200 < min = infinity")
  273. << 5.0 << 12.0
  274. << std::numeric_limits<double>::infinity() << -42.4
  275. << -std::numeric_limits<double>::infinity() << 37.6;
  276. QTest::newRow("Linear: max = -infinity = min = -infinity < -200")
  277. << 5.0 << 12.0
  278. << - std::numeric_limits<double>::infinity() << -42.4
  279. << - std::numeric_limits<double>::infinity() << -42.4;
  280. QTest::newRow("Linear: max = min = NaN")
  281. << 5.0 << 12.0
  282. << std::numeric_limits<double>::quiet_NaN() << -42.4
  283. << std::numeric_limits<double>::quiet_NaN() << -42.4;
  284. QTest::newRow("Linear: max = NaN && f(min) > 200")
  285. << 5.0 << 12.0
  286. << 630.0 << -42.4
  287. << std::numeric_limits<double>::quiet_NaN() << 37.6;
  288. QTest::newRow("Linear: min = NaN && f(max) < -200")
  289. << 5.0 << 12.0
  290. << std::numeric_limits<double>::quiet_NaN() << -42.4
  291. << -794348.12 << -42.4;
  292. }
  293. //-----------------------------------------------------------------------------
  294. void ctkDoubleRangeSliderValueProxyTester::testSetMinValue()
  295. {
  296. // Setup
  297. ctkDoubleRangeSlider slider;
  298. slider.setMinimum(-200);
  299. slider.setMaximum(200);
  300. slider.setSingleStep(0.01);
  301. slider.setMinimumValue(-32.6);
  302. QFETCH(double, coefficient);
  303. QFETCH(double, offset);
  304. ctkLinearValueProxy proxy;
  305. proxy.setCoefficient(coefficient);
  306. proxy.setOffset(offset);
  307. slider.setValueProxy(&proxy);
  308. // Spy
  309. QSignalSpy valueSpy(&slider, SIGNAL(minimumValueChanged(double)));
  310. // Test
  311. QFETCH(double, value);
  312. slider.setMinimumValue(value);
  313. QFETCH(double, expectedValue);
  314. getSpyReport(valueSpy, expectedValue);
  315. ctkTest::COMPARE(slider.minimumValue(), expectedValue);
  316. }
  317. //-----------------------------------------------------------------------------
  318. void ctkDoubleRangeSliderValueProxyTester::testSetMaxValue()
  319. {
  320. // Setup
  321. ctkDoubleRangeSlider slider;
  322. slider.setMinimum(-200);
  323. slider.setMaximum(200);
  324. slider.setSingleStep(0.01);
  325. slider.setMaximumValue(-32.6);
  326. QFETCH(double, coefficient);
  327. QFETCH(double, offset);
  328. ctkLinearValueProxy proxy;
  329. proxy.setCoefficient(coefficient);
  330. proxy.setOffset(offset);
  331. slider.setValueProxy(&proxy);
  332. // Spy
  333. QSignalSpy valueSpy(&slider, SIGNAL(maximumValueChanged(double)));
  334. // Test
  335. QFETCH(double, value);
  336. slider.setMaximumValue(value);
  337. QFETCH(double, expectedValue);
  338. getSpyReport(valueSpy, expectedValue);
  339. ctkTest::COMPARE(slider.maximumValue(), expectedValue);
  340. }
  341. //-----------------------------------------------------------------------------
  342. void ctkDoubleRangeSliderValueProxyTester::testSetValueCommonData()
  343. {
  344. QTest::addColumn<double>("coefficient");
  345. QTest::addColumn<double>("offset");
  346. QTest::addColumn<double>("value");
  347. QTest::addColumn<double>("expectedValue");
  348. //---------------------------------------------------------------------------
  349. // Offset
  350. QTest::newRow("Offset only") << 1.0 << 42.19176 << 0.1 << 0.1;
  351. QTest::newRow("Offset only: less than min")
  352. << 1.0 << 42.19 << -510.0 << -242.19;
  353. QTest::newRow("Offset only: less than min but ok with offset")
  354. << 1.0 << 42.19 << -230.0 << -230.0;
  355. QTest::newRow("Offset only: less than min with offset")
  356. << 1.0 << -42.19 << -190.0 << -157.81;
  357. QTest::newRow("Offset only: more than max with offset")
  358. << 1.0 << 42.19 << 160.0 << 157.81;
  359. QTest::newRow("Offset only: more than max")
  360. << 1.0 << -42.19 << 65010.0 << 242.19;
  361. QTest::newRow("Offset only: less than max but ok with offset")
  362. << 1.0 << -42.19 << 229.1 << 229.1;
  363. QTest::newRow("Offset only: max")
  364. << 1.0 << 42.19 << std::numeric_limits<double>::max() << 157.81;
  365. QTest::newRow("Offset only: min")
  366. << 1.0 << 42.19 << -std::numeric_limits<double>::max() << -242.19;
  367. QTest::newRow("Offset only: infinity")
  368. << 1.0 << 42.19 << std::numeric_limits<double>::infinity() << 157.81;
  369. QTest::newRow("Offset only: - infinity")
  370. << 1.0 << 42.19 << -std::numeric_limits<double>::infinity() << -242.19;
  371. QTest::newRow("Offset only: Nan")
  372. << 1.0 << 42.19 << std::numeric_limits<double>::quiet_NaN() << -242.19;
  373. //---------------------------------------------------------------------------
  374. // Coefficient
  375. QTest::newRow("Coeff only") << 5.0 << 0.0 << 0.1 << 0.1;
  376. QTest::newRow("Coeff only: less than min")
  377. << 5.0 << 0.0 << -510.0 << -40.0;
  378. QTest::newRow("Coeff only: less than min but ok with coeff")
  379. << 0.5 << 0.0 << -230.0 << -230.0;
  380. QTest::newRow("Coeff only: less than min with coeff")
  381. << 5.0 << 0.0 << -190.0 << -40.0;
  382. QTest::newRow("Coeff only: more than max with coeff")
  383. << 5.0 << 0.0 << 160.0 << 40.0;
  384. QTest::newRow("Coeff only: more than max")
  385. << 5.0 << 0.0 << 65010.0 << 40.0;
  386. QTest::newRow("Offset only: less than max but ok with coeff")
  387. << 0.5 << 0.0 << 229.2 << 229.2;
  388. QTest::newRow("Coeff only: max")
  389. << 5.0 << 0.0 << std::numeric_limits<double>::max() << 40.0;
  390. QTest::newRow("Coeff only: min")
  391. << 5.0 << 0.0 << -std::numeric_limits<double>::max() << -40.0;
  392. QTest::newRow("Coeff only: infinity")
  393. << 5.0 << 0.0 << std::numeric_limits<double>::infinity() << 40.0;
  394. QTest::newRow("Coeff only: - infinity")
  395. << 5.0 << 0.0 << -std::numeric_limits<double>::infinity() << -40.0;
  396. QTest::newRow("Coeff only: Nan")
  397. << 5.0 << 0.0 << std::numeric_limits<double>::quiet_NaN() << -40.0;
  398. //---------------------------------------------------------------------------
  399. // Linear
  400. QTest::newRow("Linear") << 5.0 << 0.0 << 0.1 << 0.1;
  401. QTest::newRow("Linear: less than min")
  402. << 5.0 << 12.0 << -510.0 << -42.4;
  403. QTest::newRow("Linear: less than min but ok with function")
  404. << 0.5 << 12.0 << -230.0 << -230.0;
  405. QTest::newRow("Linear: less than min with function")
  406. << 5.0 << 12.0 << -61.5 << -42.4;
  407. QTest::newRow("Linear: more than max with function")
  408. << 5.0 << 12.0 << 160.0 << 37.6;
  409. QTest::newRow("Linear: more than max")
  410. << 5.0 << 12.0 << 65010.0 << 37.6;
  411. QTest::newRow("Offset only: less than max but ok with function")
  412. << 0.5 << 12.0 << 229.2 << 229.2;
  413. QTest::newRow("Linear: max")
  414. << 5.0 << 12.0 << std::numeric_limits<double>::max() << 37.6;
  415. QTest::newRow("Linear: min")
  416. << 5.0 << 12.0 << -std::numeric_limits<double>::max() << -42.4;
  417. QTest::newRow("Linear: infinity")
  418. << 5.0 << 12.0 << std::numeric_limits<double>::infinity() << 37.6;
  419. QTest::newRow("Linear: - infinity")
  420. << 5.0 << 12.0 << -std::numeric_limits<double>::infinity() << -42.4;
  421. QTest::newRow("Linear: Nan")
  422. << 5.0 << 12.0 << std::numeric_limits<double>::quiet_NaN() << -42.4;
  423. }
  424. //-----------------------------------------------------------------------------
  425. void ctkDoubleRangeSliderValueProxyTester::testSetMinPosition()
  426. {
  427. // Setup
  428. ctkDoubleRangeSlider slider;
  429. slider.setMinimum(-200);
  430. slider.setMaximum(200);
  431. slider.setSingleStep(0.01);
  432. slider.setMinimumValue(-32.6);
  433. QFETCH(double, coefficient);
  434. QFETCH(double, offset);
  435. ctkLinearValueProxy proxy;
  436. proxy.setCoefficient(coefficient);
  437. proxy.setOffset(offset);
  438. slider.setValueProxy(&proxy);
  439. // Spy
  440. QSignalSpy valueSpy(&slider, SIGNAL(minimumValueChanged(double)));
  441. // Test
  442. QFETCH(double, sliderPosition);
  443. slider.setMinimumPosition(sliderPosition);
  444. QFETCH(double, expectedSliderPosition);
  445. QFETCH(double, expectedValue);
  446. getSpyReport(valueSpy, expectedValue);
  447. ctkTest::COMPARE(slider.minimumValue(), expectedValue);
  448. ctkTest::COMPARE(slider.minimumPosition(), expectedSliderPosition);
  449. }
  450. //-----------------------------------------------------------------------------
  451. void ctkDoubleRangeSliderValueProxyTester::testSetMaxPosition()
  452. {
  453. // Setup
  454. ctkDoubleRangeSlider slider;
  455. slider.setMinimum(-200);
  456. slider.setMaximum(200);
  457. slider.setSingleStep(0.01);
  458. slider.setMaximumValue(-32.6);
  459. QFETCH(double, coefficient);
  460. QFETCH(double, offset);
  461. ctkLinearValueProxy proxy;
  462. proxy.setCoefficient(coefficient);
  463. proxy.setOffset(offset);
  464. slider.setValueProxy(&proxy);
  465. // Spy
  466. QSignalSpy valueSpy(&slider, SIGNAL(maximumValueChanged(double)));
  467. // Test
  468. QFETCH(double, sliderPosition);
  469. slider.setMaximumPosition(sliderPosition);
  470. QFETCH(double, expectedSliderPosition);
  471. QFETCH(double, expectedValue);
  472. getSpyReport(valueSpy, expectedValue);
  473. ctkTest::COMPARE(slider.maximumValue(), expectedValue);
  474. ctkTest::COMPARE(slider.maximumPosition(), expectedSliderPosition);
  475. }
  476. //-----------------------------------------------------------------------------
  477. void ctkDoubleRangeSliderValueProxyTester::testSetPositionCommonData()
  478. {
  479. QTest::addColumn<double>("coefficient");
  480. QTest::addColumn<double>("offset");
  481. QTest::addColumn<double>("sliderPosition");
  482. QTest::addColumn<double>("expectedValue");
  483. QTest::addColumn<double>("expectedSliderPosition");
  484. //---------------------------------------------------------------------------
  485. // Offset
  486. QTest::newRow("Offset only") << 1.0 << 42.19 << 0.1 << -42.09 << 0.1;
  487. QTest::newRow("Offset only: less than min")
  488. << 1.0 << 42.19 << -510.0 << -242.19 << -200.0;
  489. QTest::newRow("Offset only: more than max")
  490. << 1.0 << -42.19 << 65010.0 << 242.19 << 200.0;
  491. QTest::newRow("Offset only: max")
  492. << 1.0 << 42.19 << std::numeric_limits<double>::max()
  493. << 157.81 << 200.0;
  494. QTest::newRow("Offset only: min")
  495. << 1.0 << 42.19 << -std::numeric_limits<double>::max()
  496. << -242.19 << -200.0;
  497. QTest::newRow("Offset only: infinity")
  498. << 1.0 << 42.19 << std::numeric_limits<double>::infinity()
  499. << 157.81 << 200.0;
  500. QTest::newRow("Offset only: - infinity")
  501. << 1.0 << 42.19 << -std::numeric_limits<double>::infinity()
  502. << -242.19 << -200.0;
  503. QTest::newRow("Offset only: Nan")
  504. << 1.0 << 42.19 << std::numeric_limits<double>::quiet_NaN()
  505. << -242.19 << -200.0;
  506. //---------------------------------------------------------------------------
  507. // Coefficient
  508. QTest::newRow("Coeff only") << 5.0 << 0.0 << 5.0 << 1.0 << 5.0;
  509. QTest::newRow("Coeff only: less than min")
  510. << 5.0 << 0.0 << -1010.0 << -40.0 << -200.0;
  511. QTest::newRow("Coeff only: more than max")
  512. << 5.0 << 0.0 << 65010.0 << 40.0 << 200.0;
  513. QTest::newRow("Coeff only: max")
  514. << 5.0 << 0.0 << std::numeric_limits<double>::max() << 40.0 << 200.0;
  515. QTest::newRow("Coeff only: min")
  516. << 5.0 << 0.0 << -std::numeric_limits<double>::max() << -40.0 << -200.0;
  517. QTest::newRow("Coeff only: infinity")
  518. << 5.0 << 0.0 << std::numeric_limits<double>::infinity() << 40.0 << 200.0;
  519. QTest::newRow("Coeff only: - infinity")
  520. << 5.0 << 0.0 << -std::numeric_limits<double>::infinity()
  521. << -40.0 << -200.0;
  522. QTest::newRow("Coeff only: Nan")
  523. << 5.0 << 0.0 << std::numeric_limits<double>::quiet_NaN()
  524. << -40.0 << -200.0;
  525. //---------------------------------------------------------------------------
  526. // Linear
  527. QTest::newRow("Linear") << 5.0 << 12.0 << 42.0 << 6.0 << 42.0;
  528. QTest::newRow("Linear: less than min")
  529. << 5.0 << 12.0 << -5010.0 << -42.4 << -200.0;
  530. QTest::newRow("Linear: more than max")
  531. << 5.0 << 12.0 << 65010.0 << 37.6 << 200.0;
  532. QTest::newRow("Linear: max")
  533. << 5.0 << 12.0 << std::numeric_limits<double>::max() << 37.6 << 200.0;
  534. QTest::newRow("Linear: min")
  535. << 5.0 << 12.0 << -std::numeric_limits<double>::max() << -42.4 << -200.0;
  536. QTest::newRow("Linear: infinity")
  537. << 5.0 << 12.0 << std::numeric_limits<double>::infinity() << 37.6 << 200.0;
  538. QTest::newRow("Linear: - infinity")
  539. << 5.0 << 12.0 << -std::numeric_limits<double>::infinity()
  540. << -42.4 << -200.0;
  541. QTest::newRow("Linear: Nan")
  542. << 5.0 << 12.0 << std::numeric_limits<double>::quiet_NaN()
  543. << -42.4 << -200.0;
  544. }
  545. // ----------------------------------------------------------------------------
  546. CTK_TEST_MAIN(ctkDoubleRangeSliderValueProxyTest)
  547. #include "moc_ctkDoubleRangeSliderValueProxyTest.cpp"