Test checkpress + correction (LES TESTS C'EST UTILE)
This commit is contained in:
parent
dd67b76d1f
commit
e2fb0d911a
3 changed files with 26 additions and 4 deletions
|
@ -29,7 +29,7 @@ public:
|
||||||
static void clear() { existing_tiles.clear(); };
|
static void clear() { existing_tiles.clear(); };
|
||||||
// Should be called when one of arrows key pressed, return True if it's a good
|
// Should be called when one of arrows key pressed, return True if it's a good
|
||||||
// press
|
// press
|
||||||
bool checkPress(float press_time, NotePlaceEnum key_pressed);
|
static bool checkPress(float press_time, NotePlaceEnum key_pressed);
|
||||||
|
|
||||||
// Some getters usefull in test :
|
// Some getters usefull in test :
|
||||||
float getPlayTime() const { return play_time; };
|
float getPlayTime() const { return play_time; };
|
||||||
|
|
|
@ -21,10 +21,11 @@ void NoteTile::create(float play_time, float good_interval,
|
||||||
std::unique_ptr<NoteTile>(new NoteTile(play_time, good_interval, place)));
|
std::unique_ptr<NoteTile>(new NoteTile(play_time, good_interval, place)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NoteTile::checkPress(float press_time, NotePlaceEnum) {
|
bool NoteTile::checkPress(float press_time, NotePlaceEnum key_pressed) {
|
||||||
for (const auto ¬e_tile : NoteTile::existing_tiles) {
|
for (const auto ¬e_tile : NoteTile::existing_tiles) {
|
||||||
if (note_tile->play_time - note_tile->good_interval / 2 < press_time &&
|
if (note_tile->play_time - note_tile->good_interval / 2 < press_time &&
|
||||||
note_tile->play_time + note_tile->good_interval / 2 > press_time) {
|
note_tile->play_time + note_tile->good_interval / 2 > press_time &&
|
||||||
|
note_tile->place == key_pressed) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,35 @@
|
||||||
|
|
||||||
namespace NoteTile_test {
|
namespace NoteTile_test {
|
||||||
|
|
||||||
|
/*TEST(NoteFileTest, No) { EXPECT_EQ(0, 1); }*/
|
||||||
TEST(NoteFileTest, Yes) { EXPECT_EQ(0, 0); }
|
TEST(NoteFileTest, Yes) { EXPECT_EQ(0, 0); }
|
||||||
|
|
||||||
TEST(NoteFileTest, No) { EXPECT_EQ(0, 1); }
|
|
||||||
TEST(NoteTileTest, CreateTile) {
|
TEST(NoteTileTest, CreateTile) {
|
||||||
NoteTile::clear();
|
NoteTile::clear();
|
||||||
NoteTile::create(2.0f, 0.5f, NotePlaceEnum::Right);
|
NoteTile::create(2.0f, 0.5f, NotePlaceEnum::Right);
|
||||||
EXPECT_FLOAT_EQ(NoteTile::getExistingTiles()[0]->getPlayTime(), 2.0f);
|
EXPECT_FLOAT_EQ(NoteTile::getExistingTiles()[0]->getPlayTime(), 2.0f);
|
||||||
EXPECT_FLOAT_EQ(NoteTile::getExistingTiles()[0]->getGoodInterval(), 0.5f);
|
EXPECT_FLOAT_EQ(NoteTile::getExistingTiles()[0]->getGoodInterval(), 0.5f);
|
||||||
EXPECT_EQ(NoteTile::getExistingTiles()[0]->getPlace(), NotePlaceEnum::Right);
|
EXPECT_EQ(NoteTile::getExistingTiles()[0]->getPlace(), NotePlaceEnum::Right);
|
||||||
|
NoteTile::clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pour rappel good_interval c'est l'intervalle entier, donc la marge en positif
|
||||||
|
// est negatif est divisé par 2, voir checkPress
|
||||||
|
TEST(NoteTileTest, CheckGoodPress) {
|
||||||
|
NoteTile::clear();
|
||||||
|
NoteTile::create(2.0f, 0.5f, NotePlaceEnum::Right);
|
||||||
|
NoteTile::create(3.0f, 0.5f, NotePlaceEnum::Middle);
|
||||||
|
NoteTile::create(0.5f, 0.2f, NotePlaceEnum::Left);
|
||||||
|
|
||||||
|
EXPECT_FALSE(NoteTile::checkPress(1.0f, NotePlaceEnum::Left));
|
||||||
|
EXPECT_FALSE(NoteTile::checkPress(0.7f, NotePlaceEnum::Left));
|
||||||
|
EXPECT_FALSE(NoteTile::checkPress(0.6f, NotePlaceEnum::Middle));
|
||||||
|
EXPECT_FALSE(NoteTile::checkPress(3.5f, NotePlaceEnum::Right));
|
||||||
|
|
||||||
|
EXPECT_TRUE(NoteTile::checkPress(2.2f, NotePlaceEnum::Right));
|
||||||
|
EXPECT_TRUE(NoteTile::checkPress(1.8f, NotePlaceEnum::Right));
|
||||||
|
EXPECT_TRUE(NoteTile::checkPress(3.2f, NotePlaceEnum::Middle));
|
||||||
|
EXPECT_TRUE(NoteTile::checkPress(0.45f, NotePlaceEnum::Left));
|
||||||
|
}
|
||||||
|
|
||||||
}; // namespace NoteTile_test
|
}; // namespace NoteTile_test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue