tests: revamp tests, remove more useless tests

This commit is contained in:
2025-08-08 09:07:10 -05:00
parent b308bc0ef7
commit 87ee12543e
12 changed files with 233 additions and 521 deletions
+15 -27
View File
@@ -2,13 +2,12 @@ use pacman::texture::sprite::{AtlasMapper, MapperFrame, SpriteAtlas};
use sdl2::pixels::Color;
use std::collections::HashMap;
// Mock texture for testing
fn mock_texture() -> sdl2::render::Texture<'static> {
unsafe { std::mem::transmute(0usize) }
}
#[test]
fn test_sprite_atlas_get_tile() {
fn test_sprite_atlas_basic() {
let mut frames = HashMap::new();
frames.insert(
"test".to_string(),
@@ -26,37 +25,12 @@ fn test_sprite_atlas_get_tile() {
let tile = atlas.get_tile("test");
assert!(tile.is_some());
let tile = tile.unwrap();
assert_eq!(tile.pos, glam::U16Vec2::new(10, 20));
assert_eq!(tile.size, glam::U16Vec2::new(32, 64));
assert_eq!(tile.color, None);
}
#[test]
fn test_sprite_atlas_get_tile_nonexistent() {
let mapper = AtlasMapper { frames: HashMap::new() };
let texture = mock_texture();
let atlas = SpriteAtlas::new(texture, mapper);
let tile = atlas.get_tile("nonexistent");
assert!(tile.is_none());
}
#[test]
fn test_sprite_atlas_set_color() {
let mapper = AtlasMapper { frames: HashMap::new() };
let texture = mock_texture();
let mut atlas = SpriteAtlas::new(texture, mapper);
assert_eq!(atlas.default_color(), None);
let color = Color::RGB(255, 0, 0);
atlas.set_color(color);
assert_eq!(atlas.default_color(), Some(color));
}
#[test]
fn test_sprite_atlas_multiple_tiles() {
let mut frames = HashMap::new();
@@ -87,4 +61,18 @@ fn test_sprite_atlas_multiple_tiles() {
assert!(atlas.has_tile("tile1"));
assert!(atlas.has_tile("tile2"));
assert!(!atlas.has_tile("tile3"));
assert!(atlas.get_tile("nonexistent").is_none());
}
#[test]
fn test_sprite_atlas_color() {
let mapper = AtlasMapper { frames: HashMap::new() };
let texture = mock_texture();
let mut atlas = SpriteAtlas::new(texture, mapper);
assert_eq!(atlas.default_color(), None);
let color = Color::RGB(255, 0, 0);
atlas.set_color(color);
assert_eq!(atlas.default_color(), Some(color));
}