inosion / dadagen

Radical Random Data Generator for Testing, Data Seeding and General Awesomeness
Apache License 2.0
8 stars 2 forks source link

dadagen-core - the DSL currently does not support altering the precision value for a float. #10

Open rbuckland opened 9 years ago

rbuckland commented 9 years ago

The DSL for a number

field { "somenumber".number between 400.00 and 880.00 } 

does not support precision . a work around can be seen below where we import the specific case class for numbers and use it directly.

The DSL should look like below if 4 decimal precision numbers were required.

field { "somenumber".number between 400.00 and 880.00 precision 4 } 

This is an example of the work around

  import org.inosion.dadagen.randomtypes._

  field { "id".rownumber }.
  field { "r_uuid".regexgen ("[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}") } .
  field { "r_rand1".number between 10000 and 90000 }.
  field { "r_str".regexgen ("[A-Z][a-zA-Z]{4}[0-9]{4}") }.
  field { "payload_id".template ("PERFT_${id}_${r_uuid}") }.
  field { "gender".gender }.
  field { "firstname".name firstname }.
  field { "surname_data".name surname }.
  field { "surname".template ("${surname_data}-${r_str}") }.
  field { "fullname".template ("${firstname} ${surname}") }.
  field { "dob".regexgen ("19[3-9][0-9]-(1[012]|0[1-9])-(0[0-9]|1[0-9]|2[0-9])") }.
  field { "email_address".template("TEST_${firstname}.${surname}@noemail.test") }.
  field { "nino".regexgen("(A|B|C|E|G|H|J|K|L|M|N|O|P|R|S|T|W|X|Y|Z){2}[0-9]{6}A") }.
  field { "street_number".number between 1 and 100 }.
  field { "street_name".template ("RS Performance Street" ) }.
  field { "town".address city }.
  field { "postcode".regexgen ("[A-Z][A-Z][0-9] [0-9][A-Z][A-Z]") }.
  // API is not supporting precision right now, but the case class does (the default _is_ 2.. see "upfront_commission") .. but if you want more precision, this is how
  field { DoubleGenerator("initial_investment",1000,80000,2) }.   
  field { "regular_investment_amount".regexgen("(50|100|150|200|250|300|350|400|450|500|550|600|650|700|750|800|850|900|950)") }.
  field { "account_number".number between 8800000 and 8899999 }.
  field { "sort_code".regexgen("(402205|110124|830608|880011|938424|938343|938130)") }.
  field { "mobile_phone_number".regexgen ("07777 [0-9]{3} [0-9]{3}") }.
  field { "retirement_age".number between 65 and 75 }.
  field { "upfront_commission".number between 100.00 and 150.00 }. // when using floats, the default is precision 2 (that is, this will create eg 110.18 ) 
  field { "commission_percentage".number between 0.01 and 0.05 }