Skip to content

Commit 6cc5e53

Browse files
Merge pull request #260 from marvin-hansen/main
Re-orgnized test files
2 parents e7d1b9c + 3c5f194 commit 6cc5e53

File tree

15 files changed

+1768
-1669
lines changed

15 files changed

+1768
-1669
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: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* SPDX-License-Identifier: MIT
33
* Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
44
*/
5-
65
use crate::*;
6+
use std::hash::Hash;
77

88
// A mock data structure used across multiple tests.
99
#[derive(Debug, Clone, Eq, Hash, Copy, PartialEq, Default)]
@@ -68,3 +68,150 @@ pub type TestModel = Model<
6868
FloatType,
6969
FloatType,
7070
>;
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+
}

deep_causality/tests/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ rust_test_suite(
312312
rust_test_suite(
313313
name = "traits_tests",
314314
srcs = glob([
315-
"traits/generatable/*_tests.rs",
315+
"traits/generatable/generative_processor/*_tests.rs",
316316
]),
317317
tags = [
318318
"traits_tests",

0 commit comments

Comments
 (0)