@@ -36,185 +36,185 @@ Item {
3636 Component.onCompleted: carousel.createdDelegates++
3737 Component.onDestruction: carousel.destroyedDelegates++
3838 }
39− TestCase {
40− id: root
41− name: "Carousel"
42− when: windowShown
43−
44− property real carouselWidth
45− property int itemCount
46− property real tileWidth
47−
48− property real contentWidth: itemCount * tileWidth
49− // 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− property real gapToMiddlePhase: Math.min(carouselWidth / 2 - tileWidth / 2, (contentWidth - carouselWidth) / 2)
52− property real gapToEndPhase: contentWidth - carouselWidth - gapToMiddlePhase
53− property real kMiddleIndex: (carouselWidth / 2) / tileWidth - 0.5
54− property real kGapEnd: kMiddleIndex * (1 - gapToEndPhase / gapToMiddlePhase)
55− property real kXBeginningEnd: 1 / tileWidth + kMiddleIndex / gapToMiddlePhase
56−
57− function test_onlyNeededItemsCreated() {
58− compare(carousel.createdDelegates, 10);
59− compare(carousel.destroyedDelegates, 0);
60− }
61−
62− // test for the getContinuousIndex() function
63− function test_getContinuousIndex_data() {
64− // testing for 10 items of size 100 pixel
65− return [ {tag:"at start",
66− x: 0, carouselWidth:400, tileWidth:100, itemCount:10, result: 0},
67− {tag:"in startup",
68− x: 100, carouselWidth:400, tileWidth:100, itemCount:10, result: 2},
69− {tag:"in the middle",
70− x: 350, carouselWidth:400, tileWidth:100, itemCount:10, result: 5},
71− {tag:"at end",
72− x: 600, carouselWidth:400, tileWidth:100, itemCount:10, result: 9},
73− ]
74− }
75−
76− function test_getContinuousIndex(data) {
77− root.carouselWidth = data.carouselWidth
78− root.tileWidth = data.tileWidth
79− root.itemCount = data.itemCount
80−
81− var index = Carousel.getContinuousIndex(data.x,
82− data.tileWidth,
83− gapToMiddlePhase,
84− gapToEndPhase,
85− kGapEnd,
86− kMiddleIndex,
87− kXBeginningEnd)
88− compare(index, data.result)
89− }
90−
91− // test for the getXFromContinuousIndex() function
92− function test_getXFromContinuousIndex_data() {
93− return [ {tag:"at start",
94− index: 0, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 0},
95− {tag:"in startup",
96− index: 2, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 100},
97− {tag:"in startup with drawBuffer",
98− index: 2, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 0},
99− {tag:"in the middle",
100− index: 5, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 350},
101− {tag:"in the middle with drawBuffer",
102− index: 5, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 250},
103− {tag:"at end",
104− index: 9, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 600},
105− {tag:"at end with drawBuffer",
106− index: 9, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 500},
107− ]
108− }
109−
110− function test_getXFromContinuousIndex(data) {
111− root.carouselWidth = data.carouselWidth
112− root.tileWidth = data.tileWidth
113− root.itemCount = data.itemCount
114−
115− var x = Carousel.getXFromContinuousIndex(data.index,
116− data.carouselWidth,
117− contentWidth,
118− data.tileWidth,
119− gapToMiddlePhase,
120− gapToEndPhase,
121− data.drawBuffer)
122− compare(x, data.result)
123− }
124−
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},
131− {tag:"in startup",
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},
135− {tag:"at end",
136− x: 600, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: -150},
137− ]
138− }
139−
140− function test_getViewTranslation(data) {
141− root.carouselWidth = data.carouselWidth
142− root.tileWidth = data.tileWidth
143− root.itemCount = data.itemCount
144−
145− var x = Carousel.getViewTranslation(data.x,
39+ }
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,
146119 data.tileWidth,
147− root.gapToMiddlePhase,
148− root.gapToEndPhase,
149− data.translationXViewFactor)
150− compare(x, data.result)
151− }
152−
153− // test for the getItemScale() function
154− function test_getItemScale_data() {
155− return [ // tests for distance
156− {distance: 0, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 1},
157− {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: 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− // tests for continuousIndex
162− {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− // tests for numberOfItems
165− {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− // 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: 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: 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− ]
174− }
175−
176− function test_getItemScale(data) {
177− var scale = Carousel.getItemScale(data.distance,
178− data.continuousIndex,
179− data.numberOfItems,
180− data.scaleFactor)
181− compare(scale, data.result)
182− }
183−
184− // test for the getItemTranslation() function
185− function test_getItemTranslation_data() {
186− return [ // tests for index and selectedIndex
187− {index: 1, selectedIndex: 1, distance: 1, scale: 1, maxScale: 1, maxTranslation: 10, result: 0},
188− // 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: 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: -99, scale: 0, maxScale: 1, maxTranslation: 10, result: -10},
193− // 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: 0, maxScale: 1, maxTranslation: 10, result: 10},
196− {index: 1, selectedIndex: 2, distance: 1, scale: 0.5, maxScale: 1, maxTranslation: 10, result: 5},
197− // 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.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− // 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: 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: 0, result: 0},
206− ]
207− }
208−
209− function test_getItemTranslation(data) {
210− var scale = Carousel.getItemTranslation(data.index,
211− data.selectedIndex,
212− data.distance,
213− data.scale,
214− data.maxScale,
215− data.maxTranslation)
216− compare(scale, data.result)
217− }
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+
154+ // test for the getItemScale() function
155+ function test_getItemScale_data() {
156+ return [ // tests for distance
157+ {distance: 0, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 1},
158+ {distance: 9, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.01},
159+ {distance: 999, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.01},
160+ {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
161+ {distance: 3, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.688230855}, // = 1 - (3^2.5 / 50)
162+ // tests for continuousIndex
163+ {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
164+ {distance: 1, continuousIndex: 97, numberOfItems: 100, scaleFactor: 1, result: 0.99}, // = 1 - (1 / 100) - distanceToBounds is used
165+ // tests for numberOfItems
166+ {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
167+ {distance: 1, continuousIndex: 50, numberOfItems: 53, scaleFactor: 1, result: 0.99}, // = 1 - (1 / 100) - distanceToBounds is used
168+ // tests for scaleFactor
169+ {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
170+ {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 2, result: 0.99}, // = 1 - (1 / 100)
171+ {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 0.5, result: 0.96}, // = 1 - (1 / 25)
172+ {distance: 1, continuousIndex: 50, numberOfItems: 53, scaleFactor: 1, result: 0.99}, // = 1 - (1 / 100) - distanceToBounds is used
173+ {distance: 1, continuousIndex: 50, numberOfItems: 53, scaleFactor: 2, result: 0.996666666}, // = 1 - (1 / 300) - distanceToBounds is used
174+ ]
175+ }
176+
177+ function test_getItemScale(data) {
178+ var scale = Carousel.getItemScale(data.distance,
179+ data.continuousIndex,
180+ data.numberOfItems,
181+ data.scaleFactor)
182+ compare(scale, data.result)
183+ }
184+
185+ // test for the getItemTranslation() function
186+ function test_getItemTranslation_data() {
187+ return [ // tests for index and selectedIndex
188+ {index: 1, selectedIndex: 1, distance: 1, scale: 1, maxScale: 1, maxTranslation: 10, result: 0},
189+ // tests if distance only affects the sign
190+ {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
191+ {index: 1, selectedIndex: 2, distance: 99, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
192+ {index: 1, selectedIndex: 2, distance: -1, scale: 0, maxScale: 1, maxTranslation: 10, result: -10},
193+ {index: 1, selectedIndex: 2, distance: -99, scale: 0, maxScale: 1, maxTranslation: 10, result: -10},
194+ // tests for the scale
195+ {index: 1, selectedIndex: 2, distance: 1, scale: 1, maxScale: 1, maxTranslation: 10, result: 0},
196+ {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
197+ {index: 1, selectedIndex: 2, distance: 1, scale: 0.5, maxScale: 1, maxTranslation: 10, result: 5},
198+ // tests for maxScale
199+ {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 0.98, maxTranslation: 10, result: 9.8},
200+ {index: 1, selectedIndex: 2, distance: 1, scale: 0.5, maxScale: 0.95, maxTranslation: 10, result: 4.5},
201+ {index: 1, selectedIndex: 2, distance: 1, scale: 0.8, maxScale: 0.93, maxTranslation: 10, result: 1.3},
202+ // test for maxTranslation
203+ {index: 1, selectedIndex: 2, distance: 1, scale: 1, maxScale: 1, maxTranslation: 1, result: 0},
204+ {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 1, result: 1},
205+ {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
206+ {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 0, result: 0},
207+ ]
208+ }
209+
210+ function test_getItemTranslation(data) {
211+ var scale = Carousel.getItemTranslation(data.index,
212+ data.selectedIndex,
213+ data.distance,
214+ data.scale,
215+ data.maxScale,
216+ data.maxTranslation)
217+ compare(scale, data.result)
218218 }
219219 }
220220}