12#include <catch2/catch.hpp>
22#include "MockedPrefs.h"
23#include "MockedAudio.h"
34 hhmmssFormatter->ValueToString(0.0,
false).valueString ==
38 hhmmssFormatter->ValueToString(30.0,
false).valueString ==
42 hhmmssFormatter->ValueToString(60.0,
false).valueString ==
46 hhmmssFormatter->ValueToString(60.0,
false)
47 .fieldValueStrings.size() == 3);
50 hhmmssFormatter->ValueToString(60.0,
false).fieldValueStrings[0] ==
54 hhmmssFormatter->ValueToString(60.0,
false).fieldValueStrings[1] ==
58 hhmmssFormatter->ValueToString(60.0,
false).fieldValueStrings[2] ==
62 hhmmssFormatter->StringToValue(
"foobar").has_value() ==
false);
64 hhmmssFormatter->StringToValue(
"01 h 30 m 15 s").has_value() ==
true);
66 *hhmmssFormatter->StringToValue(
"01 h 30 m 15 s") ==
67 Approx(60 * 60 + 30 * 60 + 15));
73 MockedPrefs mockedPrefs;
74 MockedAudio mockedAudio;
79 timeSignature.SetTempo(120.0);
80 timeSignature.SetUpperTimeSignature(3);
81 timeSignature.SetLowerTimeSignature(4);
86 basicFormatter->ValueToString(-1.0,
false).valueString ==
90 basicFormatter->ValueToString(0.0,
false).valueString ==
94 basicFormatter->ValueToString(0.6,
false).valueString ==
98 basicFormatter->ValueToString(1.0,
false).valueString ==
102 basicFormatter->ValueToString(1.6,
false).valueString ==
105 REQUIRE(basicFormatter->StringToValue(
"foobar").has_value() ==
false);
107 REQUIRE(basicFormatter->StringToValue(
"001 bar 01 beat").has_value() ==
true);
109 *basicFormatter->StringToValue(
"001 bar 01 beat") == Approx(0));
111 *basicFormatter->StringToValue(
"001 bar 02 beat") == Approx(0.5));
113 *basicFormatter->StringToValue(
"002 bar 01 beat") == Approx(1.5));
115 timeSignature.SetTempo(120.0);
116 timeSignature.SetUpperTimeSignature(3);
117 timeSignature.SetLowerTimeSignature(4);
123 fracFormatter->ValueToString(-1.0,
false).valueString ==
124 "--- bar -- beat --");
127 fracFormatter->ValueToString(0.0,
false).valueString ==
128 "001 bar 01 beat 01");
131 fracFormatter->ValueToString(0.6,
false).valueString ==
132 "001 bar 02 beat 01");
135 fracFormatter->ValueToString(1.0,
false).valueString ==
136 "001 bar 03 beat 01");
139 fracFormatter->ValueToString(1.9,
false).valueString ==
140 "002 bar 01 beat 04");
142 *fracFormatter->StringToValue(
"001 bar 01 beat 01") == Approx(0));
144 *fracFormatter->StringToValue(
"001 bar 02 beat 01") == Approx(0.5));
146 *fracFormatter->StringToValue(
"002 bar 01 beat 01") == Approx(1.5));
148 *fracFormatter->StringToValue(
"001 bar 01 beat 02") == Approx(0.125));
150 *fracFormatter->StringToValue(
"001 bar 02 beat 04") == Approx(0.875));
152 *fracFormatter->StringToValue(
"002 bar 01 beat 09") ==
153 Approx(1.5 + 0.0 + 8 * (0.5 / 4)));
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));
164 durationFormatter->ValueToString(-1.0,
false).valueString ==
165 "--- bar -- beat --");
168 durationFormatter->ValueToString(0.0,
false).valueString ==
169 "000 bar 00 beat 00");
172 durationFormatter->ValueToString(0.6,
false).valueString ==
173 "000 bar 01 beat 00");
176 durationFormatter->ValueToString(1.0,
false).valueString ==
177 "000 bar 02 beat 00");
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));
186 *durationFormatter->StringToValue(
"000 bar 00 beat 01") == Approx(0.125));
188 *durationFormatter->StringToValue(
"000 bar 01 beat 03") == Approx(0.875));
190 *durationFormatter->StringToValue(
"001 bar 00 beat 08") ==
191 Approx(1.5 + 0.0 + 8 * (0.5 / 4)));
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));
198 auto longFormatterTest = [&](
double tempo)
200 timeSignature.SetTempo(tempo);
201 timeSignature.SetUpperTimeSignature(4);
202 timeSignature.SetLowerTimeSignature(4);
209 for (int32_t bar = 0; bar < 100000; ++bar)
211 for (int32_t beat = 0; beat < 4; ++beat)
213 const auto value = bar * timeSignature.GetBarDuration() +
214 beat * timeSignature.GetBeatDuration();
216 basicFormatter->UpdateFormatForValue(value,
true);
218 const auto formattedString =
219 wxString::Format(
"%03d bar %02d beat", bar + 1, beat + 1);
222 *basicFormatter->StringToValue(formattedString) ==
228 *basicFormatter->StringToValue(formattedString),
true)
229 .valueString == formattedString);
234 longFormatterTest(88);
235 longFormatterTest(117);
TEST_CASE("ParsedNumericConverterFormatter", "")
const NumericConverterType & NumericConverterType_TIME()
an object holding per-project preferred sample rate
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
static std::shared_ptr< AudacityProject > Create()
Use this factory function.
static FormatterContext ProjectContext(const AudacityProject &project)
static FormatterContext SampleRateContext(double sampleRate)
static ProjectTimeSignature & Get(AudacityProject &project)