File: RideRatings.cpp

package info (click to toggle)
openrct2 0.4.3%2Bds-1
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm
  • size: 67,880 kB
  • sloc: cpp: 549,527; ansic: 1,322; sh: 441; python: 269; xml: 180; php: 34; makefile: 19
file content (90 lines) | stat: -rw-r--r-- 2,569 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*****************************************************************************
 * Copyright (c) 2014-2022 OpenRCT2 developers
 *
 * 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.
 *****************************************************************************/

#include "TestData.h"

#include <gtest/gtest.h>
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/audio/AudioContext.h>
#include <openrct2/core/File.h>
#include <openrct2/core/Path.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/platform/Platform.h>
#include <openrct2/ride/Ride.h>
#include <openrct2/ride/RideData.h>
#include <string>

using namespace OpenRCT2;

class RideRatings : public testing::Test
{
protected:
    void CalculateRatingsForAllRides()
    {
        for (const auto& ride : GetRideManager())
        {
            ride_ratings_update_ride(ride);
        }
    }

    void DumpRatings()
    {
        for (const auto& ride : GetRideManager())
        {
            std::string line = FormatRatings(ride);
            printf("%s\n", line.c_str());
        }
    }

    std::string FormatRatings(const Ride& ride)
    {
        RatingTuple ratings = ride.ratings;
        std::string line = String::StdFormat(
            "%s: (%d, %d, %d)", ride.GetRideTypeDescriptor().EnumName, static_cast<int>(ratings.Excitement),
            static_cast<int>(ratings.Intensity), static_cast<int>(ratings.Nausea));
        return line;
    }
};

TEST_F(RideRatings, all)
{
    std::string path = TestData::GetParkPath("bpb.sv6");

    gOpenRCT2Headless = true;
    gOpenRCT2NoGraphics = true;

    Platform::CoreInit();
    auto context = CreateContext();
    bool initialised = context->Initialise();
    ASSERT_TRUE(initialised);

    GetContext()->LoadParkFromFile(path);

    // Check ride count to check load was successful
    ASSERT_EQ(ride_get_count(), 134);

    CalculateRatingsForAllRides();

    // Load expected ratings
    auto expectedDataPath = Path::Combine(TestData::GetBasePath(), u8"ratings", u8"bpb.sv6.txt");
    auto expectedRatings = File::ReadAllLines(expectedDataPath);

    // Check ride ratings
    int expI = 0;
    for (const auto& ride : GetRideManager())
    {
        auto actual = FormatRatings(ride);
        auto expected = expectedRatings[expI];
        ASSERT_STREQ(actual.c_str(), expected.c_str());

        expI++;
    }
}