quicktheories / QuickTheories

Property based testing for Java 8
Apache License 2.0
505 stars 51 forks source link

Creating numeric strings of specified lengths #69

Open ZmurLV opened 4 years ago

ZmurLV commented 4 years ago

Needed to create strings like this: "ISO0260000590230322000012A800001" that is a constant "ISO" + 22 numeric characters + A + 6 numeric characters. Could not generate a numeric string of fixed length, because strings().numeric() doesn't seem to allow to set the length of a result.

hyperpape commented 4 years ago

It's possible to achieve this result.

new StringsDSL().betweenCodePoints((int) '0', (int)'9').ofLengthBetween(22, 22); 

or

new StringsDSL().betweenCodePoints(48, 57).ofLengthBetween(22, 22); 

depending on personal preferences.

A dedicated API for this might also be nice.