#[derive(Debug, Clone)]
pub struct Profile4State {
pub(crate) protect_counter: u16,
pub(crate) last_counter: Option<u16>,
}
impl Profile4State {
#[must_use]
pub fn new() -> Self {
Self {
protect_counter: 0,
last_counter: None,
}
}
#[must_use]
pub fn with_initial_counter(counter: u16) -> Self {
Self {
protect_counter: counter,
last_counter: None,
}
}
#[must_use]
pub const fn protect_counter(&self) -> u16 {
self.protect_counter
}
#[must_use]
pub const fn last_counter(&self) -> Option<u16> {
self.last_counter
}
pub fn reset(&mut self) {
self.protect_counter = 0;
self.last_counter = None;
}
}
impl Default for Profile4State {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct Profile5State {
pub(crate) protect_counter: u8,
pub(crate) last_counter: Option<u8>,
}
impl Profile5State {
#[must_use]
pub fn new() -> Self {
Self {
protect_counter: 0,
last_counter: None,
}
}
#[must_use]
pub fn with_initial_counter(counter: u8) -> Self {
Self {
protect_counter: counter,
last_counter: None,
}
}
#[must_use]
pub const fn protect_counter(&self) -> u8 {
self.protect_counter
}
#[must_use]
pub const fn last_counter(&self) -> Option<u8> {
self.last_counter
}
pub fn reset(&mut self) {
self.protect_counter = 0;
self.last_counter = None;
}
}
impl Default for Profile5State {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn profile4_reset_clears_state() {
let mut state = Profile4State::with_initial_counter(42);
state.last_counter = Some(10);
state.reset();
assert_eq!(state.protect_counter, 0);
assert!(state.last_counter.is_none());
}
#[test]
fn profile4_default_matches_new() {
let from_new = Profile4State::new();
let from_default = Profile4State::default();
assert_eq!(from_new.protect_counter, from_default.protect_counter);
assert_eq!(from_new.last_counter, from_default.last_counter);
}
#[test]
fn profile5_reset_clears_state() {
let mut state = Profile5State::with_initial_counter(42);
state.last_counter = Some(10);
state.reset();
assert_eq!(state.protect_counter, 0);
assert!(state.last_counter.is_none());
}
#[test]
fn profile5_default_matches_new() {
let from_new = Profile5State::new();
let from_default = Profile5State::default();
assert_eq!(from_new.protect_counter, from_default.protect_counter);
assert_eq!(from_new.last_counter, from_default.last_counter);
}
#[test]
fn profile4_with_initial_counter_sets_counter() {
let state = Profile4State::with_initial_counter(42);
assert_eq!(state.protect_counter(), 42);
assert_eq!(state.last_counter(), None);
}
#[test]
fn profile4_accessors() {
let mut state = Profile4State::new();
assert_eq!(state.protect_counter(), 0);
assert_eq!(state.last_counter(), None);
state.protect_counter = 5;
state.last_counter = Some(3);
assert_eq!(state.protect_counter(), 5);
assert_eq!(state.last_counter(), Some(3));
}
#[test]
fn profile5_with_initial_counter_sets_counter() {
let state = Profile5State::with_initial_counter(42);
assert_eq!(state.protect_counter(), 42);
assert_eq!(state.last_counter(), None);
}
#[test]
fn profile5_accessors() {
let mut state = Profile5State::new();
assert_eq!(state.protect_counter(), 0);
assert_eq!(state.last_counter(), None);
state.protect_counter = 5;
state.last_counter = Some(3);
assert_eq!(state.protect_counter(), 5);
assert_eq!(state.last_counter(), Some(3));
}
}