pub struct StatsSnapshot {
sum: u64,
tps: f64,
times: u64,
avgpt: f64,
}
impl Default for StatsSnapshot {
fn default() -> Self {
Self::new()
}
}
impl StatsSnapshot {
pub fn new() -> Self {
StatsSnapshot {
sum: 0,
tps: 0.0,
times: 0,
avgpt: 0.0,
}
}
pub fn get_sum(&self) -> u64 {
self.sum
}
pub fn set_sum(&mut self, sum: u64) {
self.sum = sum;
}
pub fn get_tps(&self) -> f64 {
self.tps
}
pub fn set_tps(&mut self, tps: f64) {
self.tps = tps;
}
pub fn get_avgpt(&self) -> f64 {
self.avgpt
}
pub fn set_avgpt(&mut self, avgpt: f64) {
self.avgpt = avgpt;
}
pub fn get_times(&self) -> u64 {
self.times
}
pub fn set_times(&mut self, times: u64) {
self.times = times;
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn stats_snapshot_initializes_correctly() {
let snapshot = StatsSnapshot::new();
assert_eq!(snapshot.get_sum(), 0);
assert_eq!(snapshot.get_tps(), 0.0);
assert_eq!(snapshot.get_times(), 0);
assert_eq!(snapshot.get_avgpt(), 0.0);
}
#[test]
fn stats_snapshot_updates_sum_correctly() {
let mut snapshot = StatsSnapshot::new();
snapshot.set_sum(100);
assert_eq!(snapshot.get_sum(), 100);
}
#[test]
fn stats_snapshot_updates_tps_correctly() {
let mut snapshot = StatsSnapshot::new();
snapshot.set_tps(1.5);
assert_eq!(snapshot.get_tps(), 1.5);
}
#[test]
fn stats_snapshot_updates_avgpt_correctly() {
let mut snapshot = StatsSnapshot::new();
snapshot.set_avgpt(2.5);
assert_eq!(snapshot.get_avgpt(), 2.5);
}
#[test]
fn stats_snapshot_updates_times_correctly() {
let mut snapshot = StatsSnapshot::new();
snapshot.set_times(200);
assert_eq!(snapshot.get_times(), 200);
}
}