BurntSushi / quickcheck

Automated property based testing for Rust (with shrinking).
The Unlicense
2.32k stars 144 forks source link

QuickChecking Const Generic Code #290

Closed markcatley closed 3 years ago

markcatley commented 3 years ago

Any thoughts on using QuickCheck on const generic code? I imagine it would be a little difficult given that you'd have to run some of the testing at compile time. I.e. if you have:

pub struct Matrix<T, const ROWS: usize, const COLS: usize> {
    data: Vec<T>,
}

quickcheck! {
  fn qcheck_test<const ROWS: usize, const COLS: usize>(t: Matrix<i32, ROWS, COLS>) -> bool {
    ...
  }
}

I am guessing you'd have to generate a bunch of different versions of qcheck_test at compile time in the quickcheck! macro to make this work. I don't know if that is even possible. If you think it might work I'm happy to try to write some code.

BurntSushi commented 3 years ago

I don't understand the question. Please elaborate. Please include examples.

markcatley commented 3 years ago

Sorry about that. I'm not entirely sure how to show what I am asking. Can you see if the changes I've made to the initial comment makes sense to you? If not, close this and I guess I'll have to write some code that modifies the quickcheck macros and see if I can explain what I mean better.

BurntSushi commented 3 years ago

Yeah I guess I'm still not quite sure what you're asking. I don't see why const generic code can't be quickchecked just like anything else.

If you're talking about varying the const generic parameters themselves, then yeah, quickcheck can't and won't do that.

markcatley commented 3 years ago

Yes, I was thinking about varying the const generic parameters. Sorry that I wasn't clearer upfront - I wasn't sure about the language to use.

I don't understand why it can't be done - however, I can see why the tradeoffs might be not worth it. I might give the code a go and post a PR for my understanding. Feel free to close it without looking at it too hard if that's what you'd like to do.

Sorry for unnessisarily taking up your time and thank you for your working in the rust ecosystem.

BurntSushi commented 3 years ago

I'd love to see what you come up with personally. I wonder if we might still be missing each other here. The code will help clarify I think.