Skip to content
Browse files

randomized number of statements

  • Loading branch information...
1 parent 5bedb20 commit efc7941159dcd78ea9648345585a9cf8b21dc9c2 @apartridge apartridge committed Nov 29, 2011
Showing with 13 additions and 3 deletions.
  1. +5 −2 src/generate/Program.cpp
  2. +8 −1 src/generate/Statement/VariableStatement.cpp
View
7 src/generate/Program.cpp
@@ -3,21 +3,24 @@
#include "Variable.h"
#include "VariableStatement.h"
#include "FunctionDeclaration.h"
+#include "Random.h"
#include <vector>
#include <string>
Program::Program() : Scope(NULL) {
// Global variables where side effects can be observed
- for (int i = 0; i < 10; i++) {
+ int globvars = Random::randint(1,10) + Random::randint(0,10);
+ for (int i = 0; i < globvars; i++) {
this->source_elements.push_back( new VariableStatement(this, 0));
}
// Guarantee at least one "class"
this->source_elements.push_back( new FunctionDeclaration(this, 0) );
// Generate some number of SourceElements
- for (int i = 0; i < 4; ++i) {
+ int sourceelements = Random::randint(1,5);
+ for (int i = 0; i < sourceelements; ++i) {
this->source_elements.push_back( SourceElement::createRandom(this, 0) );
}
}
View
9 src/generate/Statement/VariableStatement.cpp
@@ -18,7 +18,14 @@ VariableStatement::VariableStatement(Scope* s, int depth) : Statement(s, depth)
this->var = scope->generateNumberVariable(false);
break;
}
- line_end = ";";
+ RandomDiscreteDistribution use_semicolon = RandomDiscreteDistribution(2, 2, 1);
+ if(use_semicolon.getChosenIndex() == 0){
+ line_end = ";";
+ }
+ else
+ {
+ line_end = "";
+ }
}
void VariableStatement::print(std::ostream& out) {

0 comments on commit efc7941

Please sign in to comment.
Something went wrong with that request. Please try again.