Skip to content

Commit 1be5a47

Browse files
committed
Re-organized test utils
Signed-off-by: Marvin Hansen <[email protected]>
1 parent f2aaf9a commit 1be5a47

File tree

2 files changed

+118
-1
lines changed

2 files changed

+118
-1
lines changed

deep_causality/src/utils_test/test_utils.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55

66
use crate::*;
77

8+
pub fn get_context() -> BaseContext {
9+
let id = 1;
10+
let name = "base context";
11+
let capacity = 10; // adjust as needed
12+
Context::with_capacity(id, name, capacity)
13+
}
14+
815
pub fn get_test_assumption_vec() -> Vec<Assumption> {
916
let a1 = get_test_assumption();
1017
let a2 = get_test_assumption();

deep_causality/src/utils_test/test_utils_generator.rs

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* SPDX-License-Identifier: MIT
33
* Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
44
*/
5-
5+
use std::hash::Hash;
66
use crate::*;
77

88
// A mock data structure used across multiple tests.
@@ -68,3 +68,113 @@ pub type TestModel = Model<
6868
FloatType,
6969
FloatType,
7070
>;
71+
72+
73+
// A test processor to act as a destination for the generative output.
74+
pub struct TestProcessor<D, S, T, ST, SYM, VS, VT>
75+
where
76+
D: Default + Datable + Copy + Clone + Hash + Eq + PartialEq,
77+
S: Spatial<VS> + Clone,
78+
T: Temporal<VT> + Clone,
79+
ST: SpaceTemporal<VS, VT> + Clone,
80+
SYM: Symbolic + Clone,
81+
VS: Clone,
82+
VT: Clone,
83+
{
84+
pub causaloid_dest: Option<Causaloid<D, S, T, ST, SYM, VS, VT>>,
85+
pub context_dest: Option<Context<D, S, T, ST, SYM, VS, VT>>,
86+
}
87+
88+
impl<D, S, T, ST, SYM, VS, VT> TestProcessor<D, S, T, ST, SYM, VS, VT>
89+
where
90+
D: Default + Datable + Copy + Clone + Hash + Eq + PartialEq,
91+
S: Spatial<VS> + Clone,
92+
T: Temporal<VT> + Clone,
93+
ST: SpaceTemporal<VS, VT> + Clone,
94+
SYM: Symbolic + Clone,
95+
VS: Clone,
96+
VT: Clone,
97+
{
98+
pub fn new() -> Self {
99+
Self {
100+
causaloid_dest: None,
101+
context_dest: None,
102+
}
103+
}
104+
}
105+
106+
// Implement the processor trait so it can be used to test generators.
107+
impl<D, S, T, ST, SYM, VS, VT, G> GenerativeProcessor<D, S, T, ST, SYM, VS, VT, G>
108+
for TestProcessor<D, S, T, ST, SYM, VS, VT>
109+
where
110+
D: Default + Datable + Copy + Clone + Hash + Eq + PartialEq,
111+
S: Spatial<VS> + Clone,
112+
T: Temporal<VT> + Clone,
113+
ST: SpaceTemporal<VS, VT> + Clone,
114+
SYM: Symbolic + Clone,
115+
VS: Clone,
116+
VT: Clone,
117+
G: Generatable<D, S, T, ST, SYM, VS, VT, G>,
118+
{
119+
fn get_causaloid_dest(&mut self) -> &mut Option<Causaloid<D, S, T, ST, SYM, VS, VT>> {
120+
&mut self.causaloid_dest
121+
}
122+
123+
fn get_context_dest(&mut self) -> &mut Option<Context<D, S, T, ST, SYM, VS, VT>> {
124+
&mut self.context_dest
125+
}
126+
}
127+
128+
// Type alias for brevity in tests
129+
pub type TestProcessorAlias = TestProcessor<
130+
MockData,
131+
EuclideanSpace,
132+
EuclideanTime,
133+
EuclideanSpacetime,
134+
BaseSymbol,
135+
FloatType,
136+
FloatType,
137+
>;
138+
139+
// Define a dummy generator for testing standalone outputs.
140+
pub struct DummyGenerator;
141+
impl
142+
Generatable<
143+
MockData,
144+
EuclideanSpace,
145+
EuclideanTime,
146+
EuclideanSpacetime,
147+
BaseSymbol,
148+
FloatType,
149+
FloatType,
150+
DummyGenerator,
151+
> for DummyGenerator
152+
{
153+
fn generate(
154+
&mut self,
155+
_trigger: &GenerativeTrigger<MockData>,
156+
_context: &Context<
157+
MockData,
158+
EuclideanSpace,
159+
EuclideanTime,
160+
EuclideanSpacetime,
161+
BaseSymbol,
162+
FloatType,
163+
FloatType,
164+
>,
165+
) -> Result<
166+
GenerativeOutput<
167+
MockData,
168+
EuclideanSpace,
169+
EuclideanTime,
170+
EuclideanSpacetime,
171+
BaseSymbol,
172+
FloatType,
173+
FloatType,
174+
DummyGenerator,
175+
>,
176+
ModelGenerativeError,
177+
> {
178+
Ok(GenerativeOutput::NoOp)
179+
}
180+
}

0 commit comments

Comments
 (0)