on xenial help sign in
Carousel: Add test to make sure we only create the needed delegates and not more
f69160aAlbert Astals
qml/Components/Carousel.qml+69−63
@@ -261,77 +261,83 @@ Item {
261 listView.gapToEndPhase,
261 listView.gapToEndPhase,
262 listView.translationXViewFactor)
262 listView.translationXViewFactor)
263
263
264+ delegate: tileWidth > 0 && tileHeight > 0 ? loaderComponent : undefined
265+
266+ Component {
267+ id: loaderComponent
268+
264− delegate: Loader {
269+ Loader {
265− property bool explicitlyScaled: explicitScaleFactor == carousel.selectedItemScaleFactor
270+ property bool explicitlyScaled: explicitScaleFactor == carousel.selectedItemScaleFactor
266− property real explicitScaleFactor: explicitScale ? carousel.selectedItemScaleFactor : 1.0
271+ property real explicitScaleFactor: explicitScale ? carousel.selectedItemScaleFactor : 1.0
267− readonly property bool explicitScale: (!listView.moving ||
272+ readonly property bool explicitScale: (!listView.moving ||
268− listView.realContentX <= 0 ||
273+ listView.realContentX <= 0 ||
269− listView.realContentX >= listView.realContentWidth - listView.realWidth) &&
274+ listView.realContentX >= listView.realContentWidth - listView.realWidth) &&
270− listView.newContentX === listView.disabledNewContentX &&
275+ listView.newContentX === listView.disabledNewContentX &&
271− index === listView.selectedIndex
276+ index === listView.selectedIndex
272− readonly property real cachedTiles: listView.realPathItemCount + carousel.drawBuffer / listView.tileWidth
277+ readonly property real cachedTiles: listView.realPathItemCount + carousel.drawBuffer / listView.tileWidth
273− readonly property real distance: listView.continuousIndex - index
278+ readonly property real distance: listView.continuousIndex - index
274− readonly property real itemTranslationScale: CarouselJS.getItemScale(0.5,
279+ readonly property real itemTranslationScale: CarouselJS.getItemScale(0.5,
275− (index + 0.5), // good approximation of scale while changing selected item
280+ (index + 0.5), // good approximation of scale while changing selected item
276− listView.count,
281+ listView.count,
277− listView.visibleTilesScaleFactor)
282+ listView.visibleTilesScaleFactor)
278− readonly property real itemScale: CarouselJS.getItemScale(distance,
283+ readonly property real itemScale: CarouselJS.getItemScale(distance,
279− listView.continuousIndex,
284+ listView.continuousIndex,
280− listView.count,
285+ listView.count,
281− listView.visibleTilesScaleFactor)
286+ listView.visibleTilesScaleFactor)
282− readonly property real translationX: CarouselJS.getItemTranslation(index,
287+ readonly property real translationX: CarouselJS.getItemTranslation(index,
283− listView.selectedIndex,
288+ listView.selectedIndex,
284− distance,
289+ distance,
285− itemScale,
290+ itemScale,
286− itemTranslationScale,
291+ itemTranslationScale,
287− listView.maximumItemTranslation)
292+ listView.maximumItemTranslation)
288−
293+
289− readonly property real xTransform: listView.viewTranslation + translationX * listView.scaleFactor
294+ readonly property real xTransform: listView.viewTranslation + translationX * listView.scaleFactor
290− readonly property real center: x - listView.contentX + xTransform - drawBuffer + (width/2)
295+ readonly property real center: x - listView.contentX + xTransform - drawBuffer + (width/2)
291−
296+
292− width: listView.tileWidth
297+ width: listView.tileWidth
293− height: listView.tileHeight
298+ height: listView.tileHeight
294− scale: itemScale * explicitScaleFactor
299+ scale: itemScale * explicitScaleFactor
295− sourceComponent: itemComponent
300+ sourceComponent: itemComponent
296− z: cachedTiles - Math.abs(index - listView.selectedIndex)
301+ z: cachedTiles - Math.abs(index - listView.selectedIndex)
297−
302+
298− transform: Translate {
303+ transform: Translate {
299− x: xTransform
304+ x: xTransform
300− }
305+ }
301
306
302− Behavior on explicitScaleFactor {
307+ Behavior on explicitScaleFactor {
303− SequentialAnimation {
308+ SequentialAnimation {
304− ScriptAction {
309+ ScriptAction {
305− script: if (!explicitScale)
310+ script: if (!explicitScale)
306− explicitlyScaled = false
311+ explicitlyScaled = false
307− }
312+ }
308− NumberAnimation {
313+ NumberAnimation {
309− duration: explicitScaleFactor === 1.0 ? 250 : 150
314+ duration: explicitScaleFactor === 1.0 ? 250 : 150
310− easing.type: Easing.InOutQuad
315+ easing.type: Easing.InOutQuad
311− }
316+ }
312− ScriptAction {
317+ ScriptAction {
313− script: if (explicitScale)
318+ script: if (explicitScale)
314− explicitlyScaled = true
319+ explicitlyScaled = true
320+ }
315 }
321 }
316 }
322 }
317− }
318
323
319− onLoaded: {
324+ onLoaded: {
320− item.explicitlyScaled = Qt.binding(function() { return explicitlyScaled; })
325+ item.explicitlyScaled = Qt.binding(function() { return explicitlyScaled; })
321− item.model = Qt.binding(function() { return model; })
326+ item.model = Qt.binding(function() { return model; })
322− }
327+ }
323
328
324− MouseArea {
329+ MouseArea {
325− id: mouseArea
330+ id: mouseArea
326
331
327− anchors.fill: parent
332+ anchors.fill: parent
328
333
329− onClicked: {
334+ onClicked: {
330− listView.itemClicked(index, item)
335+ listView.itemClicked(index, item)
331− }
336+ }
332
337
333− onPressAndHold: {
338+ onPressAndHold: {
334− listView.itemPressAndHold(index, item)
339+ listView.itemPressAndHold(index, item)
340+ }
335 }
341 }
336 }
342 }
337 }
343 }
tests/qmltests/CMakeLists.txt+1−1
@@ -12,7 +12,6 @@ set(qmltest_DEFAULT_TARGETS qmlunittests)
12set(qmltest_DEFAULT_NO_ADD_TEST FALSE)
12set(qmltest_DEFAULT_NO_ADD_TEST FALSE)
13set(qmltest_DEFAULT_PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=minimal")
13set(qmltest_DEFAULT_PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=minimal")
14add_qml_test(Components AnimationControllerWithSignals)
14add_qml_test(Components AnimationControllerWithSignals)
15−add_qml_test(Components Carousel)
16add_qml_test(Panel IndicatorItem)
15add_qml_test(Panel IndicatorItem)
17add_qml_test(utils/Unity/Test UnityTest)
16add_qml_test(utils/Unity/Test UnityTest)
18
17
@@ -23,6 +22,7 @@ set(qmltest_DEFAULT_PROPERTIES "")
23add_qml_test(. Shell IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks
22add_qml_test(. Shell IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/tests/mocks
24 ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
23 ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
25add_manual_qml_test(Components DragHandle IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins)
24add_manual_qml_test(Components DragHandle IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins)
25+add_qml_test(Components Carousel)
26add_qml_test(Components DraggingArea)
26add_qml_test(Components DraggingArea)
27add_qml_test(Components EdgeDemoOverlay)
27add_qml_test(Components EdgeDemoOverlay)
28add_qml_test(Components FilterGrid IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins)
28add_qml_test(Components FilterGrid IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins)
tests/qmltests/Components/tst_Carousel.qml+194−168
@@ -16,179 +16,205 @@
16
16
17import QtQuick 2.0
17import QtQuick 2.0
18import QtTest 1.0
18import QtTest 1.0
19+import "../../../qml/Components/"
19import "../../../qml/Components/carousel.js" as Carousel
20import "../../../qml/Components/carousel.js" as Carousel
20
21
21−TestCase {
22+Item {
22− id: root
23+ width: 700
23− name: "Carousel"
24+ height: 400
24−
25− property real carouselWidth
26− property int itemCount
27− property real tileWidth
28−
29− property real contentWidth: itemCount * tileWidth
30− // following variables are copied from Carousel.qml
31− // I'm not using the variables directly from there, as then tileWidth and others would be affected as well
32− property real gapToMiddlePhase: Math.min(carouselWidth / 2 - tileWidth / 2, (contentWidth - carouselWidth) / 2)
33− property real gapToEndPhase: contentWidth - carouselWidth - gapToMiddlePhase
34− property real kMiddleIndex: (carouselWidth / 2) / tileWidth - 0.5
35− property real kGapEnd: kMiddleIndex * (1 - gapToEndPhase / gapToMiddlePhase)
36− property real kXBeginningEnd: 1 / tileWidth + kMiddleIndex / gapToMiddlePhase
37−
38− // test for the getContinuousIndex() function
39− function test_getContinuousIndex_data() {
40− // testing for 10 items of size 100 pixel
41− return [ {tag:"at start",
42− x: 0, carouselWidth:400, tileWidth:100, itemCount:10, result: 0},
43− {tag:"in startup",
44− x: 100, carouselWidth:400, tileWidth:100, itemCount:10, result: 2},
45− {tag:"in the middle",
46− x: 350, carouselWidth:400, tileWidth:100, itemCount:10, result: 5},
47− {tag:"at end",
48− x: 600, carouselWidth:400, tileWidth:100, itemCount:10, result: 9},
49− ]
50− }
51
25
52− function test_getContinuousIndex(data) {
26+ Carousel {
53− root.carouselWidth = data.carouselWidth
27+ anchors.fill: parent
54− root.tileWidth = data.tileWidth
28+ id: carousel
55− root.itemCount = data.itemCount
29+ model: 40
56
30
57− var index = Carousel.getContinuousIndex(data.x,
31+ property int createdDelegates: 0
58− data.tileWidth,
32+ property int destroyedDelegates: 0
59− gapToMiddlePhase,
60− gapToEndPhase,
61− kGapEnd,
62− kMiddleIndex,
63− kXBeginningEnd)
64− compare(index, data.result)
65− }
66−
67− // test for the getXFromContinuousIndex() function
68− function test_getXFromContinuousIndex_data() {
69− return [ {tag:"at start",
70− index: 0, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 0},
71− {tag:"in startup",
72− index: 2, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 100},
73− {tag:"in startup with drawBuffer",
74− index: 2, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 0},
75− {tag:"in the middle",
76− index: 5, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 350},
77− {tag:"in the middle with drawBuffer",
78− index: 5, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 250},
79− {tag:"at end",
80− index: 9, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 600},
81− {tag:"at end with drawBuffer",
82− index: 9, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 500},
83− ]
84− }
85−
86− function test_getXFromContinuousIndex(data) {
87− root.carouselWidth = data.carouselWidth
88− root.tileWidth = data.tileWidth
89− root.itemCount = data.itemCount
90−
91− var x = Carousel.getXFromContinuousIndex(data.index,
92− data.carouselWidth,
93− contentWidth,
94− data.tileWidth,
95− gapToMiddlePhase,
96− gapToEndPhase,
97− data.drawBuffer)
98− compare(x, data.result)
99− }
100−
101− // test for the getViewTranslation() function
102− function test_getViewTranslation_data() {
103− return [ {tag:"at start - viewfactor 1",
104− x: 0, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: 150},
105− {tag:"at start - viewfactor 2",
106− x: 0, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:2, result: 300},
107− {tag:"in startup",
108− x: 100, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: 50},
109− {tag:"in the middle",
110− x: 350, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: 0},
111− {tag:"at end",
112− x: 600, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: -150},
113− ]
114− }
115
33
116− function test_getViewTranslation(data) {
34+ itemComponent: Rectangle {
117− root.carouselWidth = data.carouselWidth
35+ color: "red"
118− root.tileWidth = data.tileWidth
36+ Component.onCompleted: carousel.createdDelegates++
119− root.itemCount = data.itemCount
37+ Component.onDestruction: carousel.destroyedDelegates++
120−
38+ }
121− var x = Carousel.getViewTranslation(data.x,
122− data.tileWidth,
123− root.gapToMiddlePhase,
124− root.gapToEndPhase,
125− data.translationXViewFactor)
126− compare(x, data.result)
127 }
39 }
128−
40+ TestCase {
41+ id: root
42+ name: "Carousel"
43+ when: windowShown
44+
45+ property real carouselWidth
46+ property int itemCount
47+ property real tileWidth
48+
49+ property real contentWidth: itemCount * tileWidth
50+ // following variables are copied from Carousel.qml
51+ // I'm not using the variables directly from there, as then tileWidth and others would be affected as well
52+ property real gapToMiddlePhase: Math.min(carouselWidth / 2 - tileWidth / 2, (contentWidth - carouselWidth) / 2)
53+ property real gapToEndPhase: contentWidth - carouselWidth - gapToMiddlePhase
54+ property real kMiddleIndex: (carouselWidth / 2) / tileWidth - 0.5
55+ property real kGapEnd: kMiddleIndex * (1 - gapToEndPhase / gapToMiddlePhase)
56+ property real kXBeginningEnd: 1 / tileWidth + kMiddleIndex / gapToMiddlePhase
57+
58+ function test_onlyNeededItemsCreated() {
59+ compare(carousel.createdDelegates, 10);
60+ compare(carousel.destroyedDelegates, 0);
61+ }
62+
63+ // test for the getContinuousIndex() function
64+ function test_getContinuousIndex_data() {
65+ // testing for 10 items of size 100 pixel
66+ return [ {tag:"at start",
67+ x: 0, carouselWidth:400, tileWidth:100, itemCount:10, result: 0},
68+ {tag:"in startup",
69+ x: 100, carouselWidth:400, tileWidth:100, itemCount:10, result: 2},
70+ {tag:"in the middle",
71+ x: 350, carouselWidth:400, tileWidth:100, itemCount:10, result: 5},
72+ {tag:"at end",
73+ x: 600, carouselWidth:400, tileWidth:100, itemCount:10, result: 9},
74+ ]
75+ }
76+
77+ function test_getContinuousIndex(data) {
78+ root.carouselWidth = data.carouselWidth
79+ root.tileWidth = data.tileWidth
80+ root.itemCount = data.itemCount
81+
82+ var index = Carousel.getContinuousIndex(data.x,
83+ data.tileWidth,
84+ gapToMiddlePhase,
85+ gapToEndPhase,
86+ kGapEnd,
87+ kMiddleIndex,
88+ kXBeginningEnd)
89+ compare(index, data.result)
90+ }
91+
92+ // test for the getXFromContinuousIndex() function
93+ function test_getXFromContinuousIndex_data() {
94+ return [ {tag:"at start",
95+ index: 0, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 0},
96+ {tag:"in startup",
97+ index: 2, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 100},
98+ {tag:"in startup with drawBuffer",
99+ index: 2, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 0},
100+ {tag:"in the middle",
101+ index: 5, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 350},
102+ {tag:"in the middle with drawBuffer",
103+ index: 5, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 250},
104+ {tag:"at end",
105+ index: 9, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 600},
106+ {tag:"at end with drawBuffer",
107+ index: 9, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 500},
108+ ]
109+ }
110+
111+ function test_getXFromContinuousIndex(data) {
112+ root.carouselWidth = data.carouselWidth
113+ root.tileWidth = data.tileWidth
114+ root.itemCount = data.itemCount
115+
116+ var x = Carousel.getXFromContinuousIndex(data.index,
117+ data.carouselWidth,
118+ contentWidth,
119+ data.tileWidth,
120+ gapToMiddlePhase,
121+ gapToEndPhase,
122+ data.drawBuffer)
123+ compare(x, data.result)
124+ }
125+
126+ // test for the getViewTranslation() function
127+ function test_getViewTranslation_data() {
128+ return [ {tag:"at start - viewfactor 1",
129+ x: 0, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: 150},
130+ {tag:"at start - viewfactor 2",
131+ x: 0, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:2, result: 300},
132+ {tag:"in startup",
133+ x: 100, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: 50},
134+ {tag:"in the middle",
135+ x: 350, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: 0},
136+ {tag:"at end",
137+ x: 600, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: -150},
138+ ]
139+ }
140+
141+ function test_getViewTranslation(data) {
142+ root.carouselWidth = data.carouselWidth
143+ root.tileWidth = data.tileWidth
144+ root.itemCount = data.itemCount
145+
146+ var x = Carousel.getViewTranslation(data.x,
147+ data.tileWidth,
148+ root.gapToMiddlePhase,
149+ root.gapToEndPhase,
150+ data.translationXViewFactor)
151+ compare(x, data.result)
152+ }
153+
129− // test for the getItemScale() function
154+ // test for the getItemScale() function
130− function test_getItemScale_data() {
155+ function test_getItemScale_data() {
131− return [ // tests for distance
156+ return [ // tests for distance
132− {distance: 0, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 1},
157+ {distance: 0, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 1},
133− {distance: 9, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.01},
158+ {distance: 9, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.01},
134− {distance: 999, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.01},
159+ {distance: 999, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.01},
135− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
160+ {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
136− {distance: 3, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.688230855}, // = 1 - (3^2.5 / 50)
161+ {distance: 3, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.688230855}, // = 1 - (3^2.5 / 50)
137− // tests for continuousIndex
162+ // tests for continuousIndex
138− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
163+ {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
139− {distance: 1, continuousIndex: 97, numberOfItems: 100, scaleFactor: 1, result: 0.99}, // = 1 - (1 / 100) - distanceToBounds is used
164+ {distance: 1, continuousIndex: 97, numberOfItems: 100, scaleFactor: 1, result: 0.99}, // = 1 - (1 / 100) - distanceToBounds is used
140− // tests for numberOfItems
165+ // tests for numberOfItems
141− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
166+ {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
142− {distance: 1, continuousIndex: 50, numberOfItems: 53, scaleFactor: 1, result: 0.99}, // = 1 - (1 / 100) - distanceToBounds is used
167+ {distance: 1, continuousIndex: 50, numberOfItems: 53, scaleFactor: 1, result: 0.99}, // = 1 - (1 / 100) - distanceToBounds is used
143− // tests for scaleFactor
168+ // tests for scaleFactor
144− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
169+ {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
145− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 2, result: 0.99}, // = 1 - (1 / 100)
170+ {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 2, result: 0.99}, // = 1 - (1 / 100)
146− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 0.5, result: 0.96}, // = 1 - (1 / 25)
171+ {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 0.5, result: 0.96}, // = 1 - (1 / 25)
147− {distance: 1, continuousIndex: 50, numberOfItems: 53, scaleFactor: 1, result: 0.99}, // = 1 - (1 / 100) - distanceToBounds is used
172+ {distance: 1, continuousIndex: 50, numberOfItems: 53, scaleFactor: 1, result: 0.99}, // = 1 - (1 / 100) - distanceToBounds is used
148− {distance: 1, continuousIndex: 50, numberOfItems: 53, scaleFactor: 2, result: 0.996666666}, // = 1 - (1 / 300) - distanceToBounds is used
173+ {distance: 1, continuousIndex: 50, numberOfItems: 53, scaleFactor: 2, result: 0.996666666}, // = 1 - (1 / 300) - distanceToBounds is used
149− ]
174+ ]
150− }
175+ }
151−
176+
152− function test_getItemScale(data) {
177+ function test_getItemScale(data) {
153− var scale = Carousel.getItemScale(data.distance,
178+ var scale = Carousel.getItemScale(data.distance,
154− data.continuousIndex,
179+ data.continuousIndex,
155− data.numberOfItems,
180+ data.numberOfItems,
156− data.scaleFactor)
181+ data.scaleFactor)
157− compare(scale, data.result)
182+ compare(scale, data.result)
158− }
183+ }
159−
184+
160− // test for the getItemTranslation() function
185+ // test for the getItemTranslation() function
161− function test_getItemTranslation_data() {
186+ function test_getItemTranslation_data() {
162− return [ // tests for index and selectedIndex
187+ return [ // tests for index and selectedIndex
163− {index: 1, selectedIndex: 1, distance: 1, scale: 1, maxScale: 1, maxTranslation: 10, result: 0},
188+ {index: 1, selectedIndex: 1, distance: 1, scale: 1, maxScale: 1, maxTranslation: 10, result: 0},
164− // tests if distance only affects the sign
189+ // tests if distance only affects the sign
165− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
190+ {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
166− {index: 1, selectedIndex: 2, distance: 99, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
191+ {index: 1, selectedIndex: 2, distance: 99, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
167− {index: 1, selectedIndex: 2, distance: -1, scale: 0, maxScale: 1, maxTranslation: 10, result: -10},
192+ {index: 1, selectedIndex: 2, distance: -1, scale: 0, maxScale: 1, maxTranslation: 10, result: -10},
168− {index: 1, selectedIndex: 2, distance: -99, scale: 0, maxScale: 1, maxTranslation: 10, result: -10},
193+ {index: 1, selectedIndex: 2, distance: -99, scale: 0, maxScale: 1, maxTranslation: 10, result: -10},
169− // tests for the scale
194+ // tests for the scale
170− {index: 1, selectedIndex: 2, distance: 1, scale: 1, maxScale: 1, maxTranslation: 10, result: 0},
195+ {index: 1, selectedIndex: 2, distance: 1, scale: 1, maxScale: 1, maxTranslation: 10, result: 0},
171− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
196+ {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
172− {index: 1, selectedIndex: 2, distance: 1, scale: 0.5, maxScale: 1, maxTranslation: 10, result: 5},
197+ {index: 1, selectedIndex: 2, distance: 1, scale: 0.5, maxScale: 1, maxTranslation: 10, result: 5},
173− // tests for maxScale
198+ // tests for maxScale
174− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 0.98, maxTranslation: 10, result: 9.8},
199+ {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 0.98, maxTranslation: 10, result: 9.8},
175− {index: 1, selectedIndex: 2, distance: 1, scale: 0.5, maxScale: 0.95, maxTranslation: 10, result: 4.5},
200+ {index: 1, selectedIndex: 2, distance: 1, scale: 0.5, maxScale: 0.95, maxTranslation: 10, result: 4.5},
176− {index: 1, selectedIndex: 2, distance: 1, scale: 0.8, maxScale: 0.93, maxTranslation: 10, result: 1.3},
201+ {index: 1, selectedIndex: 2, distance: 1, scale: 0.8, maxScale: 0.93, maxTranslation: 10, result: 1.3},
177− // test for maxTranslation
202+ // test for maxTranslation
178− {index: 1, selectedIndex: 2, distance: 1, scale: 1, maxScale: 1, maxTranslation: 1, result: 0},
203+ {index: 1, selectedIndex: 2, distance: 1, scale: 1, maxScale: 1, maxTranslation: 1, result: 0},
179− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 1, result: 1},
204+ {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 1, result: 1},
180− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
205+ {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
181− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 0, result: 0},
206+ {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 0, result: 0},
182− ]
207+ ]
183− }
208+ }
184−
209+
185− function test_getItemTranslation(data) {
210+ function test_getItemTranslation(data) {
186− var scale = Carousel.getItemTranslation(data.index,
211+ var scale = Carousel.getItemTranslation(data.index,
187− data.selectedIndex,
212+ data.selectedIndex,
188− data.distance,
213+ data.distance,
189− data.scale,
214+ data.scale,
190− data.maxScale,
215+ data.maxScale,
191− data.maxTranslation)
216+ data.maxTranslation)
192− compare(scale, data.result)
217+ compare(scale, data.result)
218+ }
193 }
219 }
194}
220}