yaml_gen now gens strings with user-specified alphabet, with Unicode support.

This commit is contained in:
Ferdinand Majerech 2014-08-02 23:29:55 +02:00
parent af4245811a
commit 760e39479e
2 changed files with 11 additions and 10 deletions

View file

@ -1,8 +1,8 @@
root-type: seq
root-type: map
documents: 2
complex-keys: false
collection-keys: false
min-nodes-per-document: 65536
min-nodes-per-document: 4096
encoding: utf-8
indent: 4
text-width: 40
@ -11,7 +11,8 @@ text-width: 40
#we end up with extremely deeply nested structures
string:
probability: 10
probability: 20
alphabet: " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_0123456789ábćčďéěǵǧȟíǐǰḱǩĺľḿńňóǒôäṕŕřśšť"
range: {min: 1, max: 40, dist: cubic}
int:
probability: 10

View file

@ -1,6 +1,7 @@
///Random YAML generator. Used to generate benchmarking inputs.
import std.algorithm;
import std.conv;
import std.datetime;
import std.math;
@ -10,9 +11,6 @@ import std.string;
import dyaml.all;
immutable alphabet = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
immutable digits = "0123456789";
Node config;
Node function(bool)[string] generators;
auto typesScalar = ["string", "int", "float", "bool", "timestamp", "binary"];
@ -65,7 +63,7 @@ real randomReal(const real min, const real max, const string distribution = "lin
return min + (max - min) * randomNormalized(distribution);
}
char randomChar(const string chars)
dchar randomChar(const dstring chars)
{
return chars[randomLong(0, chars.length - 1)];
}
@ -84,17 +82,19 @@ Node genString(bool root = false)
{
auto range = config["string"]["range"];
auto alphabet = config["string"]["alphabet"].as!dstring;
const chars = randomLong(range["min"].as!uint, range["max"].as!uint,
range["dist"].as!string);
char[] result = new char[chars];
dchar[] result = new dchar[chars];
result[0] = randomChar(alphabet);
foreach(i; 1 .. chars)
{
result[i] = randomChar(alphabet ~ digits);
result[i] = randomChar(alphabet);
}
return Node(cast(string)result);
return Node(result.to!string);
}
Node genInt(bool root = false)