@@ -32,6 +32,8 @@ using namespace mu::engraving;
3232
3333static const String TEMPOMAP_TEST_FILES_DIR (" tempomap_data/" );
3434
35+ static constexpr double TEMPO_ERROR (0.000001 );
36+
3537class Engraving_TempoMapTests : public ::testing::Test
3638{
3739protected:
@@ -59,8 +61,10 @@ TEST_F(Engraving_TempoMapTests, DEFAULT_TEMPO)
5961
6062 // [THEN] Applied tempo matches our expectations
6163 for (const auto & pair : *tempoMap) {
62- EXPECT_EQ (pair.second .tempo , expectedTempo);
64+ EXPECT_NEAR (pair.second .tempo . val , expectedTempo. val , TEMPO_ERROR );
6365 }
66+
67+ delete score;
6468}
6569
6670/* *
@@ -76,16 +80,18 @@ TEST_F(Engraving_TempoMapTests, ABSOLUTE_TEMPO_80_BPM)
7680 ASSERT_TRUE (score);
7781
7882 // [GIVEN] Expected tempo
79- BeatsPerSecond expectedTempo = BeatsPerSecond::fromBPM (BeatsPerMinute ( 80 .f ) );
83+ BeatsPerSecond expectedTempo = BeatsPerSecond::fromBPM (80.0 );
8084
8185 // [WHEN] We request score's tempomap it should contain only 1 value, which is our expected tempo
8286 const TempoMap* tempoMap = score->tempomap ();
8387 EXPECT_EQ (tempoMap->size (), 1 );
8488
8589 // [THEN] Applied tempo matches with our expectations
8690 for (const auto & pair : *tempoMap) {
87- EXPECT_TRUE ( muse::RealIsEqual ( muse::RealRound ( pair.second .tempo .val , 2 ), muse::RealRound ( expectedTempo.val , 2 )) );
91+ EXPECT_NEAR ( pair.second .tempo .val , expectedTempo.val , TEMPO_ERROR );
8892 }
93+
94+ delete score;
8995}
9096
9197/* *
@@ -102,9 +108,9 @@ TEST_F(Engraving_TempoMapTests, ABSOLUTE_TEMPO_FROM_80_TO_120_BPM)
102108 ASSERT_TRUE (score);
103109
104110 // [GIVEN] Expected tempomap
105- std::map<int , BeatsPerSecond> expectedTempoMap = {
106- { 0 , BeatsPerSecond::fromBPM (BeatsPerMinute ( 80 .f ) ) }, // first measure
107- { 4 * 4 * Constants::DIVISION, BeatsPerSecond::fromBPM (BeatsPerMinute ( 120 .f ) ) } // 4-th measure
111+ std::map<int , BeatsPerSecond> expectedTempoMap {
112+ { 0 , BeatsPerSecond::fromBPM (80.0 ) }, // first measure
113+ { 4 * 4 * Constants::DIVISION, BeatsPerSecond::fromBPM (120.0 ) } // 4-th measure
108114 };
109115
110116 // [WHEN] We request score's tempomap its size matches with our expectations
@@ -113,8 +119,10 @@ TEST_F(Engraving_TempoMapTests, ABSOLUTE_TEMPO_FROM_80_TO_120_BPM)
113119
114120 // [THEN] Applied tempo matches with our expectations
115121 for (const auto & pair : *tempoMap) {
116- EXPECT_TRUE ( muse::RealIsEqual ( muse::RealRound ( pair.second .tempo .val , 2 ), muse::RealRound ( expectedTempoMap.at (pair.first ).val , 2 )) );
122+ EXPECT_NEAR ( pair.second .tempo .val , expectedTempoMap.at (pair.first ).val , TEMPO_ERROR );
117123 }
124+
125+ delete score;
118126}
119127
120128/* *
@@ -138,9 +146,9 @@ TEST_F(Engraving_TempoMapTests, TEMPO_MULTIPLIER)
138146 tempoMap->setTempoMultiplier (multiplier);
139147
140148 // [GIVEN] Expected tempomap
141- std::map<int , BeatsPerSecond> expectedTempoMap = {
142- { 0 , BeatsPerSecond::fromBPM (BeatsPerMinute ( 80.0 )) }, // first measure
143- { 4 * 4 * Constants::DIVISION, BeatsPerSecond::fromBPM (BeatsPerMinute ( 120.0 ) ) } // 4-th measure
149+ std::map<int , BeatsPerSecond> expectedTempoMap {
150+ { 0 , BeatsPerSecond::fromBPM (80.0 ) }, // first measure
151+ { 4 * 4 * Constants::DIVISION, BeatsPerSecond::fromBPM (120.0 ) } // 4-th measure
144152 };
145153
146154 // [WHEN] We request score's tempomap its size matches with our expectations
@@ -150,10 +158,12 @@ TEST_F(Engraving_TempoMapTests, TEMPO_MULTIPLIER)
150158 for (int tick : muse::keys (*tempoMap)) {
151159 double expectedBps = expectedTempoMap[tick].val ;
152160
153- EXPECT_NEAR (tempoMap->at (tick).tempo .val , expectedBps, 0.001 );
154- EXPECT_NEAR (tempoMap->tempo (tick).val , expectedBps, 0.001 );
155- EXPECT_NEAR (tempoMap->multipliedTempo (tick).val , expectedBps * multiplier, 0.001 );
161+ EXPECT_NEAR (tempoMap->at (tick).tempo .val , expectedBps, TEMPO_ERROR );
162+ EXPECT_NEAR (tempoMap->tempo (tick).val , expectedBps, TEMPO_ERROR );
163+ EXPECT_NEAR (tempoMap->multipliedTempo (tick).val , expectedBps * multiplier, TEMPO_ERROR );
156164 }
165+
166+ delete score;
157167}
158168
159169/* *
@@ -172,8 +182,8 @@ TEST_F(Engraving_TempoMapTests, GRADUAL_TEMPO_CHANGE_ACCELERANDO)
172182
173183 // [GIVEN] Expected tempomap
174184 std::map<int , BeatsPerSecond> expectedTempoMap = {
175- { 0 , BeatsPerSecond::fromBPM (BeatsPerMinute ( 120 .f ) ) }, // beginning of the first measure
176- { 6 * 4 * Constants::DIVISION, BeatsPerSecond::fromBPM (BeatsPerMinute ( 159 .6f ) ) } // beginning of the last measure
185+ { 0 , BeatsPerSecond::fromBPM (120.0 ) }, // beginning of the first measure
186+ { 6 * 4 * Constants::DIVISION, BeatsPerSecond::fromBPM (159.6 ) } // beginning of the last measure
177187 };
178188
179189 // [WHEN] We request score's tempomap its size matches with our expectations
@@ -182,8 +192,10 @@ TEST_F(Engraving_TempoMapTests, GRADUAL_TEMPO_CHANGE_ACCELERANDO)
182192
183193 // [THEN] Applied tempo matches with our expectations
184194 for (const auto & pair : expectedTempoMap) {
185- EXPECT_TRUE ( muse::RealIsEqual ( muse::RealRound ( tempoMap->at (pair.first ).tempo .val , 2 ), muse::RealRound ( pair.second .val , 2 )) );
195+ EXPECT_NEAR ( tempoMap->at (pair.first ).tempo .val , pair.second .val , TEMPO_ERROR );
186196 }
197+
198+ delete score;
187199}
188200
189201/* *
@@ -200,9 +212,9 @@ TEST_F(Engraving_TempoMapTests, GRADUAL_TEMPO_CHANGE_RALLENTANDO)
200212 ASSERT_TRUE (score);
201213
202214 // [GIVEN] Expected tempomap
203- std::map<int , BeatsPerSecond> expectedTempoMap = {
204- { 0 , BeatsPerSecond::fromBPM (BeatsPerMinute ( 120 .f ) ) }, // beginning of the first measure
205- { 6 * 4 * Constants::DIVISION, BeatsPerSecond::fromBPM (BeatsPerMinute ( 90 .f ) ) } // beginning of the last measure
215+ std::map<int , BeatsPerSecond> expectedTempoMap {
216+ { 0 , BeatsPerSecond::fromBPM (120.0 ) }, // beginning of the first measure
217+ { 6 * 4 * Constants::DIVISION, BeatsPerSecond::fromBPM (90.0 ) } // beginning of the last measure
206218 };
207219
208220 // [WHEN] We request score's tempomap its size matches with our expectations
@@ -211,8 +223,10 @@ TEST_F(Engraving_TempoMapTests, GRADUAL_TEMPO_CHANGE_RALLENTANDO)
211223
212224 // [THEN] Applied tempo matches with our expectations
213225 for (const auto & pair : expectedTempoMap) {
214- EXPECT_TRUE ( muse::RealIsEqual ( muse::RealRound ( tempoMap->at (pair.first ).tempo .val , 2 ), muse::RealRound ( pair.second .val , 2 )) );
226+ EXPECT_NEAR ( tempoMap->at (pair.first ).tempo .val , pair.second .val , TEMPO_ERROR );
215227 }
228+
229+ delete score;
216230}
217231
218232/* *
@@ -235,17 +249,17 @@ TEST_F(Engraving_TempoMapTests, GRADUAL_TEMPO_CHANGE_DOESNT_OVERWRITE_OTHER_TEMP
235249 ASSERT_TRUE (score);
236250
237251 // [GIVEN] Expected tempomap
238- std::map<int , BeatsPerSecond> expectedTempoMap = {
252+ std::map<int , BeatsPerSecond> expectedTempoMap {
239253 // ritardando (beginning of the first measure)
240- { 0 , BeatsPerSecond::fromBPM (BeatsPerMinute ( 120 .f ) ) },
241- { 960 , BeatsPerSecond::fromBPM (BeatsPerMinute ( 112 .5f ) ) },
254+ { 0 , BeatsPerSecond::fromBPM (120.0 ) },
255+ { 960 , BeatsPerSecond::fromBPM (112.5 ) },
242256 // tempo marking (80 BPM, the first measure)
243- { 1440 , BeatsPerSecond::fromBPM (BeatsPerMinute ( 80 .f ) ) },
257+ { 1440 , BeatsPerSecond::fromBPM (80.0 ) },
244258 // ritardando (the second measure)
245- { 1920 , BeatsPerSecond::fromBPM (BeatsPerMinute ( 105 .f ) ) },
246- { 2880 , BeatsPerSecond::fromBPM (BeatsPerMinute ( 97 .5f ) ) },
259+ { 1920 , BeatsPerSecond::fromBPM (105.0 ) },
260+ { 2880 , BeatsPerSecond::fromBPM (97.5 ) },
247261 // presto (beginning of the third measure)
248- { 3840 , BeatsPerSecond::fromBPM (BeatsPerMinute ( 187 .2f ) ) },
262+ { 3840 , BeatsPerSecond::fromBPM (187.0 ) },
249263 };
250264
251265 // [WHEN] We request score's tempomap its size matches with our expectations
@@ -254,6 +268,8 @@ TEST_F(Engraving_TempoMapTests, GRADUAL_TEMPO_CHANGE_DOESNT_OVERWRITE_OTHER_TEMP
254268
255269 // [THEN] Applied tempo matches with our expectations
256270 for (const auto & pair : expectedTempoMap) {
257- EXPECT_TRUE ( muse::RealIsEqual ( muse::RealRound ( tempoMap->at (pair.first ).tempo .val , 2 ), muse::RealRound ( pair.second .val , 2 )) );
271+ EXPECT_NEAR ( tempoMap->at (pair.first ).tempo .val , pair.second .val , TEMPO_ERROR );
258272 }
273+
274+ delete score;
259275}
0 commit comments