#[inline]
pub fn estimate_content_capacity(file_size: u64, format: &str) -> usize {
let ratio = match format.to_lowercase().as_str() {
"txt" | "text" => 0.95,
"md" | "markdown" => 0.95,
"html" | "htm" => 0.65,
"docx" | "doc" => 0.45,
"xlsx" | "xls" | "xlsm" | "xlam" | "xltm" | "xlsb" => 0.40,
"pptx" | "ppt" | "pptm" | "ppsx" => 0.35,
"pdf" => 0.25,
_ => 0.50,
};
(file_size as f64 * ratio).ceil() as usize
}
#[inline]
pub fn estimate_html_markdown_capacity(html_size: u64) -> usize {
let estimated = (html_size as f64 * 0.65).ceil() as usize;
estimated.max(64)
}
#[inline]
pub fn estimate_spreadsheet_capacity(file_size: u64) -> usize {
let estimated = (file_size as f64 * 0.40).ceil() as usize;
estimated.max(64)
}
#[inline]
pub fn estimate_presentation_capacity(file_size: u64) -> usize {
let estimated = (file_size as f64 * 0.35).ceil() as usize;
estimated.max(64)
}
#[inline]
pub fn estimate_table_markdown_capacity(row_count: usize, col_count: usize) -> usize {
let base = 50 + (col_count * 5);
let cell_estimate = row_count.saturating_mul(col_count).saturating_mul(12);
base.saturating_add(cell_estimate).max(64)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_estimate_content_capacity_text() {
let capacity = estimate_content_capacity(1_000_000, "txt");
assert_eq!(capacity, 950_000);
}
#[test]
fn test_estimate_content_capacity_markdown() {
let capacity = estimate_content_capacity(1_000_000, "md");
assert_eq!(capacity, 950_000);
}
#[test]
fn test_estimate_content_capacity_html() {
let capacity = estimate_content_capacity(1_000_000, "html");
assert_eq!(capacity, 650_000);
}
#[test]
fn test_estimate_content_capacity_docx() {
let capacity = estimate_content_capacity(1_000_000, "docx");
assert_eq!(capacity, 450_000);
}
#[test]
fn test_estimate_content_capacity_xlsx() {
let capacity = estimate_content_capacity(1_000_000, "xlsx");
assert_eq!(capacity, 400_000);
}
#[test]
fn test_estimate_content_capacity_pptx() {
let capacity = estimate_content_capacity(1_000_000, "pptx");
assert_eq!(capacity, 350_000);
}
#[test]
fn test_estimate_content_capacity_pdf() {
let capacity = estimate_content_capacity(1_000_000, "pdf");
assert_eq!(capacity, 250_000);
}
#[test]
fn test_estimate_content_capacity_unknown() {
let capacity = estimate_content_capacity(1_000_000, "unknown");
assert_eq!(capacity, 500_000);
}
#[test]
fn test_estimate_content_capacity_case_insensitive() {
let lower = estimate_content_capacity(1_000_000, "html");
let upper = estimate_content_capacity(1_000_000, "HTML");
let mixed = estimate_content_capacity(1_000_000, "HtMl");
assert_eq!(lower, upper);
assert_eq!(lower, mixed);
}
#[test]
fn test_html_markdown_capacity() {
let capacity = estimate_html_markdown_capacity(1_000_000);
assert_eq!(capacity, 650_000);
}
#[test]
fn test_html_markdown_capacity_minimum() {
let capacity = estimate_html_markdown_capacity(10);
assert!(capacity >= 64);
}
#[test]
fn test_spreadsheet_capacity() {
let capacity = estimate_spreadsheet_capacity(1_000_000);
assert_eq!(capacity, 400_000);
}
#[test]
fn test_presentation_capacity() {
let capacity = estimate_presentation_capacity(1_000_000);
assert_eq!(capacity, 350_000);
}
#[test]
fn test_table_markdown_capacity() {
let capacity = estimate_table_markdown_capacity(10, 5);
assert_eq!(capacity, 675);
}
#[test]
fn test_table_markdown_capacity_minimum() {
let capacity = estimate_table_markdown_capacity(0, 0);
assert!(capacity >= 64);
}
#[test]
fn test_capacity_overflow_resistance() {
let capacity = estimate_content_capacity(u64::MAX, "txt");
assert!(capacity > 0);
}
}