72{
73 MockedPrefs mockedPrefs;
74 MockedAudio mockedAudio;
75
78
79 timeSignature.SetTempo(120.0);
80 timeSignature.SetUpperTimeSignature(3);
81 timeSignature.SetLowerTimeSignature(4);
82
84
85 REQUIRE(
86 basicFormatter->ValueToString(-1.0, false).valueString ==
87 "--- bar -- beat");
88
89 REQUIRE(
90 basicFormatter->ValueToString(0.0, false).valueString ==
91 "001 bar 01 beat");
92
93 REQUIRE(
94 basicFormatter->ValueToString(0.6, false).valueString ==
95 "001 bar 02 beat");
96
97 REQUIRE(
98 basicFormatter->ValueToString(1.0, false).valueString ==
99 "001 bar 03 beat");
100
101 REQUIRE(
102 basicFormatter->ValueToString(1.6, false).valueString ==
103 "002 bar 01 beat");
104
105 REQUIRE(basicFormatter->StringToValue("foobar").has_value() == false);
106
107 REQUIRE(basicFormatter->StringToValue("001 bar 01 beat").has_value() == true);
108 REQUIRE(
109 *basicFormatter->StringToValue("001 bar 01 beat") == Approx(0));
110 REQUIRE(
111 *basicFormatter->StringToValue("001 bar 02 beat") == Approx(0.5));
112 REQUIRE(
113 *basicFormatter->StringToValue("002 bar 01 beat") == Approx(1.5));
114
115 timeSignature.SetTempo(120.0);
116 timeSignature.SetUpperTimeSignature(3);
117 timeSignature.SetLowerTimeSignature(4);
118
121
122 REQUIRE(
123 fracFormatter->ValueToString(-1.0, false).valueString ==
124 "--- bar -- beat --");
125
126 REQUIRE(
127 fracFormatter->ValueToString(0.0, false).valueString ==
128 "001 bar 01 beat 01");
129
130 REQUIRE(
131 fracFormatter->ValueToString(0.6, false).valueString ==
132 "001 bar 02 beat 01");
133
134 REQUIRE(
135 fracFormatter->ValueToString(1.0, false).valueString ==
136 "001 bar 03 beat 01");
137
138 REQUIRE(
139 fracFormatter->ValueToString(1.9, false).valueString ==
140 "002 bar 01 beat 04");
141 REQUIRE(
142 *fracFormatter->StringToValue("001 bar 01 beat 01") == Approx(0));
143 REQUIRE(
144 *fracFormatter->StringToValue("001 bar 02 beat 01") == Approx(0.5));
145 REQUIRE(
146 *fracFormatter->StringToValue("002 bar 01 beat 01") == Approx(1.5));
147 REQUIRE(
148 *fracFormatter->StringToValue("001 bar 01 beat 02") == Approx(0.125));
149 REQUIRE(
150 *fracFormatter->StringToValue("001 bar 02 beat 04") == Approx(0.875));
151 REQUIRE(
152 *fracFormatter->StringToValue("002 bar 01 beat 09") ==
153 Approx(1.5 + 0.0 + 8 * (0.5 / 4)));
154
155 REQUIRE(fracFormatter->SingleStep(0.0, 2, true) == Approx(1.5));
156 REQUIRE(fracFormatter->SingleStep(0.0, 1, true) == Approx(15.0));
157 REQUIRE(fracFormatter->SingleStep(0.0, 4, true) == Approx(0.5));
158 REQUIRE(fracFormatter->SingleStep(0.0, 3, true) == Approx(5));
159
162
163 REQUIRE(
164 durationFormatter->ValueToString(-1.0, false).valueString ==
165 "--- bar -- beat --");
166
167 REQUIRE(
168 durationFormatter->ValueToString(0.0, false).valueString ==
169 "000 bar 00 beat 00");
170
171 REQUIRE(
172 durationFormatter->ValueToString(0.6, false).valueString ==
173 "000 bar 01 beat 00");
174
175 REQUIRE(
176 durationFormatter->ValueToString(1.0, false).valueString ==
177 "000 bar 02 beat 00");
178
179 REQUIRE(
180 durationFormatter->ValueToString(1.9, false).valueString ==
181 "001 bar 00 beat 03");
182 REQUIRE(*durationFormatter->StringToValue("000 bar 00 beat 00") == Approx(0));
183 REQUIRE(*durationFormatter->StringToValue("000 bar 01 beat 00") == Approx(0.5));
184 REQUIRE(*durationFormatter->StringToValue("001 bar 00 beat 00") == Approx(1.5));
185 REQUIRE(
186 *durationFormatter->StringToValue("000 bar 00 beat 01") == Approx(0.125));
187 REQUIRE(
188 *durationFormatter->StringToValue("000 bar 01 beat 03") == Approx(0.875));
189 REQUIRE(
190 *durationFormatter->StringToValue("001 bar 00 beat 08") ==
191 Approx(1.5 + 0.0 + 8 * (0.5 / 4)));
192
193 REQUIRE(durationFormatter->SingleStep(0.0, 2, true) == Approx(1.5));
194 REQUIRE(durationFormatter->SingleStep(0.0, 1, true) == Approx(15.0));
195 REQUIRE(durationFormatter->SingleStep(0.0, 4, true) == Approx(0.5));
196 REQUIRE(durationFormatter->SingleStep(0.0, 3, true) == Approx(5));
197
198 auto longFormatterTest = [&](double tempo)
199 {
200 timeSignature.SetTempo(tempo);
201 timeSignature.SetUpperTimeSignature(4);
202 timeSignature.SetLowerTimeSignature(4);
203
204
205
206
207
208
209 for (int32_t bar = 0; bar < 100000; ++bar)
210 {
211 for (int32_t beat = 0; beat < 4; ++beat)
212 {
213 const auto value = bar * timeSignature.GetBarDuration() +
214 beat * timeSignature.GetBeatDuration();
215
216 basicFormatter->UpdateFormatForValue(value, true);
217
218 const auto formattedString =
219 wxString::Format("%03d bar %02d beat", bar + 1, beat + 1);
220
221 REQUIRE(
222 *basicFormatter->StringToValue(formattedString) ==
223 Approx(value));
224
225 REQUIRE(
226 basicFormatter
227 ->ValueToString(
228 *basicFormatter->StringToValue(formattedString), true)
229 .valueString == formattedString);
230 }
231 }
232 };
233
234 longFormatterTest(88);
235 longFormatterTest(117);
236}
static std::shared_ptr< AudacityProject > Create()
Use this factory function.
static FormatterContext ProjectContext(const AudacityProject &project)
static ProjectTimeSignature & Get(AudacityProject &project)