From a3fdd7f20eade9a62f0b4bf4daaf15cd3ccee940 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 10 Dec 2015 16:47:55 -0800 Subject: [PATCH] Improve random word generation in random corpus specs --- spec/runtime/language_specs.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/spec/runtime/language_specs.cc b/spec/runtime/language_specs.cc index 169f7c19..d8d7f256 100644 --- a/spec/runtime/language_specs.cc +++ b/spec/runtime/language_specs.cc @@ -91,13 +91,16 @@ string random_char(string characters) { string random_words(size_t count) { string result; + bool just_inserted_word = false; for (size_t i = 0; i < count; i++) { - if (!result.empty() && rand() % 2 > 0) - result += " "; - if (rand() % 10 < 5) + if (rand() % 10 < 6) { result += random_char("!(){}[]<>+-="); - else + } else { + if (just_inserted_word) + result += " "; result += random_string('a', 'z'); + just_inserted_word = true; + } } return result; } @@ -148,7 +151,7 @@ describe("Languages", [&]() { string inserted_text = random_words(rand() % 4 + 1); if (insertions.insert({edit_position, inserted_text}).second) { - string description = "'" + inserted_text + "' at " + to_string(edit_position); + string description = "\"" + inserted_text + "\" at " + to_string(edit_position); it_handles_edit_sequence("repairing an insertion of " + description, [&]() { ts_document_edit(doc, input->replace(edit_position, 0, inserted_text));