Back to Comfy Small Projects

Last week, I contributed to Mattermost’s web app, this week, I looked through the list of projects my peers contributed to and there was one that caught my eye. Roger contributed to a Rust project which was a “CLI tool to calculate beer brewing values for different things” named rustybeer. I like Rust and beer, and the project had many issues for the taking so I thought it was perfect.

I chose to add the subcommand for the yeast viability issue. Yeast as it ages, goes bad after a period, the command should estimate the viability, which is the difference of live cells and initial cell count of the yeast. This allows the brewer to pitch in the correct amount of yeast based off their final cell count.

First, I looked at the website used for calculating yeast viability but saw it was a linear equation which didn’t sit well with me so I looked for other calculators and I found yeastcalc which many other sites used to replicate so I charted both expressions into desmos and replied to the issue detailing what work I did and asking which expression they’d like me to implement for yeast viability calculations.

The red line is the linear expression found in the site mentioned in the issue, blue line is yeastcalc’s expression.

After figuring out which expression should be used, I updated my branch to use it for calculations and made a pull request. I made sure to use all the rust cargo utilities to ensure I had no checkstyle violations and that my formatting was correct. After all the checks passed, I made the pull request.

The maintainer of the project reviewed the code and was happy with the changes made and merged the PR, but they left a message saying tests we’re missing and advised I could add them in another PR, so that’s exactly what I did. I rebased my fork onto the new master and updated my yeast-viability branch to be even with the master upstream branch and added my tests.


#[test]
fn yeast_variability() {
    use rustybeer::calculators::yeast_viability::{calculate_cc, calculate_yv};

    assert_approx!(970.0, calculate_cc(1000.0, 0.0));

    assert_approx!(115.048_26, calculate_cc(123.45, 5.0));

    assert_approx!(0.0, calculate_cc(9001.0, 3650.0));

    assert_approx!(97.0, calculate_yv(0.0));

    assert_approx!(65.004_616, calculate_yv(50.0));

    assert_approx!(0.0, calculate_yv(3650.0));
}

Rust has built in testing which is used with the #[test] annotation which was a please working with and it took no time to write my test cases and running them with cargo test.

results of the calculator tests

The tests passed with the calculations I made, so I pushed the tests to my repo and made another pull request.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with WordPress.com
Get started
%d bloggers like this: