MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / better_than_raw_on_structured

Function better_than_raw_on_structured

nodedb-codec/src/rans.rs:421–436  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

419
420 #[test]
421 fn better_than_raw_on_structured() {
422 // Structured data after type-aware preprocessing (typical pipeline output).
423 let mut data = Vec::with_capacity(10_000);
424 for i in 0..10_000 {
425 data.push((i % 16) as u8); // Low entropy, 4 bits/byte → 2x compression.
426 }
427 let encoded = encode(&data);
428 let decoded = decode(&encoded).unwrap();
429 assert_eq!(decoded, data);
430
431 let ratio = data.len() as f64 / encoded.len() as f64;
432 assert!(
433 ratio > 1.5,
434 "low-entropy data should compress >1.5x, got {ratio:.1}x"
435 );
436 }
437
438 #[test]
439 fn truncated_input_errors() {

Callers

nothing calls this directly

Calls 4

encodeFunction · 0.70
decodeFunction · 0.70
pushMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected