Chris@1407
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@1407
|
2
|
Chris@1407
|
3 /*
|
Chris@1407
|
4 Sonic Visualiser
|
Chris@1407
|
5 An audio file viewer and annotation editor.
|
Chris@1407
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@1407
|
7
|
Chris@1407
|
8 This program is free software; you can redistribute it and/or
|
Chris@1407
|
9 modify it under the terms of the GNU General Public License as
|
Chris@1407
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@1407
|
11 License, or (at your option) any later version. See the file
|
Chris@1407
|
12 COPYING included with this distribution for more information.
|
Chris@1407
|
13 */
|
Chris@1407
|
14
|
Chris@1407
|
15 #ifndef TEST_SCALE_TICK_INTERVALS_H
|
Chris@1407
|
16 #define TEST_SCALE_TICK_INTERVALS_H
|
Chris@1407
|
17
|
Chris@1407
|
18 #include "../ScaleTickIntervals.h"
|
Chris@1407
|
19
|
Chris@1407
|
20 #include <QObject>
|
Chris@1407
|
21 #include <QtTest>
|
Chris@1407
|
22 #include <QDir>
|
Chris@1407
|
23
|
Chris@1407
|
24 #include <iostream>
|
Chris@1407
|
25
|
Chris@1407
|
26 using namespace std;
|
Chris@1407
|
27
|
Chris@1407
|
28 class TestScaleTickIntervals : public QObject
|
Chris@1407
|
29 {
|
Chris@1407
|
30 Q_OBJECT
|
Chris@1407
|
31
|
Chris@1407
|
32 void printDiff(vector<ScaleTickIntervals::Tick> ticks,
|
Chris@1407
|
33 vector<ScaleTickIntervals::Tick> expected) {
|
Chris@1407
|
34
|
Chris@1407
|
35 cerr << "Have " << ticks.size() << " ticks, expected "
|
Chris@1407
|
36 << expected.size() << endl;
|
Chris@1407
|
37 for (int i = 0; i < int(expected.size()); ++i) {
|
Chris@1407
|
38 if (i < int(ticks.size())) {
|
Chris@1407
|
39 cerr << i << ": have " << ticks[i].value << " \""
|
Chris@1407
|
40 << ticks[i].label << "\", expected "
|
Chris@1407
|
41 << expected[i].value << " \"" << expected[i].label
|
Chris@1407
|
42 << "\"" << endl;
|
Chris@1407
|
43 }
|
Chris@1407
|
44 }
|
Chris@1407
|
45 }
|
Chris@1407
|
46
|
Chris@1407
|
47 void compareTicks(vector<ScaleTickIntervals::Tick> ticks,
|
Chris@1407
|
48 vector<ScaleTickIntervals::Tick> expected)
|
Chris@1407
|
49 {
|
Chris@1408
|
50 double eps = 1e-7;
|
Chris@1407
|
51 for (int i = 0; i < int(expected.size()); ++i) {
|
Chris@1407
|
52 if (i < int(ticks.size())) {
|
Chris@1407
|
53 if (ticks[i].label != expected[i].label ||
|
Chris@1408
|
54 fabs(ticks[i].value - expected[i].value) > eps) {
|
Chris@1407
|
55 printDiff(ticks, expected);
|
Chris@1407
|
56 }
|
Chris@1407
|
57 QCOMPARE(ticks[i].label, expected[i].label);
|
Chris@1407
|
58 QCOMPARE(ticks[i].value, expected[i].value);
|
Chris@1407
|
59 }
|
Chris@1407
|
60 }
|
Chris@1408
|
61 if (ticks.size() != expected.size()) {
|
Chris@1408
|
62 printDiff(ticks, expected);
|
Chris@1408
|
63 }
|
Chris@1407
|
64 QCOMPARE(ticks.size(), expected.size());
|
Chris@1407
|
65 }
|
Chris@1407
|
66
|
Chris@1407
|
67 private slots:
|
Chris@1407
|
68 void linear_0_1_10()
|
Chris@1407
|
69 {
|
Chris@1407
|
70 auto ticks = ScaleTickIntervals::linear({ 0, 1, 10 });
|
Chris@1407
|
71 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
72 { 0.0, "0.0" },
|
Chris@1409
|
73 { 0.1, "0.1" },
|
Chris@1409
|
74 { 0.2, "0.2" },
|
Chris@1409
|
75 { 0.3, "0.3" },
|
Chris@1409
|
76 { 0.4, "0.4" },
|
Chris@1409
|
77 { 0.5, "0.5" },
|
Chris@1409
|
78 { 0.6, "0.6" },
|
Chris@1409
|
79 { 0.7, "0.7" },
|
Chris@1409
|
80 { 0.8, "0.8" },
|
Chris@1409
|
81 { 0.9, "0.9" },
|
Chris@1409
|
82 { 1.0, "1.0" }
|
Chris@1409
|
83 };
|
Chris@1409
|
84 compareTicks(ticks.ticks, expected);
|
Chris@1409
|
85 }
|
Chris@1409
|
86
|
Chris@1409
|
87 void linear_0_5_5()
|
Chris@1409
|
88 {
|
Chris@1409
|
89 auto ticks = ScaleTickIntervals::linear({ 0, 5, 5 });
|
Chris@1410
|
90 // generally if we have some activity in the units column, we
|
Chris@1410
|
91 // should add .0 to satisfy the human worry that we aren't
|
Chris@1410
|
92 // being told the whole story...
|
Chris@1409
|
93 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1410
|
94 { 0, "0.0" },
|
Chris@1410
|
95 { 1, "1.0" },
|
Chris@1410
|
96 { 2, "2.0" },
|
Chris@1410
|
97 { 3, "3.0" },
|
Chris@1410
|
98 { 4, "4.0" },
|
Chris@1410
|
99 { 5, "5.0" },
|
Chris@1409
|
100 };
|
Chris@1409
|
101 compareTicks(ticks.ticks, expected);
|
Chris@1409
|
102 }
|
Chris@1409
|
103
|
Chris@1409
|
104 void linear_0_10_5()
|
Chris@1409
|
105 {
|
Chris@1409
|
106 auto ticks = ScaleTickIntervals::linear({ 0, 10, 5 });
|
Chris@1409
|
107 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1410
|
108 { 0, "0.0" },
|
Chris@1410
|
109 { 2, "2.0" },
|
Chris@1410
|
110 { 4, "4.0" },
|
Chris@1410
|
111 { 6, "6.0" },
|
Chris@1410
|
112 { 8, "8.0" },
|
Chris@1410
|
113 { 10, "10.0" }
|
Chris@1407
|
114 };
|
Chris@1407
|
115 compareTicks(ticks.ticks, expected);
|
Chris@1407
|
116 }
|
Chris@1407
|
117
|
Chris@1407
|
118 void linear_0_0p1_5()
|
Chris@1407
|
119 {
|
Chris@1407
|
120 auto ticks = ScaleTickIntervals::linear({ 0, 0.1, 5 });
|
Chris@1407
|
121 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
122 { 0.00, "0.00" },
|
Chris@1407
|
123 { 0.02, "0.02" },
|
Chris@1407
|
124 { 0.04, "0.04" },
|
Chris@1407
|
125 { 0.06, "0.06" },
|
Chris@1407
|
126 { 0.08, "0.08" },
|
Chris@1409
|
127 { 0.10, "0.10" }
|
Chris@1407
|
128 };
|
Chris@1407
|
129 compareTicks(ticks.ticks, expected);
|
Chris@1407
|
130 }
|
Chris@1407
|
131
|
Chris@1407
|
132 void linear_0_0p01_5()
|
Chris@1407
|
133 {
|
Chris@1407
|
134 auto ticks = ScaleTickIntervals::linear({ 0, 0.01, 5 });
|
Chris@1407
|
135 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
136 { 0.000, "0.000" },
|
Chris@1407
|
137 { 0.002, "0.002" },
|
Chris@1407
|
138 { 0.004, "0.004" },
|
Chris@1407
|
139 { 0.006, "0.006" },
|
Chris@1407
|
140 { 0.008, "0.008" },
|
Chris@1409
|
141 { 0.010, "0.010" }
|
Chris@1409
|
142 };
|
Chris@1409
|
143 compareTicks(ticks.ticks, expected);
|
Chris@1409
|
144 }
|
Chris@1409
|
145
|
Chris@1409
|
146 void linear_0_0p005_5()
|
Chris@1409
|
147 {
|
Chris@1409
|
148 auto ticks = ScaleTickIntervals::linear({ 0, 0.005, 5 });
|
Chris@1409
|
149 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
150 { 0.000, "0.000" },
|
Chris@1409
|
151 { 0.001, "0.001" },
|
Chris@1409
|
152 { 0.002, "0.002" },
|
Chris@1409
|
153 { 0.003, "0.003" },
|
Chris@1409
|
154 { 0.004, "0.004" },
|
Chris@1409
|
155 { 0.005, "0.005" }
|
Chris@1407
|
156 };
|
Chris@1407
|
157 compareTicks(ticks.ticks, expected);
|
Chris@1407
|
158 }
|
Chris@1407
|
159
|
Chris@1407
|
160 void linear_0_0p001_5()
|
Chris@1407
|
161 {
|
Chris@1407
|
162 auto ticks = ScaleTickIntervals::linear({ 0, 0.001, 5 });
|
Chris@1407
|
163 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
164 { 0.0000, "0.0e+00" },
|
Chris@1407
|
165 { 0.0002, "2.0e-04" },
|
Chris@1407
|
166 { 0.0004, "4.0e-04" },
|
Chris@1407
|
167 { 0.0006, "6.0e-04" },
|
Chris@1407
|
168 { 0.0008, "8.0e-04" },
|
Chris@1409
|
169 { 0.0010, "1.0e-03" }
|
Chris@1407
|
170 };
|
Chris@1407
|
171 compareTicks(ticks.ticks, expected);
|
Chris@1407
|
172 }
|
Chris@1407
|
173
|
Chris@1407
|
174 void linear_1_1p001_5()
|
Chris@1407
|
175 {
|
Chris@1407
|
176 auto ticks = ScaleTickIntervals::linear({ 1, 1.001, 5 });
|
Chris@1407
|
177 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
178 { 1.0000, "1.0000" },
|
Chris@1407
|
179 { 1.0002, "1.0002" },
|
Chris@1407
|
180 { 1.0004, "1.0004" },
|
Chris@1407
|
181 { 1.0006, "1.0006" },
|
Chris@1407
|
182 { 1.0008, "1.0008" },
|
Chris@1409
|
183 { 1.0010, "1.0010" }
|
Chris@1409
|
184 };
|
Chris@1409
|
185 compareTicks(ticks.ticks, expected);
|
Chris@1409
|
186 }
|
Chris@1409
|
187
|
Chris@1409
|
188 void linear_10000_10010_5()
|
Chris@1409
|
189 {
|
Chris@1409
|
190 auto ticks = ScaleTickIntervals::linear({ 10000, 10010, 5 });
|
Chris@1409
|
191 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1410
|
192 { 10000, "10000.0" },
|
Chris@1410
|
193 { 10002, "10002.0" },
|
Chris@1410
|
194 { 10004, "10004.0" },
|
Chris@1410
|
195 { 10006, "10006.0" },
|
Chris@1410
|
196 { 10008, "10008.0" },
|
Chris@1410
|
197 { 10010, "10010.0" },
|
Chris@1409
|
198 };
|
Chris@1409
|
199 compareTicks(ticks.ticks, expected);
|
Chris@1409
|
200 }
|
Chris@1409
|
201
|
Chris@1409
|
202 void linear_10000_20000_5()
|
Chris@1409
|
203 {
|
Chris@1409
|
204 auto ticks = ScaleTickIntervals::linear({ 10000, 20000, 5 });
|
Chris@1409
|
205 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
206 { 10000, "10000" },
|
Chris@1409
|
207 { 12000, "12000" },
|
Chris@1409
|
208 { 14000, "14000" },
|
Chris@1409
|
209 { 16000, "16000" },
|
Chris@1409
|
210 { 18000, "18000" },
|
Chris@1409
|
211 { 20000, "20000" },
|
Chris@1409
|
212 };
|
Chris@1409
|
213 compareTicks(ticks.ticks, expected);
|
Chris@1409
|
214 }
|
Chris@1409
|
215
|
Chris@1409
|
216 void linear_m1_1_10()
|
Chris@1409
|
217 {
|
Chris@1409
|
218 auto ticks = ScaleTickIntervals::linear({ -1, 1, 10 });
|
Chris@1409
|
219 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
220 { -1.0, "-1.0" },
|
Chris@1409
|
221 { -0.8, "-0.8" },
|
Chris@1409
|
222 { -0.6, "-0.6" },
|
Chris@1409
|
223 { -0.4, "-0.4" },
|
Chris@1409
|
224 { -0.2, "-0.2" },
|
Chris@1409
|
225 { 0.0, "0.0" },
|
Chris@1409
|
226 { 0.2, "0.2" },
|
Chris@1409
|
227 { 0.4, "0.4" },
|
Chris@1409
|
228 { 0.6, "0.6" },
|
Chris@1409
|
229 { 0.8, "0.8" },
|
Chris@1409
|
230 { 1.0, "1.0" }
|
Chris@1407
|
231 };
|
Chris@1407
|
232 compareTicks(ticks.ticks, expected);
|
Chris@1407
|
233 }
|
Chris@1407
|
234 };
|
Chris@1407
|
235
|
Chris@1407
|
236 #endif
|
Chris@1407
|
237
|
Chris@1407
|
238
|