#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct Slot {
pub time_ms: i64, pub first_pos: i64,
pub last_pos: i64,
pub num: i32,
pub magic: i32, }
impl Slot {
pub const SIZE: i16 = 32;
pub fn new(time_ms: i64, first_pos: i64, last_pos: i64) -> Self {
Slot {
time_ms,
first_pos,
last_pos,
num: 0,
magic: 0,
}
}
pub fn new_with_num_magic(time_ms: i64, first_pos: i64, last_pos: i64, num: i32, magic: i32) -> Self {
Slot {
time_ms,
first_pos,
last_pos,
num,
magic,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
fn create_slot() -> Slot {
Slot::new(1000, 10, 20)
}
#[test]
fn creates_slot_with_default_num_and_magic() {
let slot = Slot::new(1000, 10, 20);
assert_eq!(slot.time_ms, 1000);
assert_eq!(slot.first_pos, 10);
assert_eq!(slot.last_pos, 20);
assert_eq!(slot.num, 0);
assert_eq!(slot.magic, 0);
}
#[test]
fn creates_slot_with_custom_num_and_magic() {
let slot = Slot::new_with_num_magic(2000, 30, 40, 5, 99);
assert_eq!(slot.time_ms, 2000);
assert_eq!(slot.first_pos, 30);
assert_eq!(slot.last_pos, 40);
assert_eq!(slot.num, 5);
assert_eq!(slot.magic, 99);
}
#[test]
fn slot_size_constant_is_correct() {
assert_eq!(Slot::SIZE, 32);
}
#[test]
fn slots_with_same_values_are_equal() {
let slot1 = create_slot();
let slot2 = Slot::new(1000, 10, 20);
assert_eq!(slot1, slot2);
}
#[test]
fn slots_with_different_values_are_not_equal() {
let slot1 = create_slot();
let slot2 = Slot::new_with_num_magic(2000, 30, 40, 5, 99);
assert_ne!(slot1, slot2);
}
}