5d20e43f-cfcc-4489-bd25-9c8b412f3386
This commit is contained in:
107
tests/unit/core/test_pokemon_table.cpp
Normal file
107
tests/unit/core/test_pokemon_table.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "core/pokemon_table.h"
|
||||
|
||||
using namespace PokEng;
|
||||
|
||||
class PokemonTableTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
// Initialize the global Pokemon table for each test
|
||||
ASSERT_TRUE(initializePokemonTable());
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
// Clean up the global Pokemon table after each test
|
||||
shutdownPokemonTable();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(PokemonTableTest, Initialization) {
|
||||
ASSERT_TRUE(g_pokemonTable != nullptr);
|
||||
EXPECT_GT(g_pokemonTable->size(), 0);
|
||||
EXPECT_GT(g_pokemonTable->getMaxId(), 0);
|
||||
}
|
||||
|
||||
TEST_F(PokemonTableTest, BulbasaurLookup) {
|
||||
const auto* bulbasaur = g_pokemonTable->getPokemon(1);
|
||||
ASSERT_TRUE(bulbasaur != nullptr);
|
||||
EXPECT_EQ(bulbasaur->id, 1);
|
||||
EXPECT_EQ(bulbasaur->name, "bulbasaur");
|
||||
EXPECT_EQ(bulbasaur->base_stats.hp, 45);
|
||||
EXPECT_EQ(bulbasaur->base_stats.attack, 49);
|
||||
EXPECT_EQ(bulbasaur->base_stats.defense, 49);
|
||||
EXPECT_EQ(bulbasaur->base_stats.sp_attack, 65);
|
||||
EXPECT_EQ(bulbasaur->base_stats.sp_defense, 65);
|
||||
EXPECT_EQ(bulbasaur->base_stats.speed, 45);
|
||||
|
||||
// Check types
|
||||
EXPECT_EQ(bulbasaur->types.getPrimary(), Type::GRASS);
|
||||
EXPECT_EQ(bulbasaur->types.getSecondary(), Type::POISON);
|
||||
}
|
||||
|
||||
TEST_F(PokemonTableTest, NameBasedLookup) {
|
||||
const auto* charizard = g_pokemonTable->getPokemonByName("charizard");
|
||||
ASSERT_TRUE(charizard != nullptr);
|
||||
EXPECT_EQ(charizard->id, 6); // Charizard's ID
|
||||
EXPECT_EQ(charizard->name, "charizard");
|
||||
}
|
||||
|
||||
TEST_F(PokemonTableTest, InvalidIdLookup) {
|
||||
const auto* invalid = g_pokemonTable->getPokemon(99999);
|
||||
EXPECT_TRUE(invalid == nullptr);
|
||||
|
||||
// Test ID 0 (should be invalid)
|
||||
const auto* zero = g_pokemonTable->getPokemon(0);
|
||||
EXPECT_TRUE(zero == nullptr);
|
||||
}
|
||||
|
||||
TEST_F(PokemonTableTest, InvalidNameLookup) {
|
||||
const auto* invalid = g_pokemonTable->getPokemonByName("nonexistentpokemon");
|
||||
EXPECT_TRUE(invalid == nullptr);
|
||||
}
|
||||
|
||||
TEST_F(PokemonTableTest, HasPokemonFunction) {
|
||||
EXPECT_TRUE(g_pokemonTable->hasPokemon(1)); // Bulbasaur
|
||||
EXPECT_TRUE(g_pokemonTable->hasPokemon(150)); // Mewtwo
|
||||
EXPECT_FALSE(g_pokemonTable->hasPokemon(0));
|
||||
EXPECT_FALSE(g_pokemonTable->hasPokemon(99999));
|
||||
}
|
||||
|
||||
TEST_F(PokemonTableTest, PerformanceTest) {
|
||||
// Test that lookups are fast enough (less than 1ms for 1000 lookups)
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
uint16_t id = (i % g_pokemonTable->getMaxId()) + 1;
|
||||
const auto* pokemon = g_pokemonTable->getPokemon(id);
|
||||
ASSERT_TRUE(pokemon != nullptr);
|
||||
// Just access some data to ensure the pointer is valid
|
||||
volatile uint16_t hp = pokemon->base_stats.hp;
|
||||
(void)hp; // Prevent optimization
|
||||
}
|
||||
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||
|
||||
// Should be much faster than 1ms for 1000 lookups
|
||||
EXPECT_LT(duration.count(), 1);
|
||||
}
|
||||
|
||||
TEST_F(PokemonTableTest, Validation) {
|
||||
EXPECT_TRUE(g_pokemonTable->validate());
|
||||
}
|
||||
|
||||
TEST_F(PokemonTableTest, MewtwoStats) {
|
||||
const auto* mewtwo = g_pokemonTable->getPokemon(150);
|
||||
ASSERT_TRUE(mewtwo != nullptr);
|
||||
EXPECT_EQ(mewtwo->id, 150);
|
||||
EXPECT_EQ(mewtwo->name, "mewtwo");
|
||||
EXPECT_EQ(mewtwo->base_stats.hp, 106);
|
||||
EXPECT_EQ(mewtwo->base_stats.attack, 110);
|
||||
EXPECT_EQ(mewtwo->base_stats.defense, 90);
|
||||
EXPECT_EQ(mewtwo->base_stats.sp_attack, 154);
|
||||
EXPECT_EQ(mewtwo->base_stats.sp_defense, 90);
|
||||
EXPECT_EQ(mewtwo->base_stats.speed, 130);
|
||||
EXPECT_EQ(mewtwo->types.getPrimary(), Type::PSYCHIC);
|
||||
EXPECT_EQ(mewtwo->types.getSecondary(), Type::NONE);
|
||||
}
|
||||
Reference in New Issue
Block a user