Expand test

This commit is contained in:
Dominik Werder
2025-06-04 11:30:02 +02:00
parent 9d20359126
commit 98286a7cc1
2 changed files with 145 additions and 13 deletions

View File

@@ -54,6 +54,8 @@ autoerr::create_error_v1!(
},
);
const DO_DISCARD_FRONT: bool = true;
fn bin_len_clamp(dur: DtMs) -> PrebinnedPartitioning {
if dur < DtMs::from_ms_u64(1000 * 2) {
PrebinnedPartitioning::Sec1
@@ -480,7 +482,7 @@ impl BinWriter {
let e = Error::UnexpectedBinLen(bin_len, pbp);
return Err(e);
}
if false && *discard_front < 1 {
if DO_DISCARD_FRONT && *discard_front < 1 {
*discard_front += 1;
debug_bin!(trd, "handle_output_ready discard_front {:?}", rt);
} else {

View File

@@ -6,11 +6,14 @@ use netpod::ScalarType;
use netpod::Shape;
use netpod::TsMs;
use netpod::TsNano;
use netpod::f32_close;
use scywr::insertqueues::InsertDeques;
use scywr::iteminsertqueue::QueryItem;
use scywr::iteminsertqueue::TimeBinSimpleF32V02;
use series::ChannelStatusSeriesId;
use series::SeriesId;
use series::msp::LspU32;
use series::msp::MspU32;
use series::msp::PrebinnedPartitioning;
use std::collections::VecDeque;
@@ -31,6 +34,120 @@ macro_rules! debug_item {
};
}
struct BinsExp {
pbp: PrebinnedPartitioning,
curmsp: MspU32,
curlsp: LspU32,
msp: VecDeque<u32>,
lsp: VecDeque<u32>,
cnt: VecDeque<Option<u32>>,
min: VecDeque<Option<f32>>,
max: VecDeque<Option<f32>>,
}
impl BinsExp {
fn new(pbp: PrebinnedPartitioning, msp: MspU32, lsp: LspU32) -> Self {
Self {
pbp,
curmsp: msp,
curlsp: lsp,
msp: def(),
lsp: def(),
cnt: def(),
min: def(),
max: def(),
}
}
fn len(&self) -> usize {
self.msp.len()
}
fn inc_lsp(&mut self) {
let (m2, l2) = self.pbp.lsp_inc(self.curmsp, self.curlsp);
self.curmsp = m2;
self.curlsp = l2;
}
fn push_back_dont_care(&mut self) {
self.msp.push_back(self.curmsp.0);
self.lsp.push_back(self.curlsp.0);
self.cnt.push_back(None);
self.min.push_back(None);
self.max.push_back(None);
self.inc_lsp();
}
fn push_back_cnt(&mut self, cnt: u32) {
self.msp.push_back(self.curmsp.0);
self.lsp.push_back(self.curlsp.0);
self.cnt.push_back(Some(cnt));
self.min.push_back(None);
self.max.push_back(None);
self.inc_lsp();
}
fn push_back_cmm(&mut self, cnt: u32, min: f32, max: f32) {
self.msp.push_back(self.curmsp.0);
self.lsp.push_back(self.curlsp.0);
self.cnt.push_back(Some(cnt));
self.min.push_back(Some(min));
self.max.push_back(Some(max));
self.inc_lsp();
}
fn cmp(&self, bins: &VecDeque<TimeBinSimpleF32V02>) -> Result<(), ()> {
let mut bad = false;
for i in 0..self.msp.len() {
let bin = if let Some(x) = bins.get(i) {
x
} else {
break;
};
let msp = self.msp[i];
let lsp = self.lsp[i];
let cnt = self.cnt[i];
let min = self.min[i];
let max = self.max[i];
if bin.msp as u32 != msp {
bad = true;
info!("bad msp {} vs {}", bin.msp, msp);
}
if bin.off as u32 != lsp {
bad = true;
info!("bad lsp {} vs {}", bin.off, lsp);
}
if let Some(cnt) = cnt {
if bin.cnt as u32 != cnt {
bad = true;
info!("bad cnt {} vs {}", bin.cnt, cnt);
}
}
if let Some(min) = min {
if !f32_close(bin.min, min) {
bad = true;
info!("bad min {:.5e} vs {:.5e}", bin.min, min);
}
}
if let Some(max) = max {
if !f32_close(bin.max, max) {
bad = true;
info!("bad max {:.5e} vs {:.5e}", bin.max, max);
}
}
}
if self.len() > bins.len() {
bad = true;
info!("expect more bins {} vs {}", self.len(), bins.len());
}
if self.len() < bins.len() {
bad = true;
info!("expect less bins {} vs {}", self.len(), bins.len());
}
if bad { Err(()) } else { Ok(()) }
}
}
fn def<T: Default>() -> T {
Default::default()
}
@@ -125,28 +242,41 @@ fn binwriter_nest01_00() {
let x = pbp.msp_lsp(T0);
let msp_exp = T0.ms() / pbp.bin_len().ms() / pbp.patch_len() as u64;
assert_eq!(x.0 as u64, msp_exp);
let x = pbp.msp_lsp(sec(39.9).to_ts_ms());
let i = 0;
assert_eq!(binscol[i].msp as u32, x.0);
assert_eq!(binscol[i].off as u32, x.1);
assert_eq!(binscol[i].min, 2.2);
assert_eq!(binscol[i].max, 2.2);
let x = pbp.msp_lsp(sec(40.0).to_ts_ms());
let i = 1;
assert_eq!(binscol[i].msp as u32, x.0);
assert_eq!(binscol[i].off as u32, x.1);
assert_eq!(binscol[i].min, 2.0);
assert_eq!(binscol[i].max, 2.0);
{
let (msp, lsp) = pbp.msp_lsp(sec(40.0).to_ts_ms());
let mut exp = BinsExp::new(pbp.clone(), MspU32(msp), LspU32(lsp));
// exp.push_back_cnt(2);
exp.push_back_cmm(2, 2.0, 2.0);
for _ in 0..9 {
exp.push_back_dont_care();
}
exp.push_back_cmm(2, 2.0, 2.0);
for _ in 0..9 {
exp.push_back_dont_care();
}
for _ in 0..20 {
exp.push_back_dont_care();
}
exp.cmp(&binscol).unwrap();
}
}
{
let rt = "MT";
let binscol = collect_bin_write_only(&iqdqs.mt_rf3_qu);
print_binscol(rt, &binscol);
let pbp = PrebinnedPartitioning::Sec10;
let x = pbp.msp_lsp(T0);
let msp_exp = T0.ms() / pbp.bin_len().ms() / pbp.patch_len() as u64;
assert_eq!(x.0 as u64, msp_exp);
}
{
let rt = "LT";
let binscol = collect_bin_write_only(&iqdqs.lt_rf3_qu);
print_binscol(rt, &binscol);
let pbp = PrebinnedPartitioning::Min1;
let x = pbp.msp_lsp(T0);
let msp_exp = T0.ms() / pbp.bin_len().ms() / pbp.patch_len() as u64;
assert_eq!(x.0 as u64, msp_exp);
}
{
let pbp = PrebinnedPartitioning::Sec10;