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@1409
|
90 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
91 { 0, "0" },
|
Chris@1409
|
92 { 1, "1" },
|
Chris@1409
|
93 { 2, "2" },
|
Chris@1409
|
94 { 3, "3" },
|
Chris@1409
|
95 { 4, "4" },
|
Chris@1409
|
96 { 5, "5" },
|
Chris@1409
|
97 };
|
Chris@1409
|
98 compareTicks(ticks.ticks, expected);
|
Chris@1409
|
99 }
|
Chris@1409
|
100
|
Chris@1409
|
101 void linear_0_10_5()
|
Chris@1409
|
102 {
|
Chris@1409
|
103 auto ticks = ScaleTickIntervals::linear({ 0, 10, 5 });
|
Chris@1409
|
104 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
105 { 0, "0" },
|
Chris@1409
|
106 { 2, "2" },
|
Chris@1409
|
107 { 4, "4" },
|
Chris@1409
|
108 { 6, "6" },
|
Chris@1409
|
109 { 8, "8" },
|
Chris@1409
|
110 { 10, "10" }
|
Chris@1407
|
111 };
|
Chris@1407
|
112 compareTicks(ticks.ticks, expected);
|
Chris@1407
|
113 }
|
Chris@1407
|
114
|
Chris@1407
|
115 void linear_0_0p1_5()
|
Chris@1407
|
116 {
|
Chris@1407
|
117 auto ticks = ScaleTickIntervals::linear({ 0, 0.1, 5 });
|
Chris@1407
|
118 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
119 { 0.00, "0.00" },
|
Chris@1407
|
120 { 0.02, "0.02" },
|
Chris@1407
|
121 { 0.04, "0.04" },
|
Chris@1407
|
122 { 0.06, "0.06" },
|
Chris@1407
|
123 { 0.08, "0.08" },
|
Chris@1409
|
124 { 0.10, "0.10" }
|
Chris@1407
|
125 };
|
Chris@1407
|
126 compareTicks(ticks.ticks, expected);
|
Chris@1407
|
127 }
|
Chris@1407
|
128
|
Chris@1407
|
129 void linear_0_0p01_5()
|
Chris@1407
|
130 {
|
Chris@1407
|
131 auto ticks = ScaleTickIntervals::linear({ 0, 0.01, 5 });
|
Chris@1407
|
132 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
133 { 0.000, "0.000" },
|
Chris@1407
|
134 { 0.002, "0.002" },
|
Chris@1407
|
135 { 0.004, "0.004" },
|
Chris@1407
|
136 { 0.006, "0.006" },
|
Chris@1407
|
137 { 0.008, "0.008" },
|
Chris@1409
|
138 { 0.010, "0.010" }
|
Chris@1409
|
139 };
|
Chris@1409
|
140 compareTicks(ticks.ticks, expected);
|
Chris@1409
|
141 }
|
Chris@1409
|
142
|
Chris@1409
|
143 void linear_0_0p005_5()
|
Chris@1409
|
144 {
|
Chris@1409
|
145 auto ticks = ScaleTickIntervals::linear({ 0, 0.005, 5 });
|
Chris@1409
|
146 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
147 { 0.000, "0.000" },
|
Chris@1409
|
148 { 0.001, "0.001" },
|
Chris@1409
|
149 { 0.002, "0.002" },
|
Chris@1409
|
150 { 0.003, "0.003" },
|
Chris@1409
|
151 { 0.004, "0.004" },
|
Chris@1409
|
152 { 0.005, "0.005" }
|
Chris@1407
|
153 };
|
Chris@1407
|
154 compareTicks(ticks.ticks, expected);
|
Chris@1407
|
155 }
|
Chris@1407
|
156
|
Chris@1407
|
157 void linear_0_0p001_5()
|
Chris@1407
|
158 {
|
Chris@1407
|
159 auto ticks = ScaleTickIntervals::linear({ 0, 0.001, 5 });
|
Chris@1407
|
160 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
161 { 0.0000, "0.0e+00" },
|
Chris@1407
|
162 { 0.0002, "2.0e-04" },
|
Chris@1407
|
163 { 0.0004, "4.0e-04" },
|
Chris@1407
|
164 { 0.0006, "6.0e-04" },
|
Chris@1407
|
165 { 0.0008, "8.0e-04" },
|
Chris@1409
|
166 { 0.0010, "1.0e-03" }
|
Chris@1407
|
167 };
|
Chris@1407
|
168 compareTicks(ticks.ticks, expected);
|
Chris@1407
|
169 }
|
Chris@1407
|
170
|
Chris@1407
|
171 void linear_1_1p001_5()
|
Chris@1407
|
172 {
|
Chris@1407
|
173 auto ticks = ScaleTickIntervals::linear({ 1, 1.001, 5 });
|
Chris@1407
|
174 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
175 { 1.0000, "1.0000" },
|
Chris@1407
|
176 { 1.0002, "1.0002" },
|
Chris@1407
|
177 { 1.0004, "1.0004" },
|
Chris@1407
|
178 { 1.0006, "1.0006" },
|
Chris@1407
|
179 { 1.0008, "1.0008" },
|
Chris@1409
|
180 { 1.0010, "1.0010" }
|
Chris@1409
|
181 };
|
Chris@1409
|
182 compareTicks(ticks.ticks, expected);
|
Chris@1409
|
183 }
|
Chris@1409
|
184
|
Chris@1409
|
185 void linear_10000_10010_5()
|
Chris@1409
|
186 {
|
Chris@1409
|
187 auto ticks = ScaleTickIntervals::linear({ 10000, 10010, 5 });
|
Chris@1409
|
188 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
189 { 10000, "10000" },
|
Chris@1409
|
190 { 10002, "10002" },
|
Chris@1409
|
191 { 10004, "10004" },
|
Chris@1409
|
192 { 10006, "10006" },
|
Chris@1409
|
193 { 10008, "10008" },
|
Chris@1409
|
194 { 10010, "10010" },
|
Chris@1409
|
195 };
|
Chris@1409
|
196 compareTicks(ticks.ticks, expected);
|
Chris@1409
|
197 }
|
Chris@1409
|
198
|
Chris@1409
|
199 void linear_10000_20000_5()
|
Chris@1409
|
200 {
|
Chris@1409
|
201 auto ticks = ScaleTickIntervals::linear({ 10000, 20000, 5 });
|
Chris@1409
|
202 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
203 { 10000, "10000" },
|
Chris@1409
|
204 { 12000, "12000" },
|
Chris@1409
|
205 { 14000, "14000" },
|
Chris@1409
|
206 { 16000, "16000" },
|
Chris@1409
|
207 { 18000, "18000" },
|
Chris@1409
|
208 { 20000, "20000" },
|
Chris@1409
|
209 };
|
Chris@1409
|
210 compareTicks(ticks.ticks, expected);
|
Chris@1409
|
211 }
|
Chris@1409
|
212
|
Chris@1409
|
213 void linear_m1_1_10()
|
Chris@1409
|
214 {
|
Chris@1409
|
215 auto ticks = ScaleTickIntervals::linear({ -1, 1, 10 });
|
Chris@1409
|
216 vector<ScaleTickIntervals::Tick> expected {
|
Chris@1409
|
217 { -1.0, "-1.0" },
|
Chris@1409
|
218 { -0.8, "-0.8" },
|
Chris@1409
|
219 { -0.6, "-0.6" },
|
Chris@1409
|
220 { -0.4, "-0.4" },
|
Chris@1409
|
221 { -0.2, "-0.2" },
|
Chris@1409
|
222 { 0.0, "0.0" },
|
Chris@1409
|
223 { 0.2, "0.2" },
|
Chris@1409
|
224 { 0.4, "0.4" },
|
Chris@1409
|
225 { 0.6, "0.6" },
|
Chris@1409
|
226 { 0.8, "0.8" },
|
Chris@1409
|
227 { 1.0, "1.0" }
|
Chris@1407
|
228 };
|
Chris@1407
|
229 compareTicks(ticks.ticks, expected);
|
Chris@1407
|
230 }
|
Chris@1407
|
231 };
|
Chris@1407
|
232
|
Chris@1407
|
233 #endif
|
Chris@1407
|
234
|
Chris@1407
|
235
|