|
2 | 2 | * SPDX-License-Identifier: MIT |
3 | 3 | * Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved. |
4 | 4 | */ |
5 | | - |
6 | 5 | use crate::*; |
| 6 | +use std::hash::Hash; |
7 | 7 |
|
8 | 8 | // A mock data structure used across multiple tests. |
9 | 9 | #[derive(Debug, Clone, Eq, Hash, Copy, PartialEq, Default)] |
@@ -68,3 +68,150 @@ pub type TestModel = Model< |
68 | 68 | FloatType, |
69 | 69 | FloatType, |
70 | 70 | >; |
| 71 | + |
| 72 | +// A test processor to act as a destination for the generative output. |
| 73 | +pub struct TestProcessor<D, S, T, ST, SYM, VS, VT> |
| 74 | +where |
| 75 | + D: Default + Datable + Copy + Clone + Hash + Eq + PartialEq, |
| 76 | + S: Spatial<VS> + Clone, |
| 77 | + T: Temporal<VT> + Clone, |
| 78 | + ST: SpaceTemporal<VS, VT> + Clone, |
| 79 | + SYM: Symbolic + Clone, |
| 80 | + VS: Clone, |
| 81 | + VT: Clone, |
| 82 | +{ |
| 83 | + pub causaloid_dest: Option<Causaloid<D, S, T, ST, SYM, VS, VT>>, |
| 84 | + pub context_dest: Option<Context<D, S, T, ST, SYM, VS, VT>>, |
| 85 | +} |
| 86 | + |
| 87 | +impl<D, S, T, ST, SYM, VS, VT> Default for TestProcessor<D, S, T, ST, SYM, VS, VT> |
| 88 | +where |
| 89 | + D: Default + Datable + Copy + Clone + Hash + Eq + PartialEq, |
| 90 | + S: Spatial<VS> + Clone, |
| 91 | + T: Temporal<VT> + Clone, |
| 92 | + ST: SpaceTemporal<VS, VT> + Clone, |
| 93 | + SYM: Symbolic + Clone, |
| 94 | + VS: Clone, |
| 95 | + VT: Clone, |
| 96 | +{ |
| 97 | + fn default() -> Self { |
| 98 | + Self::new() |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +impl<D, S, T, ST, SYM, VS, VT> TestProcessor<D, S, T, ST, SYM, VS, VT> |
| 103 | +where |
| 104 | + D: Default + Datable + Copy + Clone + Hash + Eq + PartialEq, |
| 105 | + S: Spatial<VS> + Clone, |
| 106 | + T: Temporal<VT> + Clone, |
| 107 | + ST: SpaceTemporal<VS, VT> + Clone, |
| 108 | + SYM: Symbolic + Clone, |
| 109 | + VS: Clone, |
| 110 | + VT: Clone, |
| 111 | +{ |
| 112 | + pub fn new() -> Self { |
| 113 | + Self { |
| 114 | + causaloid_dest: None, |
| 115 | + context_dest: None, |
| 116 | + } |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +// Implement the processor trait so it can be used to test generators. |
| 121 | +impl<D, S, T, ST, SYM, VS, VT, G> GenerativeProcessor<D, S, T, ST, SYM, VS, VT, G> |
| 122 | + for TestProcessor<D, S, T, ST, SYM, VS, VT> |
| 123 | +where |
| 124 | + D: Default + Datable + Copy + Clone + Hash + Eq + PartialEq, |
| 125 | + S: Spatial<VS> + Clone, |
| 126 | + T: Temporal<VT> + Clone, |
| 127 | + ST: SpaceTemporal<VS, VT> + Clone, |
| 128 | + SYM: Symbolic + Clone, |
| 129 | + VS: Clone, |
| 130 | + VT: Clone, |
| 131 | + G: Generatable<D, S, T, ST, SYM, VS, VT, G>, |
| 132 | +{ |
| 133 | + fn get_causaloid_dest(&mut self) -> &mut Option<Causaloid<D, S, T, ST, SYM, VS, VT>> { |
| 134 | + &mut self.causaloid_dest |
| 135 | + } |
| 136 | + |
| 137 | + fn get_context_dest(&mut self) -> &mut Option<Context<D, S, T, ST, SYM, VS, VT>> { |
| 138 | + &mut self.context_dest |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +// Type alias for brevity in tests |
| 143 | +pub type TestProcessorAlias = TestProcessor< |
| 144 | + MockData, |
| 145 | + EuclideanSpace, |
| 146 | + EuclideanTime, |
| 147 | + EuclideanSpacetime, |
| 148 | + BaseSymbol, |
| 149 | + FloatType, |
| 150 | + FloatType, |
| 151 | +>; |
| 152 | + |
| 153 | +// Define a dummy generator for testing standalone outputs. |
| 154 | +pub struct DummyGenerator; |
| 155 | +impl |
| 156 | + Generatable< |
| 157 | + MockData, |
| 158 | + EuclideanSpace, |
| 159 | + EuclideanTime, |
| 160 | + EuclideanSpacetime, |
| 161 | + BaseSymbol, |
| 162 | + FloatType, |
| 163 | + FloatType, |
| 164 | + DummyGenerator, |
| 165 | + > for DummyGenerator |
| 166 | +{ |
| 167 | + fn generate( |
| 168 | + &mut self, |
| 169 | + _trigger: &GenerativeTrigger<MockData>, |
| 170 | + _context: &Context< |
| 171 | + MockData, |
| 172 | + EuclideanSpace, |
| 173 | + EuclideanTime, |
| 174 | + EuclideanSpacetime, |
| 175 | + BaseSymbol, |
| 176 | + FloatType, |
| 177 | + FloatType, |
| 178 | + >, |
| 179 | + ) -> Result< |
| 180 | + GenerativeOutput< |
| 181 | + MockData, |
| 182 | + EuclideanSpace, |
| 183 | + EuclideanTime, |
| 184 | + EuclideanSpacetime, |
| 185 | + BaseSymbol, |
| 186 | + FloatType, |
| 187 | + FloatType, |
| 188 | + DummyGenerator, |
| 189 | + >, |
| 190 | + ModelGenerativeError, |
| 191 | + > { |
| 192 | + Ok(GenerativeOutput::NoOp) |
| 193 | + } |
| 194 | +} |
| 195 | + |
| 196 | +#[cfg(test)] |
| 197 | +mod tests { |
| 198 | + use super::*; |
| 199 | + |
| 200 | + #[test] |
| 201 | + fn test_dummy_generator_no_op() { |
| 202 | + let mut generator = DummyGenerator; |
| 203 | + let trigger = GenerativeTrigger::ManualIntervention("test".to_string()); |
| 204 | + |
| 205 | + // Create a context of the correct type: TestContext (which is Context<MockData, ...>) |
| 206 | + let context: TestContext = TestContext::with_capacity(1, "Test Context", 10); |
| 207 | + |
| 208 | + let result = generator.generate(&trigger, &context); |
| 209 | + assert!(result.is_ok()); |
| 210 | + } |
| 211 | + |
| 212 | + #[test] |
| 213 | + fn test_processor_default() { |
| 214 | + let proc = TestProcessorAlias::default(); |
| 215 | + assert!(proc.causaloid_dest.is_none()); |
| 216 | + } |
| 217 | +} |
0 commit comments