use crate::iteration::comprehension::strategies::Tuple;
pub trait KernelScope {
type Scoped;
fn scope(&self, coords: &Tuple) -> Self::Scoped;
}
#[derive(Debug, Clone, PartialEq)]
pub struct ScopedKernelInstance<S> {
pub coords: Tuple,
pub scoped: S,
}
impl<S> ScopedKernelInstance<S> {
pub fn new(coords: Tuple, scoped: S) -> Self {
Self { coords, scoped }
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::iteration::comprehension::strategies::TupleValue;
#[derive(Debug, Clone)]
struct MockKernel {
name: String,
}
#[derive(Debug, Clone, PartialEq)]
struct MockScoped {
parent_name: String,
coords: Tuple,
}
impl KernelScope for MockKernel {
type Scoped = MockScoped;
fn scope(&self, coords: &Tuple) -> MockScoped {
MockScoped {
parent_name: self.name.clone(),
coords: coords.clone(),
}
}
}
#[test]
fn mock_kernel_scope() {
let parent = MockKernel { name: "phase_x".into() };
let coords = Tuple::new().with("k", TupleValue::I64(42));
let scoped = parent.scope(&coords);
assert_eq!(scoped.parent_name, "phase_x");
assert_eq!(scoped.coords.bindings[0].0, "k");
}
#[test]
fn scoped_instance_construction() {
let coords = Tuple::new().with("limit", TupleValue::I64(100));
let instance = ScopedKernelInstance::new(coords.clone(), "scoped_value".to_string());
assert_eq!(instance.coords, coords);
assert_eq!(instance.scoped, "scoped_value");
}
}