@@ -36,185 +36,185 @@ Item {
36 Component.onCompleted: carousel.createdDelegates++
36 Component.onCompleted: carousel.createdDelegates++
37 Component.onDestruction: carousel.destroyedDelegates++
37 Component.onDestruction: carousel.destroyedDelegates++
39− TestCase {
40+ TestCase {
41− name: "Carousel"
42+ name: "Carousel"
42− when: windowShown
43+ when: windowShown
44− property real carouselWidth
45+ property real carouselWidth
45− property int itemCount
46+ property int itemCount
46− property real tileWidth
47+ property real tileWidth
48− property real contentWidth: itemCount * tileWidth
49+ property real contentWidth: itemCount * tileWidth
49− // following variables are copied from Carousel.qml
50+ // following variables are copied from Carousel.qml
50− // I'm not using the variables directly from there, as then tileWidth and others would be affected as well
51+ // I'm not using the variables directly from there, as then tileWidth and others would be affected as well
51− property real gapToMiddlePhase: Math.min(carouselWidth / 2 - tileWidth / 2, (contentWidth - carouselWidth) / 2)
52+ property real gapToMiddlePhase: Math.min(carouselWidth / 2 - tileWidth / 2, (contentWidth - carouselWidth) / 2)
52− property real gapToEndPhase: contentWidth - carouselWidth - gapToMiddlePhase
53+ property real gapToEndPhase: contentWidth - carouselWidth - gapToMiddlePhase
53− property real kMiddleIndex: (carouselWidth / 2) / tileWidth - 0.5
54+ property real kMiddleIndex: (carouselWidth / 2) / tileWidth - 0.5
54− property real kGapEnd: kMiddleIndex * (1 - gapToEndPhase / gapToMiddlePhase)
55+ property real kGapEnd: kMiddleIndex * (1 - gapToEndPhase / gapToMiddlePhase)
55− property real kXBeginningEnd: 1 / tileWidth + kMiddleIndex / gapToMiddlePhase
56+ property real kXBeginningEnd: 1 / tileWidth + kMiddleIndex / gapToMiddlePhase
57− function test_onlyNeededItemsCreated() {
58+ function test_onlyNeededItemsCreated() {
58− compare(carousel.createdDelegates, 10);
59+ compare(carousel.createdDelegates, 10);
59− compare(carousel.destroyedDelegates, 0);
60+ compare(carousel.destroyedDelegates, 0);
62− // test for the getContinuousIndex() function
63+ // test for the getContinuousIndex() function
63− function test_getContinuousIndex_data() {
64+ function test_getContinuousIndex_data() {
64− // testing for 10 items of size 100 pixel
65+ // testing for 10 items of size 100 pixel
65− return [ {tag:"at start",
66+ return [ {tag:"at start",
66− x: 0, carouselWidth:400, tileWidth:100, itemCount:10, result: 0},
67+ x: 0, carouselWidth:400, tileWidth:100, itemCount:10, result: 0},
67− {tag:"in startup",
68+ {tag:"in startup",
68− x: 100, carouselWidth:400, tileWidth:100, itemCount:10, result: 2},
69+ x: 100, carouselWidth:400, tileWidth:100, itemCount:10, result: 2},
69− {tag:"in the middle",
70+ {tag:"in the middle",
70− x: 350, carouselWidth:400, tileWidth:100, itemCount:10, result: 5},
71+ x: 350, carouselWidth:400, tileWidth:100, itemCount:10, result: 5},
71− {tag:"at end",
72+ {tag:"at end",
72− x: 600, carouselWidth:400, tileWidth:100, itemCount:10, result: 9},
73+ x: 600, carouselWidth:400, tileWidth:100, itemCount:10, result: 9},
76− function test_getContinuousIndex(data) {
77+ function test_getContinuousIndex(data) {
77− root.carouselWidth = data.carouselWidth
78+ root.carouselWidth = data.carouselWidth
78− root.tileWidth = data.tileWidth
79+ root.tileWidth = data.tileWidth
79− root.itemCount = data.itemCount
80+ root.itemCount = data.itemCount
81− var index = Carousel.getContinuousIndex(data.x,
82+ var index = Carousel.getContinuousIndex(data.x,
82− data.tileWidth,
83+ data.tileWidth,
83− gapToMiddlePhase,
84+ gapToMiddlePhase,
84− gapToEndPhase,
85+ gapToEndPhase,
86− kMiddleIndex,
87+ kMiddleIndex,
87− kXBeginningEnd)
88+ kXBeginningEnd)
88− compare(index, data.result)
89+ compare(index, data.result)
91− // test for the getXFromContinuousIndex() function
92+ // test for the getXFromContinuousIndex() function
92− function test_getXFromContinuousIndex_data() {
93+ function test_getXFromContinuousIndex_data() {
93− return [ {tag:"at start",
94+ return [ {tag:"at start",
94− index: 0, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 0},
95+ index: 0, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 0},
95− {tag:"in startup",
96+ {tag:"in startup",
96− index: 2, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 100},
97+ index: 2, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 100},
97− {tag:"in startup with drawBuffer",
98+ {tag:"in startup with drawBuffer",
98− index: 2, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 0},
99+ index: 2, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 0},
99− {tag:"in the middle",
100+ {tag:"in the middle",
100− index: 5, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 350},
101+ index: 5, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 350},
101− {tag:"in the middle with drawBuffer",
102+ {tag:"in the middle with drawBuffer",
102− index: 5, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 250},
103+ index: 5, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 250},
103− {tag:"at end",
104+ {tag:"at end",
104− index: 9, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 600},
105+ index: 9, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 600},
105− {tag:"at end with drawBuffer",
106+ {tag:"at end with drawBuffer",
106− index: 9, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 500},
107+ index: 9, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 500},
110− function test_getXFromContinuousIndex(data) {
111+ function test_getXFromContinuousIndex(data) {
111− root.carouselWidth = data.carouselWidth
112+ root.carouselWidth = data.carouselWidth
112− root.tileWidth = data.tileWidth
113+ root.tileWidth = data.tileWidth
113− root.itemCount = data.itemCount
114+ root.itemCount = data.itemCount
115− var x = Carousel.getXFromContinuousIndex(data.index,
116+ var x = Carousel.getXFromContinuousIndex(data.index,
116− data.carouselWidth,
117+ data.carouselWidth,
117− contentWidth,
118+ contentWidth,
122− compare(x, data.result)
125− // test for the getViewTranslation() function
126− function test_getViewTranslation_data() {
127− return [ {tag:"at start - viewfactor 1",
128− x: 0, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: 150},
129− {tag:"at start - viewfactor 2",
130− x: 0, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:2, result: 300},
132− x: 100, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: 50},
133− {tag:"in the middle",
134− x: 350, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: 0},
136− x: 600, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: -150},
140− function test_getViewTranslation(data) {
141− root.carouselWidth = data.carouselWidth
142− root.tileWidth = data.tileWidth
143− root.itemCount = data.itemCount
145− var x = Carousel.getViewTranslation(data.x,
146 data.tileWidth,
119 data.tileWidth,
123+ compare(x, data.result)
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},
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},
137+ x: 600, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: -150},
141+ function test_getViewTranslation(data) {
142+ root.carouselWidth = data.carouselWidth
143+ root.tileWidth = data.tileWidth
144+ root.itemCount = data.itemCount
146+ var x = Carousel.getViewTranslation(data.x,
147− root.gapToMiddlePhase,
148+ root.gapToMiddlePhase,
148− root.gapToEndPhase,
149+ root.gapToEndPhase,
149− data.translationXViewFactor)
150+ data.translationXViewFactor)
150− compare(x, data.result)
151+ compare(x, data.result)
153− // test for the getItemScale() function
154+ // test for the getItemScale() function
154− function test_getItemScale_data() {
155+ function test_getItemScale_data() {
155− return [ // tests for distance
156+ return [ // tests for distance
156− {distance: 0, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 1},
157+ {distance: 0, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 1},
157− {distance: 9, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.01},
158+ {distance: 9, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.01},
158− {distance: 999, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.01},
159+ {distance: 999, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.01},
159− {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)
160− {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)
161− // tests for continuousIndex
162+ // tests for continuousIndex
162− {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)
163− {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
164− // tests for numberOfItems
165+ // tests for numberOfItems
165− {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)
166− {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
167− // tests for scaleFactor
168+ // tests for scaleFactor
168− {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)
169− {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)
170− {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)
171− {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
172− {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
176− function test_getItemScale(data) {
177+ function test_getItemScale(data) {
177− var scale = Carousel.getItemScale(data.distance,
178+ var scale = Carousel.getItemScale(data.distance,
178− data.continuousIndex,
179+ data.continuousIndex,
179− data.numberOfItems,
180+ data.numberOfItems,
180− data.scaleFactor)
181+ data.scaleFactor)
181− compare(scale, data.result)
182+ compare(scale, data.result)
184− // test for the getItemTranslation() function
185+ // test for the getItemTranslation() function
185− function test_getItemTranslation_data() {
186+ function test_getItemTranslation_data() {
186− return [ // tests for index and selectedIndex
187+ return [ // tests for index and selectedIndex
187− {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},
188− // tests if distance only affects the sign
189+ // tests if distance only affects the sign
189− {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},
190− {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},
191− {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},
192− {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},
193− // tests for the scale
194+ // tests for the scale
194− {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},
195− {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},
196− {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},
197− // tests for maxScale
198+ // tests for maxScale
198− {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},
199− {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},
200− {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},
201− // test for maxTranslation
202+ // test for maxTranslation
202− {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},
203− {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},
204− {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},
205− {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},
209− function test_getItemTranslation(data) {
210+ function test_getItemTranslation(data) {
210− var scale = Carousel.getItemTranslation(data.index,
211+ var scale = Carousel.getItemTranslation(data.index,
211− data.selectedIndex,
212+ data.selectedIndex,
212− data.distance,
213+ data.distance,
213− data.scale,
214+ data.scale,
214− data.maxScale,
215+ data.maxScale,
215− data.maxTranslation)
216+ data.maxTranslation)
216− compare(scale, data.result)
217+ compare(scale, data.result)