wowlab_engine_ports/
request.rs1#[derive(Debug)]
4#[non_exhaustive]
5pub struct ChunkAssignment {
6 pub job_id: String,
7 pub chunk_id: String,
8 pub chunk_index: u32,
9 pub chunk_count: u32,
10 pub iterations: u32,
11 pub seed_offset: u64,
12 pub permutation_index: Option<u64>,
13 pub min_iterations: Option<u32>,
14 pub max_iterations: Option<u32>,
15 pub target_error: Option<f64>,
16}
17impl ChunkAssignment {
20 #[must_use]
21 pub fn single(label: &str, iterations: u32) -> Self {
22 Self {
23 job_id: label.to_string(),
24 chunk_id: format!("{label}-0"),
25 chunk_index: 0,
26 chunk_count: 1,
27 iterations,
28 seed_offset: 0,
29 permutation_index: None,
30 min_iterations: None,
31 max_iterations: None,
32 target_error: None,
33 }
34 }
35
36 #[must_use]
37 pub fn single_indexed(label: &str, chunk_index: u32, iterations: u32) -> Self {
38 Self {
39 job_id: label.to_string(),
40 chunk_id: format!("{label}-{chunk_index}"),
41 chunk_index,
42 chunk_count: 1,
43 iterations,
44 seed_offset: 0,
45 permutation_index: None,
46 min_iterations: None,
47 max_iterations: None,
48 target_error: None,
49 }
50 }
51}
52
53#[cfg(test)]
54mod tests {
55 use googletest::prelude::*;
56
57 use super::*;
58
59 #[gtest]
60 fn chunk_assignment_carries_permutation_index() -> Result<()> {
61 let a = ChunkAssignment {
62 job_id: "j".to_string(),
63 chunk_id: "c".to_string(),
64 chunk_index: 0,
65 chunk_count: 1,
66 iterations: 1,
67 seed_offset: 0,
68 permutation_index: Some(42),
69 min_iterations: None,
70 max_iterations: None,
71 target_error: None,
72 };
73
74 verify_that!(a.permutation_index, some(eq(42)))
75 }
76
77 #[gtest]
78 fn single_constructors_default_permutation_to_none() -> Result<()> {
79 let a = ChunkAssignment::single("job", 10);
80
81 verify_that!(a.permutation_index, none())?;
82
83 let b = ChunkAssignment::single_indexed("job", 3, 10);
84
85 verify_that!(b.permutation_index, none())
86 }
87}