Comments (13)
Errm, try: quickcheck(prop as fn(Vec<i32>) -> bool)
.
from quickcheck.
As far as I can tell, this is just never going to work. See rust-lang/rust#25041 for more discussion, where it seems to me the issue has been interpreted as "confusing" rather than a bug to fix. Some reasons are given but I don't quite understand them. I don't see any movement to resolve it, so after half a decade, I'm giving up and calling this wontfix
.
I would very much love to make quickcheck work with closures though. So if there are any fresh ideas, we can re-open is this issue.
from quickcheck.
That does work, thank you. I'm a bit baffled that it's required since it's trivially inferrable type information...
from quickcheck.
I'm pretty sure it's a known bug, but I can't find it in the Rust issue tracker at the moment. I think this happened when Rust moved everything over to unboxed closures. Unfortunately, I can't remember why this happens.
from quickcheck.
The PR that introduced this, I think, is rust-lang/rust#19891. I too remember seeing something that indicated this coercion is supposed to exist at some point but can't find it either.
from quickcheck.
Afaik, functions now implement the Fn(…) -> …
traits. So I think it would actually be cleaner if quickcheck would impl<F: Fn(…) -> …> Testable for F
instead of coercing to a trait object.
Edit: that does not work together with the coherence rules, does it?
from quickcheck.
I've tried really hard to work around this (by pursuing impls with Fn
instead of fn
) and I haven't been able to come up with a solution yet.
from quickcheck.
I think I'm currently blocked on this by this bug: rust-lang/rust#25041 (Well, I think it's a bug. It sure feels like it.)
from quickcheck.
cc me
from quickcheck.
Just to clarify: we are currently blocked on being able to quickcheck an arbitrary closure? (Important to be able to nest to stage generation of values, as in Haskell QuickCheck and Scala ScalaCheck.)
from quickcheck.
@FranklinChen Yup. I might be missing another solution to the problem, but the straight-forward path is to implement Testable
on closure types, and the bug in rust-lang/rust#25041 seems to be preventing that.
from quickcheck.
While this still doesn't seem possible at the type level yet, you can reduce a bit of boilerplate by using _
when casting to the function pointer:
fn prop(xs: Vec<i32>) -> bool {
xs == reverse(&reverse(&xs[..])[..])
}
quickcheck(prop as fn(_) -> _);
This is a bit nicer as you only have to duplicate the number of arguments, not the types.
from quickcheck.
@shepmaster Ah, thanks for that tip. Could a macro automate that?
from quickcheck.
Related Issues (20)
- Cannot use Rng methods on `Gen` when implementing `Arbitrary` HOT 5
- Identity checking HOT 3
- Stack overflow in quickcheck case shrinking HOT 3
- example case sort TEST FAILED HOT 1
- QuickChecking Const Generic Code HOT 5
- Implement Arbitrary for AsMut<[T: Arbitrary]> HOT 2
- Infinite Repetition/Never Ending Test with `f32` and `f64`. HOT 17
- Q: Idiomatic way to specify the length of an arbitrary vector HOT 7
- <newbie> How to generate a number within a range HOT 2
- Negating an integer leads to stack overflow HOT 2
- upgrade notes would be nice. HOT 1
- debug_reprs taking up 41% of test runtime HOT 2
- warning: panic message is not a string literal HOT 1
- Rng Size for Vec Arbitrary cannot be 0
- Impl Clone for Gen
- Implement something like choose_weighted for `Gen`
- Is this still maintained? HOT 1
- Is quickcheck still maintained? HOT 1
- How to combine quickcheck 1+ with fake? HOT 3
- Durations's Arbitrary instance is dependant on Gen's size HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quickcheck.