You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by dj...@apache.org on 2016/12/27 09:54:29 UTC
[text] Complete test coverage for RandomStringGenerator
Repository: commons-text
Updated Branches:
refs/heads/master 1b3e44809 -> 0b1ca53b3
Complete test coverage for RandomStringGenerator
Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/0b1ca53b
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/0b1ca53b
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/0b1ca53b
Branch: refs/heads/master
Commit: 0b1ca53b3e00e74364849a14372e4b3f57c2d3a0
Parents: 1b3e448
Author: duncan <du...@wortharead.com>
Authored: Tue Dec 27 09:54:19 2016 +0000
Committer: duncan <du...@wortharead.com>
Committed: Tue Dec 27 09:54:19 2016 +0000
----------------------------------------------------------------------
.../org/apache/commons/text/RandomStringGeneratorTest.java | 6 ++++++
1 file changed, 6 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-text/blob/0b1ca53b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
index 2ff7a67..36ce5e0 100644
--- a/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
+++ b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
@@ -203,4 +203,10 @@ public class RandomStringGeneratorTest {
assertTrue(c == 'b');
}
}
+
+ @Test
+ public void testZeroLength() throws Exception {
+ RandomStringGenerator generator = new RandomStringGenerator.Builder().build();
+ assertEquals("", generator.generate(0));
+ }
}
Re: [text] Complete test coverage for RandomStringGenerator
Posted by Pascal Schumacher <pa...@gmx.net>.
Am 27.12.2016 um 11:51 schrieb Duncan Jones:
>
>> On 27 Dec 2016, at 10:29, Gilles <gi...@harfang.homelinux.org> wrote:
>>
>> Hi.
>>
>> On Tue, 27 Dec 2016 09:54:29 +0000 (UTC), djones@apache.org wrote:
>> A string of length zero hardly qualifies as random.
>> Shouldn't "generate(0)" rather raise an exception?
>> [I know that "nextInt(1)" is also not random, but what applies to a
>> general-purpose low-level utility might not be the best option for
>> applications that would use TEXT.]
> I was following the Robustness principle. Asking for a zero-length string is odd, but as there was a way to interpret that request without throwing an exception, I did so.
+1 When generating strings with a random length (e.g between 0 and 10)
asking for a zero length string is not so odd.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [text] Complete test coverage for RandomStringGenerator
Posted by Rob Tompkins <ch...@gmail.com>.
> On Dec 27, 2016, at 5:51 AM, Duncan Jones <du...@wortharead.com> wrote:
>
>
>> On 27 Dec 2016, at 10:29, Gilles <gi...@harfang.homelinux.org> wrote:
>>
>> Hi.
>>
>>> On Tue, 27 Dec 2016 09:54:29 +0000 (UTC), djones@apache.org wrote:
>>> Repository: commons-text
>>> Updated Branches:
>>> refs/heads/master 1b3e44809 -> 0b1ca53b3
>>>
>>>
>>> Complete test coverage for RandomStringGenerator
>>>
>>> Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
>>> Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/0b1ca53b
>>> Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/0b1ca53b
>>> Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/0b1ca53b
>>>
>>> Branch: refs/heads/master
>>> Commit: 0b1ca53b3e00e74364849a14372e4b3f57c2d3a0
>>> Parents: 1b3e448
>>> Author: duncan <du...@wortharead.com>
>>> Authored: Tue Dec 27 09:54:19 2016 +0000
>>> Committer: duncan <du...@wortharead.com>
>>> Committed: Tue Dec 27 09:54:19 2016 +0000
>>>
>>> ----------------------------------------------------------------------
>>> .../org/apache/commons/text/RandomStringGeneratorTest.java | 6 ++++++
>>> 1 file changed, 6 insertions(+)
>>> ----------------------------------------------------------------------
>>>
>>>
>>> http://git-wip-us.apache.org/repos/asf/commons-text/blob/0b1ca53b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
>>> ----------------------------------------------------------------------
>>> diff --git
>>> a/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
>>> b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
>>> index 2ff7a67..36ce5e0 100644
>>> --- a/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
>>> +++ b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
>>> @@ -203,4 +203,10 @@ public class RandomStringGeneratorTest {
>>> assertTrue(c == 'b');
>>> }
>>> }
>>> +
>>> + @Test
>>> + public void testZeroLength() throws Exception {
>>> + RandomStringGenerator generator = new
>>> RandomStringGenerator.Builder().build();
>>> + assertEquals("", generator.generate(0));
>>> + }
>>> }
>>
>> A string of length zero hardly qualifies as random.
>> Shouldn't "generate(0)" rather raise an exception?
>> [I know that "nextInt(1)" is also not random, but what applies to a
>> general-purpose low-level utility might not be the best option for
>> applications that would use TEXT.]
>
> I was following the Robustness principle. Asking for a zero-length string is odd, but as there was a way to interpret that request without throwing an exception, I did so.
>
This makes sense to me. It feels like every random string generator, regardless of the underlying distribution, on the request for the string of length 0 should return a string from the Kleene closure over the null set.
-Rob
> Duncan
>
>>
>> Regards,
>> Gilles
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [text] Complete test coverage for RandomStringGenerator
Posted by Duncan Jones <du...@wortharead.com>.
> On 27 Dec 2016, at 10:29, Gilles <gi...@harfang.homelinux.org> wrote:
>
> Hi.
>
> On Tue, 27 Dec 2016 09:54:29 +0000 (UTC), djones@apache.org wrote:
>> Repository: commons-text
>> Updated Branches:
>> refs/heads/master 1b3e44809 -> 0b1ca53b3
>>
>>
>> Complete test coverage for RandomStringGenerator
>>
>> Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/0b1ca53b
>> Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/0b1ca53b
>> Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/0b1ca53b
>>
>> Branch: refs/heads/master
>> Commit: 0b1ca53b3e00e74364849a14372e4b3f57c2d3a0
>> Parents: 1b3e448
>> Author: duncan <du...@wortharead.com>
>> Authored: Tue Dec 27 09:54:19 2016 +0000
>> Committer: duncan <du...@wortharead.com>
>> Committed: Tue Dec 27 09:54:19 2016 +0000
>>
>> ----------------------------------------------------------------------
>> .../org/apache/commons/text/RandomStringGeneratorTest.java | 6 ++++++
>> 1 file changed, 6 insertions(+)
>> ----------------------------------------------------------------------
>>
>>
>> http://git-wip-us.apache.org/repos/asf/commons-text/blob/0b1ca53b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
>> ----------------------------------------------------------------------
>> diff --git
>> a/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
>> b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
>> index 2ff7a67..36ce5e0 100644
>> --- a/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
>> +++ b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
>> @@ -203,4 +203,10 @@ public class RandomStringGeneratorTest {
>> assertTrue(c == 'b');
>> }
>> }
>> +
>> + @Test
>> + public void testZeroLength() throws Exception {
>> + RandomStringGenerator generator = new
>> RandomStringGenerator.Builder().build();
>> + assertEquals("", generator.generate(0));
>> + }
>> }
>
> A string of length zero hardly qualifies as random.
> Shouldn't "generate(0)" rather raise an exception?
> [I know that "nextInt(1)" is also not random, but what applies to a
> general-purpose low-level utility might not be the best option for
> applications that would use TEXT.]
I was following the Robustness principle. Asking for a zero-length string is odd, but as there was a way to interpret that request without throwing an exception, I did so.
Duncan
>
> Regards,
> Gilles
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [text] Complete test coverage for RandomStringGenerator
Posted by Gilles <gi...@harfang.homelinux.org>.
Hi.
On Tue, 27 Dec 2016 09:54:29 +0000 (UTC), djones@apache.org wrote:
> Repository: commons-text
> Updated Branches:
> refs/heads/master 1b3e44809 -> 0b1ca53b3
>
>
> Complete test coverage for RandomStringGenerator
>
> Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
> Commit:
> http://git-wip-us.apache.org/repos/asf/commons-text/commit/0b1ca53b
> Tree:
> http://git-wip-us.apache.org/repos/asf/commons-text/tree/0b1ca53b
> Diff:
> http://git-wip-us.apache.org/repos/asf/commons-text/diff/0b1ca53b
>
> Branch: refs/heads/master
> Commit: 0b1ca53b3e00e74364849a14372e4b3f57c2d3a0
> Parents: 1b3e448
> Author: duncan <du...@wortharead.com>
> Authored: Tue Dec 27 09:54:19 2016 +0000
> Committer: duncan <du...@wortharead.com>
> Committed: Tue Dec 27 09:54:19 2016 +0000
>
>
> ----------------------------------------------------------------------
> .../org/apache/commons/text/RandomStringGeneratorTest.java | 6
> ++++++
> 1 file changed, 6 insertions(+)
>
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/commons-text/blob/0b1ca53b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
>
> ----------------------------------------------------------------------
> diff --git
>
> a/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
>
> b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
> index 2ff7a67..36ce5e0 100644
> ---
> a/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
> +++
> b/src/test/java/org/apache/commons/text/RandomStringGeneratorTest.java
> @@ -203,4 +203,10 @@ public class RandomStringGeneratorTest {
> assertTrue(c == 'b');
> }
> }
> +
> + @Test
> + public void testZeroLength() throws Exception {
> + RandomStringGenerator generator = new
> RandomStringGenerator.Builder().build();
> + assertEquals("", generator.generate(0));
> + }
> }
A string of length zero hardly qualifies as random.
Shouldn't "generate(0)" rather raise an exception?
[I know that "nextInt(1)" is also not random, but what applies to a
general-purpose low-level utility might not be the best option for
applications that would use TEXT.]
Regards,
Gilles
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org