Module test_data_generation::data_sample_parser [−][src]
Expand description
The data_sample_parser
module provides functionality to read sample data, parse and analyze it,
so that test data can be generated based on profiles.
Examples
Generate some demo test data …
extern crate test_data_generation;
use test_data_generation::data_sample_parser::DataSampleParser;
fn main() {
// initalize a new DataSampelParser
let dsp = DataSampleParser::new();
// generate some test data using the demo functions
println!("generate date:{}", dsp.demo_date());
println!("generate person:{}", dsp.demo_person_name());
}
Save the algorithm …
Archive (export) the data sample parser object so that you can reuse the algorithm to generate test data at a later time. This enables you to persist the algorithm without having to store the actual data sample that was used to create the algorithm - Which is important if you used ‘real’ data in your sample data.
extern crate test_data_generation;
use test_data_generation::data_sample_parser::DataSampleParser;
fn main() {
// analyze the dataset
let mut dsp = DataSampleParser::new();
assert_eq!(dsp.save(&String::from("./tests/samples/empty-dsp")).unwrap(), true);
}
Load an algorithm …
Create a data sample parser from a previously saved (exported) archive file so you can generate test data based on the algorithm. NOTE: In this example, there was only one data point in the data sample that was analyzed (the word ‘OK’). This was intentional so the algorithm would be guaranteed to generate that same word. This was done ensure the assert_eq! returns true.
extern crate test_data_generation;
use test_data_generation::data_sample_parser::DataSampleParser;
fn main() {
let mut dsp = DataSampleParser::from_file(&String::from("./tests/samples/sample-00-dsp"));
assert_eq!(dsp.generate_record()[0], "OK".to_string());
}
You can also generate a new csv file based on the data sample provided.
extern crate test_data_generation;
use test_data_generation::data_sample_parser::DataSampleParser;
fn main() {
let mut dsp = DataSampleParser::new();
// Using the default delimiter (comma)
dsp.analyze_csv_file(&String::from("./tests/samples/sample-01.csv"), None).unwrap();
dsp.generate_csv(100, &String::from("./tests/samples/generated-01.csv"), None).unwrap();
}
Structs
Represents the Parser for sample data to be used