align_part function now passing tests. #2
This commit is contained in:
Generated
+42
-3
@@ -624,6 +624,17 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
||||
|
||||
[[package]]
|
||||
name = "chacha20"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"rand_core 0.10.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clipboard-win"
|
||||
version = "5.4.1"
|
||||
@@ -793,6 +804,15 @@ dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.5.0"
|
||||
@@ -1322,6 +1342,7 @@ dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi 6.0.0",
|
||||
"rand_core 0.10.1",
|
||||
"wasip2",
|
||||
"wasip3",
|
||||
]
|
||||
@@ -2008,6 +2029,7 @@ dependencies = [
|
||||
"blocking",
|
||||
"iced",
|
||||
"iced_moving_picture",
|
||||
"rand 0.10.1",
|
||||
"rust-i18n",
|
||||
"toml 1.1.2+spec-1.1.0",
|
||||
]
|
||||
@@ -3104,7 +3126,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44c5af06bb1b7d3216d91932aed5265164bf384dc89cd6ba05cf59a35f5f76ea"
|
||||
dependencies = [
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
"rand_core 0.9.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207"
|
||||
dependencies = [
|
||||
"chacha20",
|
||||
"getrandom 0.4.2",
|
||||
"rand_core 0.10.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3114,7 +3147,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
"rand_core 0.9.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3126,6 +3159,12 @@ dependencies = [
|
||||
"getrandom 0.3.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
|
||||
|
||||
[[package]]
|
||||
name = "range-alloc"
|
||||
version = "0.1.5"
|
||||
@@ -3165,7 +3204,7 @@ dependencies = [
|
||||
"num-traits",
|
||||
"paste",
|
||||
"profiling",
|
||||
"rand",
|
||||
"rand 0.9.4",
|
||||
"rand_chacha",
|
||||
"simd_helpers",
|
||||
"thiserror 2.0.18",
|
||||
|
||||
@@ -10,6 +10,9 @@ iced_moving_picture = "0"
|
||||
rust-i18n = "3"
|
||||
toml = "1"
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.10"
|
||||
|
||||
[profile.release]
|
||||
#lto = true
|
||||
codegen-units = 16
|
||||
|
||||
+36
-3
@@ -222,7 +222,10 @@ pub fn align_part(size: u64, start: u64, align: u64) -> Option<(u64, u64, u64)>
|
||||
let align_size = align_end - align_start + 1;
|
||||
|
||||
if align_size < align {
|
||||
println!("if align_size < align !!!!!!! align_size: {} align: {}",align_size,align);
|
||||
println!(
|
||||
"if align_size < align !!!!!!! align_size: {} align: {}",
|
||||
align_size, align
|
||||
);
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -274,10 +277,12 @@ impl PartLayout {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use rand::RngExt;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_align_part_fn() {
|
||||
fn test_align_part_fn_joe() {
|
||||
//START (S),SIZE (Z),ALIGNMENT (A),ALIGNED_START (Salign),ALIGNED_END (Ealign),Effektive Größe (Zalign)
|
||||
let joes_test_data: Vec<(u64, u64, u64, u64, u64, u64)> = vec![
|
||||
(0, 10000, 4096, 0, 8191, 8192),
|
||||
@@ -287,11 +292,39 @@ mod tests {
|
||||
(2097152, 1050000, 1048576, 2097152, 3145727, 1048576),
|
||||
];
|
||||
for test_data in joes_test_data {
|
||||
let res = align_part(test_data.1,test_data.0,test_data.2).unwrap();
|
||||
let res = align_part(test_data.1, test_data.0, test_data.2).unwrap();
|
||||
let test_res = (test_data.5, test_data.3, test_data.4);
|
||||
assert_eq!(res, test_res);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_align_part_fn_rand() {
|
||||
for ((size, start, align), test_res) in rand::rng()
|
||||
.random_iter::<u32>()
|
||||
.filter(|n| *n > 0)
|
||||
.take(100)
|
||||
.flat_map(|align|
|
||||
(0..u64::MAX)
|
||||
.step_by(align as usize)
|
||||
.take(1000)
|
||||
.map(move |start_align| {
|
||||
let mut rng = rand::rng();
|
||||
let size_align = align as u64 * rng.random_range(1..u16::MAX) as u64;
|
||||
let end_align = start_align + size_align - 1;
|
||||
let start = start_align.saturating_sub(rng.random_range(0..align) as u64);
|
||||
let size = size_align.saturating_add(rng.random_range(0..align) as u64);
|
||||
(
|
||||
(size, start, align as u64),
|
||||
(size_align, start_align.clone(), end_align),
|
||||
)
|
||||
})
|
||||
)
|
||||
{
|
||||
let res = align_part(size, start, align).unwrap();
|
||||
assert_eq!(res, test_res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fn add_part(part_list: Vec<PartInfo>, rem_size: u64, part_t: PartType, )
|
||||
|
||||
Reference in New Issue
Block a user