The NEW Pong Game V13.2.1
An interesting implemnettaion of the pong game
Loading...
Searching...
No Matches
ball_test.cpp File Reference

Test suite for the Ball classes functionality. More...

#include "../ball_base.hpp"
#include "../classic_ball.hpp"
#include "../square_ball.hpp"
#include "../triangle_ball.hpp"
#include "../paddle.hpp"
#include "../user.hpp"
#include <cassert>
#include <iostream>
#include <SDL.h>

Functions

void cleanup_sdl ()
 Cleans up SDL resources.
 
int main ()
 Main test runner function.
 
bool setup_sdl ()
 Sets up the SDL environment for tests.
 
void test_ball_boundaries ()
 Tests ball collision boundaries.
 
void test_ball_color ()
 Tests color change functionality.
 
void test_ball_initialization ()
 Tests the BallBase initialization and getters.
 
void test_ball_movement ()
 Tests position and velocity setters and getters.
 
void test_ball_rendering ()
 Tests the rendering of different ball types.
 
void test_ball_reset ()
 Tests the ball reset functionality.
 
void test_ball_sizes ()
 Tests that different ball subclasses have correct sizes.
 

Variables

SDL_Renderer * renderer = nullptr
 
SDL_Window * window = nullptr
 

Detailed Description

Test suite for the Ball classes functionality.

Authors
Vasileios Filippos Skarleas

This file contains tests for verifying the proper functionality of our Ball classes hierarchy. We test the base class functionality and derived class implementations.

Function Documentation

◆ cleanup_sdl()

void cleanup_sdl ( )

Cleans up SDL resources.

Destroys the renderer and window, and quits SDL

◆ main()

int main ( )

Main test runner function.

Executes all Ball class tests and reports results.

Returns
0 on successful test completion, non-zero on failure

◆ setup_sdl()

bool setup_sdl ( )

Sets up the SDL environment for tests.

Initializes SDL, creates a hidden window, and sets up a renderer for testing ball rendering functionality.

Returns
true if initialization successful, false otherwise

◆ test_ball_boundaries()

void test_ball_boundaries ( )

Tests ball collision boundaries.

Ensures that the ball's collision rectangle is properly calculated.

◆ test_ball_color()

void test_ball_color ( )

Tests color change functionality.

Verifies that ball color can be properly set and retrieved.

◆ test_ball_initialization()

void test_ball_initialization ( )

Tests the BallBase initialization and getters.

Verifies that the ball is initialized at the center of the screen, with proper size and non-zero velocities.

◆ test_ball_movement()

void test_ball_movement ( )

Tests position and velocity setters and getters.

Ensures we can properly set and retrieve ball position and velocity.

◆ test_ball_rendering()

void test_ball_rendering ( )

Tests the rendering of different ball types.

Verifies that each ball type can be rendered without errors. Note: This only tests that the render call doesn't crash, not the actual visual appearance.

◆ test_ball_reset()

void test_ball_reset ( )

Tests the ball reset functionality.

Checks if the ball correctly resets to center position and gets a new random direction.

◆ test_ball_sizes()

void test_ball_sizes ( )

Tests that different ball subclasses have correct sizes.

Each ball type can have its own default size, this test verifies they're initialized correctly.

Variable Documentation

◆ renderer

SDL_Renderer* renderer = nullptr

◆ window

SDL_Window* window = nullptr