-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Injecting static types #232
Comments
Sorry, but I'm not sure to have understood your question. Do you want to write some tests and apply them on the 2 backends? Something like the follow code? trait MyTrait {
fn get() -> u32;
}
struct A;
struct B;
impl MyTrait for A {
fn get() -> u32 {
42
}
}
impl MyTrait for B {
fn get() -> u32 {
84
}
}
use rstest::rstest;
use std::marker::PhantomData;
#[rstest]
#[case(PhantomData::<A>)]
#[case(PhantomData::<B>)]
fn test_get<T: MyTrait>(#[case] _a: PhantomData<T>) {
assert_eq!(T::get() % 2, 0);
} You can also use |
@a10736, thank you so much for you suggestion and great examples. Continuing with your example, let me clarify. Basically, I need to have |
Maybe what you need are contract tests. There's a nice way to implement contract tests that's just work for integration tests. Look at [email protected]:la10736/contract_tests_example.git and let me know if it's what you're looking for. The nice thing here if that is the tests itself that ask for the implementation to use and you import the module with the tests for each dependency that you would tests. Is a sort of Dependency Injection. |
@la10736 Thank you. I will look into this. Here is the link that takes directly to the repo: https://github.com/la10736/contract_tests_example |
I will check it out and report back. Thank you. |
I have a burn-tensor crate that defines tensor operations and traits, and I have separate backend crates (burn-ndarray and burn-tch) that implement these traits for specific tensor backends.
How can I use rstest to write tests for the tensor operations in the burn-tensor crate and inject static backend types into the tests?
A couple of constraints that I wish to keep: 1) I do not want to define macro in burn-tensor crate that will be re-imported into the backend crates (this is how it's currently done 2) I do not want burn-tensor to depend on the backend crates.
The text was updated successfully, but these errors were encountered: