Giter Site home page Giter Site logo

Comments (5)

BurntSushi avatar BurntSushi commented on August 11, 2024 1

Errm, right, I forgot to update this issue, but I grew tired of the ASCII-only behavior so I just changed it.

ASCII-only is still useful though, so we might want an AsciiString type or something.

from quickcheck.

BurntSushi avatar BurntSushi commented on August 11, 2024

Yeah, this definitely needs to be fixed. I think the ASCII limitation has been there and nobody has had cause enough to fix it.

There's basically two concerns here. The first is ergonomics. It's really nice when your witnesses are limited to characters that are likely to be meaningful in your terminal (i.e., printable characters). The second is that, of course, strings outside the ASCII range should be tested. When I first wrote quickcheck, I didn't know how to balance these so I just chose to address the first concern.

It seems like the principle of least surprise should apply here: String should be fuzzed with the set of Unicode scalar values and some other type (perhaps defined in quickcheck, i.e., AsciiString) should be more limited when you want a guarantee of nicer witnesses. I think it could deref to &String, which should mostly provide the ergonomics of a plain String.

from quickcheck.

shepmaster avatar shepmaster commented on August 11, 2024

It seems like shrinking could also come into play. I could conceive of a string with only ascii as being "smaller" than one with ascii + ascii punctuation. Then it could "grow" to include more common unicode, then "grow" towards uncommon. Just thinking outloud, really.

from quickcheck.

bluss avatar bluss commented on August 11, 2024

Has this changed? I think I saw wildly different results than this.

Just as a data point, this is what I ended up using for a string search testing / fuzzing:

#[derive(Clone, Debug)]
struct Text(String);

//static ALPHABET: &'static str = "ABCD";
static ALPHABET: &'static str = "\0\u{1}\u{2}\u{3}";

impl Arbitrary for Text {
    fn arbitrary<G: qc::Gen>(g: &mut G) -> Self {
        let len = u16::arbitrary(g);
        let mut s = String::with_capacity(len as usize);
        for _ in 0..len {
            let i = usize::arbitrary(g);
            let i = i % ALPHABET.len();
            s.push(ALPHABET.as_bytes()[i] as char)
        }
        Text(s)
    }
    fn shrink(&self) -> Box<Iterator<Item=Self>> {
        Box::new(self.0.shrink().map(Text))
    }
}

Since the algorithm was working on just the byte slice, I switched to an alphabet of 0-4 for even easier to read intermediate debug outputs..

from quickcheck.

shepmaster avatar shepmaster commented on August 11, 2024

@bluss it appears so! This could be considered closed via 848acee.

from quickcheck.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.