-
Notifications
You must be signed in to change notification settings - Fork 408
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
Add Generators For Hex Char And String Values #470
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -694,7 +694,7 @@ object Gen extends GenArities with GenVersionSpecific { | |
choose(1, gs.length+2).flatMap(pick(_, g1, g2, gs: _*)) | ||
|
||
/** A generator that randomly picks a given number of elements from a list | ||
* | ||
* | ||
* The elements are not guaranteed to be permuted in random order. | ||
*/ | ||
def pick[T](n: Int, l: Iterable[T]): Gen[collection.Seq[T]] = { | ||
|
@@ -722,7 +722,7 @@ object Gen extends GenArities with GenVersionSpecific { | |
} | ||
|
||
/** A generator that randomly picks a given number of elements from a list | ||
* | ||
* | ||
* The elements are not guaranteed to be permuted in random order. | ||
*/ | ||
def pick[T](n: Int, g1: Gen[T], g2: Gen[T], gn: Gen[T]*): Gen[Seq[T]] = { | ||
|
@@ -766,6 +766,15 @@ object Gen extends GenArities with GenVersionSpecific { | |
/** Generates a ASCII printable character */ | ||
def asciiPrintableChar: Gen[Char] = choose(32.toChar, 126.toChar) | ||
|
||
/** Generates a character that can represent a valid hexadecimal digit. This | ||
* includes both upper and lower case values. | ||
*/ | ||
def hexChar: Gen[Char] = | ||
Gen.oneOf( | ||
Gen.oneOf("0123456789abcdef".toSeq), | ||
Gen.oneOf("0123456789ABCDEF".toSeq) | ||
) | ||
|
||
//// String Generators //// | ||
|
||
/** Generates a string that starts with a lower-case alpha character, | ||
|
@@ -803,6 +812,11 @@ object Gen extends GenArities with GenVersionSpecific { | |
def asciiPrintableStr: Gen[String] = | ||
listOf(asciiPrintableChar).map(_.mkString) | ||
|
||
/** Generates a string that can represent a valid hexadecimal digit. This | ||
* includes both upper and lower case values. | ||
*/ | ||
def hexStr: Gen[String] = | ||
listOf(hexChar).map(_.mkString) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This produces a lengthy string by default (up to 100?). That works for your test with I guess you've copied the definition of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, I agree. I did this for consistency. That being said, I'm not too worried about this. If people want to create a |
||
//// Number Generators //// | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I was trying to be consistent with the rest of the file.