Files
pokemon-battle-engine/tests/unit/core/test_example.cpp
cdemeyer-teachx 1c1e7f8d51 Google Tests
2025-08-14 10:19:03 +09:00

76 lines
2.0 KiB
C++

#include <gtest/gtest.h>
// Example test case demonstrating Google Test usage
class ExampleTest : public ::testing::Test {
protected:
void SetUp() override {
// Set up test fixtures here
}
void TearDown() override {
// Clean up test fixtures here
}
};
// Basic assertion test
TEST_F(ExampleTest, BasicAssertions) {
// Basic equality assertions
EXPECT_EQ(2 + 2, 4);
EXPECT_NE(2 + 2, 5);
// Boolean assertions
EXPECT_TRUE(true);
EXPECT_FALSE(false);
// String assertions
EXPECT_STREQ("hello", "hello");
EXPECT_STRNE("hello", "world");
}
// Test with parameters
TEST(ParameterizedTest, Addition) {
EXPECT_EQ(1 + 1, 2);
EXPECT_EQ(10 + 5, 15);
EXPECT_EQ(-1 + 1, 0);
}
// Test that demonstrates failure (using TEST_F to match the fixture)
TEST_F(ExampleTest, ThisWillFail) {
// This test will fail to demonstrate the failure output
// EXPECT_EQ(2 + 2, 5); // Uncomment this line to see a failing test
}
// Example of how you might test a Pokemon battle simulator component
// This demonstrates testing the placeholder implementation we created
#include "pokemon_battle_sim.h"
TEST(PokemonTest, PokemonCreation) {
PokemonSim::Pokemon pikachu("Pikachu", 100);
// Test basic properties
EXPECT_EQ(pikachu.getName(), "Pikachu");
EXPECT_EQ(pikachu.getHealth(), 100);
}
TEST(PokemonTest, PokemonHealthModification) {
PokemonSim::Pokemon charizard("Charizard", 150);
EXPECT_EQ(charizard.getHealth(), 150);
charizard.setHealth(100);
EXPECT_EQ(charizard.getHealth(), 100);
}
TEST(PokemonTest, BattleSimulation) {
PokemonSim::Pokemon pokemon1("Pokemon1", 50);
PokemonSim::Pokemon pokemon2("Pokemon2", 30);
// Pokemon1 should win because it has more health
bool result = PokemonSim::simulateBattle(pokemon1, pokemon2);
EXPECT_TRUE(result); // Pokemon1 wins
// Both Pokemon should have taken damage
EXPECT_LT(pokemon1.getHealth(), 50);
EXPECT_LE(pokemon2.getHealth(), 0);
}