Skip to content

Commit

Permalink
update images
Browse files Browse the repository at this point in the history
  • Loading branch information
RGGH committed Nov 14, 2024
1 parent 8f23b89 commit 6998d2a
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/image_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,65 @@ pub fn is_collision(rect1: (u32, u32, u32, u32), rect2: (u32, u32, u32, u32)) ->

x1 < x2 + w2 && x1 + w1 > x2 && y1 < y2 + h2 && y1 + h1 > y2
}

#[cfg(test)]
mod tests {
use super::*;
use std::time::Instant;

#[test]
fn test_draw_raindrop() {
let width = 10;
let height = 10;
let mut buffer = vec![0xFFFFFFFF; (width * height) as usize];

// Initialize Raindrop with current Instant for `last_update` and `start_time`
let raindrop = Raindrop {
x: 3,
y: 3,
last_update: Instant::now(),
start_time: Instant::now(),
};

draw_raindrop(&mut buffer, width, height, &raindrop);

// Check if the raindrop was drawn at the correct position
for y in 3..(3 + DROP_SIZE) {
for x in 3..(3 + DROP_SIZE) {
assert_eq!(buffer[(y * width + x) as usize], 0xFFFFFFFF);
}
}
}

#[test]
fn test_draw_square() {
let width = 10;
let height = 10;
let mut buffer = vec![0xFFFFFFFF; (width * height) as usize];

// Draw a 2x2 red square at (3, 3)
draw_square(&mut buffer, width, height, 3, 3, 2);

// Check if the square was drawn at the correct position
for y in 3..5 {
for x in 3..5 {
assert_eq!(buffer[(y * width + x) as usize], 0xFFFF0000);
}
}
}

#[test]
fn test_is_collision() {
// Define two rectangles
let rect1 = (0, 0, 2, 2);
let rect2 = (1, 1, 2, 2);

// Check if they collide
assert!(is_collision(rect1, rect2));

// Define a non-colliding rectangle
let rect3 = (5, 5, 2, 2);
assert!(!is_collision(rect1, rect3));
}

}

0 comments on commit 6998d2a

Please sign in to comment.