From ff3171d9e7ba81ed6b33f32b0da20b56b861326b Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 20:54:36 -0400 Subject: [PATCH] tsk-44: Updating tests --- src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 16f20a3..97c6803 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,8 @@ pub mod test_util { pub mod util { use std::io::{self, Write}; + use rand::Rng; + // Function to save a Vec to a file pub fn save_bytes_to_file(bytes: &[u8], file_path: &String) -> io::Result<()> { let file = std::path::Path::new(file_path); @@ -44,6 +46,25 @@ pub mod test_util { } } + pub fn generate_filename() -> Result { + let mut filename = String::from("track-"); + let length = 20; + let characters = "abcdef0123456789"; + let amount_of_characters = characters.len() - 1; + let mut rng = rand::rng(); + + for _ in 0..length { + let index = rng.random_range(0..=amount_of_characters); + let random_c = characters.chars().nth(index); + + if let Some(c) = random_c { + filename.push(c); + } + } + + Ok(format!("{filename}.flac")) + } + fn path_buf( directory: &String, filename: &String,