Commit c9663b9e authored by John Zacarias Jekel's avatar John Zacarias Jekel
Browse files

Add a reminder for myself to not forget to add integration tests

parent a425325f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
 
+6 −13
Original line number Diff line number Diff line
@@ -135,26 +135,19 @@ fn benchmark_file(args: &Vec<String>) {

    let file_contents = std::fs::read_to_string(input_file).unwrap();

    let mut total_duration_utf8 = std::time::Duration::new(0, 0);
    let mut total_duration_regular = std::time::Duration::new(0, 0);

    for _ in 0..iterations {
        let start_time = std::time::Instant::now();
        let translated_file_contents = translate(&file_contents);
        let time_to_translate = start_time.elapsed();

        total_duration_utf8 += time_to_translate;
        total_duration_regular += time_to_translate;
        std::fs::write("/dev/null", &translated_file_contents).unwrap();//TODO avoid needing unix
    }
    eprintln!("Sucessful: UTF-8 translation took {}ns to translate on average over {} runs.", total_duration_utf8.as_nanos() / iterations, iterations);
    eprintln!("Sucessful: Regular translation took {}ns to translate on average over {} runs.", total_duration_regular.as_nanos() / iterations, iterations);

    for character in file_contents.chars() {
        if !character.is_ascii() {
            eprintln!("Not performing ASCII translation benchmarks as the file's contents are not entirely ASCII.");
            return;
        }
    }

    let mut total_duration_ascii = std::time::Duration::new(0, 0);
    let mut total_duration_byte_string = std::time::Duration::new(0, 0);

    let mut translated_file_contents = Vec::<u8>::new();//TODO set a sane initial size
    for _ in 0..iterations {
@@ -162,10 +155,10 @@ fn benchmark_file(args: &Vec<String>) {
        translated_file_contents.truncate(0);
        byte_string::translate(file_contents.as_bytes(), &mut translated_file_contents);
        let time_to_translate = start_time.elapsed();
        total_duration_ascii += time_to_translate;
        total_duration_byte_string += time_to_translate;
        std::fs::write("/dev/null", &translated_file_contents).unwrap();//TODO avoid needing unix
    }
    eprintln!("Sucessful: ASCII translation took {}ns to translate on average over {} runs.", total_duration_ascii.as_nanos() / iterations, iterations);
    eprintln!("Sucessful: Byte-string translation with reused allocations took {}ns to translate on average over {} runs.", total_duration_byte_string.as_nanos() / iterations, iterations);
}

fn translate_args(args: &Vec<String>) {
+0 −2
Original line number Diff line number Diff line
@@ -70,7 +70,6 @@ pub fn translate_with_style(english: &[u8], suffix_lower: &[u8], special_case_su
    translate_with_style_lower_and_upper_suffixes(english, suffix_lower, special_case_suffix_lower, &suffix_upper, &special_case_suffix_upper, pig_latin_string);
}

//TODO tests for this function
pub(crate) fn translate_with_style_lower_and_upper_suffixes (
    english: &[u8],
    suffix_lower: &[u8], special_case_suffix_lower: &[u8], suffix_upper: &[u8], special_case_suffix_upper: &[u8],
@@ -267,7 +266,6 @@ mod tests {
    //NOTE: We don't test byte_string::translate_with_style and other similar functions in here directly since we test them through string.rs

    //TODO test uppercase words

    #[test]
    fn test_translate_word_with_style() {
        let suffix_special_case_suffix_pairs = [