Files

109 lines
3.1 KiB
C++
Raw Permalink Normal View History

2018-06-15 14:07:34 +02:00
/*****************************************************************************
2024-12-31 20:30:04 +01:00
* Copyright (c) 2014-2025 OpenRCT2 developers
2018-06-15 14:07:34 +02:00
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
2018-06-22 22:29:03 +02:00
#include "TestData.h"
2017-01-10 12:57:55 +00:00
#include <gtest/gtest.h>
#include <openrct2/Context.h>
2018-06-22 22:29:03 +02:00
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
2018-06-22 22:29:03 +02:00
#include <openrct2/OpenRCT2.h>
2017-05-17 19:12:02 +01:00
#include <openrct2/core/File.h>
2017-01-10 12:57:55 +00:00
#include <openrct2/core/Path.hpp>
#include <openrct2/core/String.hpp>
2018-06-22 22:29:03 +02:00
#include <openrct2/ride/Ride.h>
#include <openrct2/ride/RideData.h>
#include <openrct2/ride/RideManager.hpp>
2018-06-22 22:29:03 +02:00
#include <string>
2017-01-10 12:57:55 +00:00
using namespace OpenRCT2;
2017-01-10 12:57:55 +00:00
class RideRatings : public testing::Test
{
protected:
void CalculateRatingsForAllRides()
{
auto& gameState = getGameState();
for (const auto& ride : RideManager(gameState))
{
RideRating::UpdateRide(ride);
}
}
void DumpRatings()
{
auto& gameState = getGameState();
for (const auto& ride : RideManager(gameState))
{
std::string line = FormatRatings(ride);
printf("%s\n", line.c_str());
}
}
std::string FormatRatings(const Ride& ride)
{
RideRating::Tuple ratings = ride.ratings;
2025-03-09 00:26:25 +01:00
auto name = std::string(ride.getRideTypeDescriptor().Name);
2024-12-11 22:28:31 +01:00
std::string line = String::stdFormat(
2024-11-23 00:10:18 +01:00
"%s: (%d, %d, %d)", name.c_str(), static_cast<int>(ratings.excitement), static_cast<int>(ratings.intensity),
static_cast<int>(ratings.nausea));
return line;
}
2023-04-26 17:45:32 +03:00
void TestRatings(const u8string& parkFile, uint16_t expectedRideCount)
{
const auto parkFilePath = TestData::GetParkPath(parkFile);
const auto ratingsDataPath = Path::Combine(TestData::GetBasePath(), u8"ratings", parkFile + u8".txt");
// Load expected ratings
auto expectedRatings = File::ReadAllLines(ratingsDataPath);
ASSERT_FALSE(expectedRatings.empty());
gOpenRCT2Headless = true;
gOpenRCT2NoGraphics = true;
auto context = CreateContext();
bool initialised = context->Initialise();
ASSERT_TRUE(initialised);
GetContext()->LoadParkFromFile(parkFilePath);
// Check ride count to check load was successful
ASSERT_EQ(RideGetCount(), expectedRideCount);
CalculateRatingsForAllRides();
// Check ride ratings
int expI = 0;
auto& gameState = getGameState();
for (const auto& ride : RideManager(gameState))
2023-04-26 17:45:32 +03:00
{
auto actual = FormatRatings(ride);
auto expected = expectedRatings[expI];
ASSERT_STREQ(actual.c_str(), expected.c_str());
expI++;
}
}
2017-01-10 12:57:55 +00:00
};
2023-04-26 17:45:32 +03:00
TEST_F(RideRatings, bpb)
2017-01-10 12:57:55 +00:00
{
2023-04-26 17:45:32 +03:00
TestRatings("bpb.sv6", 134);
}
2017-01-10 12:57:55 +00:00
2023-04-26 17:45:32 +03:00
TEST_F(RideRatings, BigMap)
{
TestRatings("BigMapTest.sv6", 100);
2017-01-10 12:57:55 +00:00
}
TEST_F(RideRatings, EverythingPark)
{
TestRatings("EverythingPark.park", 529);
}