You are browsing as a guest. Sign up (or log in) to start making projects!

2h 3m 55s logged

Testing, Testing, 1 2 3

Here’s what I’ve been working on to try to get a good, stable release.

I Need an Extension

I discovered that when doing the normalising add, the one that’s like problem-1.txt, problem-11.rs (-n 1) -> problem-01.txt, problem-11.rs (keeps the same total length of the numeric portion), it actually counts the extension characters, so the result would actually be problem-01.txt, problem-011.rs because the extensions are different lengths. Previously, the find_target() function was like this:

pub fn find_target(filenames: &Vec<String>, count: usize) -> usize {
    let mut minimum = usize::MAX;
    for file in filenames {
        let (dot_index, cond) = check_file(file);
        if cond {
            continue;
        }
        let split_index = find_split_index(file, dot_index);
        minimum = minimum.min(file[split_index..].len());
    }
    minimum + count
}

Now, it’s

pub fn find_target(filenames: &Vec<String>, count: usize) -> usize {
    let mut minimum = usize::MAX;
    let mut is_numeric: bool = false;
    for file in filenames {
        let (dot_index, cond) = check_file(file);
        if cond {
            continue;
        }
        let split_index = find_split_index(file, dot_index);
        minimum = minimum.min(file[split_index..dot_index].len());
        is_numeric = true;
    }
    if is_numeric { minimum + count } else { 0 }
}

Now the target isn’t the shortest number of characters in the numeric portion plus the extension, it’s just the extension.

The is_numeric variable is just there so that it doesn’t try to add count to usize::MAX, getting an overflow if there are no files with numeric suffixes.

sleep(); sleep(); sleep(); allTestsPass();

The last step before 1.0.0 is UNIT TESTS!!!!!!
The easiest unit tests to write are ones for my functions in helpers.rs, including find_target(), check_file(), find_split_index(), and get_filenames(). I wrote 15 unit tests for the first three, and I might write some for get_filenames after I write some for change_leading_zeros(). While writing the unit tests, I stumbled upon the edge case for find_target if there are no applicable files, which is why I added the is_numeric above.

The next step is writing the aforementioned unit tests for change_leading_zeros().

0
111

Comments 1

@max_silly

Can’t believe I forgot to put this in the devlog