Struct test_data_generation::data_sample_parser::DataSampleParser[][src]

pub struct DataSampleParser {
    pub issues: bool,
    // some fields omitted
}

Represents the Parser for sample data to be used

Fields

indicates if there were issues parsing and anlyzing the data sample

Methods

impl DataSampleParser
[src]

Constructs a new DataSampleParser

#Example

extern crate test_data_generation;

use test_data_generation::data_sample_parser::DataSampleParser;

fn main() {
    // initalize a new DataSampelParser
    let dsp = DataSampleParser::new();
}

Constructs a new DataSampleParser

Arguments

  • `path: &String - The full path name (including the file name and extension) to the configuration file.

#Example

extern crate test_data_generation;

use test_data_generation::data_sample_parser::DataSampleParser;

fn main() {
    // initalize a new DataSampelParser
    // param: the path to the configuration  file
    let dsp = DataSampleParser::new_with(&String::from("./config/tdg.yaml"));
}

Constructs a new DataSampleParser from an exported JSON file. This is used when restoring from "archive"

Arguments

  • path: &String - The full path name of the json formatted Data Sample Parser archive file.

#Example

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());
}

This function analyzes sample data that is a csv formatted file and returns a boolean if successful. NOTE: The csv properties are as follows: + headers are included as first line + double quote wrap text + double quote escapes is enabled + delimiter is a comma

Arguments

  • path: &String - The full path name of the csv formatted sample data file.

Example

extern crate test_data_generation;

use test_data_generation::data_sample_parser::DataSampleParser;

fn main() {
    // initalize a new DataSampelParser
    let mut dsp = DataSampleParser::new();

    assert_eq!(dsp.analyze_csv_file(&String::from("./tests/samples/sample-01.csv")).unwrap(),1);
}

This function analyzes sample data that is a csv formatted string and returns a boolean if successful. NOTE: The csv properties are as follows: + headers are included as first line + double quote wrap text + double quote escapes is enabled + delimiter is a comma

Arguments

  • data: &String - The textual content of a csv formatted sample data file.

Example

extern crate test_data_generation;

use test_data_generation::data_sample_parser::DataSampleParser;

fn main() {
    // initalize a new DataSampelParser
    let mut dsp = DataSampleParser::new();
    let mut data = String::from("");
    data.push_str("\"firstname\",\"lastname\"\n");
    data.push_str("\"Aaron\",\"Aaberg\"\n");
    data.push_str("\"Aaron\",\"Aaby\"\n");
    data.push_str("\"Abbey\",\"Aadland\"\n");
    data.push_str("\"Abbie\",\"Aagaard\"\n");
    data.push_str("\"Abby\",\"Aakre\"");

    assert_eq!(dsp.analyze_csv_data(&data).unwrap(),1);
}

This function generates date as strings using the a demo profile

Example

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());
}

This function generates people's names as strings using the a demo profile

Example

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_person_name());
}

This function returns a vector of header names

Example

extern crate test_data_generation;

use test_data_generation::data_sample_parser::DataSampleParser;

fn main() {
    // initalize a new DataSampelParser
    let mut dsp = DataSampleParser::new();

    dsp.analyze_csv_file(&String::from("./tests/samples/sample-01.csv")).unwrap();
    let headers = dsp.extract_headers();

    assert_eq!(headers.len(), 2);
}

This function generates test data for the specified field name.

Arguments

  • field: String - The name of the field (e.g.: firstname) the represents the profile to use when generating the test data.

Example

extern crate test_data_generation;

use test_data_generation::data_sample_parser::DataSampleParser;

fn main() {
    // initalize a new DataSampelParser
    let mut dsp = DataSampleParser::new();

    dsp.analyze_csv_file(&String::from("./tests/samples/sample-01.csv")).unwrap();
    println!("Generated data for first name {}",dsp.generate_by_field_name("firstname".to_string()));
}

This function Vec of generates test data fields.

Example

extern crate test_data_generation;

use test_data_generation::data_sample_parser::DataSampleParser;

fn main() {
    // initalize a new DataSampelParser
    let mut dsp = DataSampleParser::new();

    dsp.analyze_csv_file(&String::from("./tests/samples/sample-01.csv")).unwrap();
    println!("Generated data record: {:?}",dsp.generate_record());
}

This function creates a csv file of generated test data. Prior to calling this funciton, you need to call the analyze_csv_file() function. NOTE: The csv properties are as follows: + headers are included as first line + double quotes wrap text + double quote escapes is enabled + delimiter is a comma

Arguments

  • row_count: u32 - The number of rows to generate.
  • path: &String - The full path name where to save the csv file.

Example

extern crate test_data_generation;

use test_data_generation::data_sample_parser::DataSampleParser;

fn main() {
    // initalize a new DataSampelParser
    let mut dsp = DataSampleParser::new();

    dsp.analyze_csv_file(&String::from("./tests/samples/sample-01.csv")).unwrap();
    dsp.generate_csv(100, &String::from("./tests/samples/generated-01.csv")).unwrap();
}

This function calculates the levenshtein distance between 2 strings. See: https://crates.io/crates/levenshtein

Arguments

  • control: &String - The string to compare against. This would be the real data from the data sample.
  • experiment: &String - The string to compare. This would be the generated data for which you want to find the distance.

#Example

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.levenshtein_distance(&"kitten".to_string(), &"sitting".to_string()), 3 as usize);
}

This function calculates the percent difference between 2 strings.

Arguments

  • control: &String - The string to compare against. This would be the real data from the data sample.
  • experiment: &String - The string to compare. This would be the generated data for which you want to find the percent difference.

#Example

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.realistic_test(&"kitten".to_string(), &"sitting".to_string()), 76.92307692307692 as f64);
}

This function returns a boolean that indicates if the data sample parsing had issues

Example

extern crate test_data_generation;

use test_data_generation::data_sample_parser::DataSampleParser;

fn main() {
    // initalize a new DataSampelParser
    // param: the path to the configuration file is wrong
    let dsp = DataSampleParser::new_with(&String::from("./target/debug/config/tdg.yaml"));

    // generate some test data using the demo functions
    assert_eq!(dsp.running_with_issues(), &false);
}

This function saves (exports) the DataSampleParser to a JSON file. This is useful when you wish to reuse the algorithm to generate more test data later.

Arguments

  • field: &String - The full path of the export file , excluding the file extension, (e.g.: "./test/data/custom-names").

#Errors If this function encounters any form of I/O or other error, an error variant will be returned. Otherwise, the function returns Ok(true).

#Example

extern crate test_data_generation;

use test_data_generation::data_sample_parser::DataSampleParser;

fn main() {
    // analyze the dataset
    let mut dsp =  DataSampleParser::new();
    dsp.analyze_csv_file(&String::from("./tests/samples/sample-00.csv")).unwrap();

    assert_eq!(dsp.save(&String::from("./tests/samples/sample-00-dsp")).unwrap(), true);
}

Trait Implementations

impl Debug for DataSampleParser
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations