Commit c94ecf8c authored by Meade's avatar Meade

Added version 5.3.0. Added unit tests for maths checking.

parent 45aea8c1
[[package]]
name = "BrewStillery"
version = "5.2.0"
version = "5.3.0"
dependencies = [
"gdk 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gio 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
......
[package]
name = "BrewStillery"
version = "5.2.0"
version = "5.3.0"
authors = ["Meade <thedarkula2049@gmail.com>", "Emily <marleybrush5@gmail.com>"]
description = "BrewStillery is a brewer's, vintner's, and distiller's calculator. It has a multitude of great functions, such as calculating ABV, determining carbonation, and total sparge water needed."
# documentation to come
......
......@@ -4,6 +4,9 @@ It has a multitude of great functions, such as calculating ABV, determining carb
Written in Rust, using GTK3
## New In 5.3.0
* Added unit tests for verifying maths. To check, run `cargo test`
## New In 5.2.0
* Created traits and implementations for common functions.
* Removed the arch PKGBUILD. It's on the AUR.
......@@ -49,7 +52,6 @@ Written in Rust, using GTK3
* Add Sugars And Fruits To ABV From Grain
* Add Water Minerals Calculator
* Add Export To Gourmet Option
* Add unit tests
## Building:
......
......@@ -18,16 +18,27 @@ pub fn champagneCarbonationPrep(champagneCarbonationBuilderClone: &gtk::Builder)
} else if champagneVolume <= 0.0 {
champagneCarbonationOutput.set_text("Enter a positive number");
} else {
champagneCarbonationMaths(champagneVolume, imperialOrMetric, champagneCarbonationBuilderClone);
let totalSugar = champagneCarbonationMaths(champagneVolume, &imperialOrMetric);
champagneOutput(totalSugar, imperialOrMetric, champagneCarbonationBuilderClone)
}
}
fn champagneCarbonationMaths(champagneVolume: f64, imperialOrMetric: imperialOrMetric, champagneCarbonationBuilderClone: &gtk::Builder) {
let champagneCarbonationOutput: gtk::Entry = champagneCarbonationBuilderClone.get_object("champagneCarbonationOutput").unwrap();
pub fn champagneCarbonationMaths(champagneVolume: f64, imperialOrMetric: &imperialOrMetric) -> f64 {
let mut totalSugar = 0.0;
if imperialOrMetric == &imperialOrMetric::imperial {
totalSugar = champagneVolume * 0.2;
} else if imperialOrMetric == &imperialOrMetric::metric {
totalSugar = (champagneVolume * 23.986897025) / 1000.0;
}
totalSugar
}
fn champagneOutput(totalSugar: f64, imperialOrMetric: imperialOrMetric, champagneCarbonationBuilderClone: &gtk::Builder) {
let champagneCarbonationOutput: gtk::Entry = champagneCarbonationBuilderClone.get_object("champagneCarbonationOutput").unwrap();
if imperialOrMetric == imperialOrMetric::imperial {
let totalSugar = champagneVolume * 0.2;
if totalSugar == 1.0 {
let sugar = format!("{:.0} pound", totalSugar);
champagneCarbonationOutput.set_text(&sugar);
......@@ -36,13 +47,12 @@ fn champagneCarbonationMaths(champagneVolume: f64, imperialOrMetric: imperialOrM
champagneCarbonationOutput.set_text(&sugar);
}
} else if imperialOrMetric == imperialOrMetric::metric {
let totalSugar = (champagneVolume * 23.986897025) / 1000.0;
if totalSugar == 1.0 {
let sugar = format!("{:.0} kilo", totalSugar);
champagneCarbonationOutput.set_text(&sugar);
} else {
let sugar = format!("{:.2} kilos", totalSugar);
champagneCarbonationOutput.set_text(&sugar);
}
if totalSugar == 1.0 {
let sugar = format!("{:.0} kilo", totalSugar);
champagneCarbonationOutput.set_text(&sugar);
} else {
let sugar = format!("{:.2} kilos", totalSugar);
champagneCarbonationOutput.set_text(&sugar);
}
}
}
\ No newline at end of file
......@@ -140,7 +140,7 @@ pub fn realABV(startingBrix: f64, finalBrix: f64) -> (f64, f64) {
(abv, attenuation)
}
pub fn grainToABV(volumeInGallons: f64, weightInPounds: f64, grainGravity: f64) -> f64 {
pub fn grainToGravity(volumeInGallons: f64, weightInPounds: f64, grainGravity: f64) -> f64 {
let extractPotential = grainGravity % 1.0 * 1000.0;
let extractionEfficiency = 0.57;
// sane default here of 57%
......
......@@ -224,13 +224,13 @@ fn grainABVMaths(allInputs: grainABVData, allOverlays: &colourOverlay) {
};
if allInputs.imperialOrMetric == imperialOrMetric::imperial {
let totalGrain1 = grainToABV(allInputs.wortAmount, allInputs.firstGrainAmount, allInputs.firstGrainInfo.0);
let totalGrain2 = grainToABV(allInputs.wortAmount, allInputs.secondGrainAmount, allInputs.secondGrainInfo.0);
let totalGrain3 = grainToABV(allInputs.wortAmount, allInputs.thirdGrainAmount, allInputs.thirdGrainInfo.0);
let totalGrain4 = grainToABV(allInputs.wortAmount, allInputs.fourthGrainAmount, allInputs.fourthGrainInfo.0);
let totalGrain5 = grainToABV(allInputs.wortAmount, allInputs.fifthGrainAmount, allInputs.fifthGrainInfo.0);
let totalGrain6 = grainToABV(allInputs.wortAmount, allInputs.sixthGrainAmount, allInputs.sixthGrainInfo.0);
let totalGrain7 = grainToABV(allInputs.wortAmount, allInputs.seventhGrainAmount, allInputs.seventhGrainInfo.0);
let totalGrain1 = grainToGravity(allInputs.wortAmount, allInputs.firstGrainAmount, allInputs.firstGrainInfo.0);
let totalGrain2 = grainToGravity(allInputs.wortAmount, allInputs.secondGrainAmount, allInputs.secondGrainInfo.0);
let totalGrain3 = grainToGravity(allInputs.wortAmount, allInputs.thirdGrainAmount, allInputs.thirdGrainInfo.0);
let totalGrain4 = grainToGravity(allInputs.wortAmount, allInputs.fourthGrainAmount, allInputs.fourthGrainInfo.0);
let totalGrain5 = grainToGravity(allInputs.wortAmount, allInputs.fifthGrainAmount, allInputs.fifthGrainInfo.0);
let totalGrain6 = grainToGravity(allInputs.wortAmount, allInputs.sixthGrainAmount, allInputs.sixthGrainInfo.0);
let totalGrain7 = grainToGravity(allInputs.wortAmount, allInputs.seventhGrainAmount, allInputs.seventhGrainInfo.0);
let grainSum = 1.0 + &totalGrain1 % 1.0 + &totalGrain2 % 1.0 + &totalGrain3 % 1.0 + &totalGrain4 % 1.0 + &totalGrain5 % 1.0 + &totalGrain6 % 1.0 + &totalGrain7 % 1.0;
let startingBrix = grainSum.gravityToBrix();
let estimatedBrix = format!("{:.2}°Bx", startingBrix);
......@@ -246,13 +246,13 @@ fn grainABVMaths(allInputs: grainABVData, allOverlays: &colourOverlay) {
allOverlays.colourOutput.set_rgba(&rgbaOutput);
}
} else if allInputs.imperialOrMetric == imperialOrMetric::metric {
let totalGrain1 = grainToABV(allInputs.wortAmount.litresToGallons(), allInputs.firstGrainAmount.kilosToPounds(), allInputs.firstGrainInfo.0);
let totalGrain2 = grainToABV(allInputs.wortAmount.litresToGallons(), allInputs.secondGrainAmount.kilosToPounds(), allInputs.secondGrainInfo.0);
let totalGrain3 = grainToABV(allInputs.wortAmount.litresToGallons(), allInputs.thirdGrainAmount.kilosToPounds(), allInputs.thirdGrainInfo.0);
let totalGrain4 = grainToABV(allInputs.wortAmount.litresToGallons(), allInputs.fourthGrainAmount.kilosToPounds(), allInputs.fourthGrainInfo.0);
let totalGrain5 = grainToABV(allInputs.wortAmount.litresToGallons(), allInputs.fifthGrainAmount.kilosToPounds(), allInputs.fifthGrainInfo.0);
let totalGrain6 = grainToABV(allInputs.wortAmount.litresToGallons(), allInputs.sixthGrainAmount.kilosToPounds(), allInputs.sixthGrainInfo.0);
let totalGrain7 = grainToABV(allInputs.wortAmount.litresToGallons(), allInputs.seventhGrainAmount.kilosToPounds(), allInputs.seventhGrainInfo.0);
let totalGrain1 = grainToGravity(allInputs.wortAmount.litresToGallons(), allInputs.firstGrainAmount.kilosToPounds(), allInputs.firstGrainInfo.0);
let totalGrain2 = grainToGravity(allInputs.wortAmount.litresToGallons(), allInputs.secondGrainAmount.kilosToPounds(), allInputs.secondGrainInfo.0);
let totalGrain3 = grainToGravity(allInputs.wortAmount.litresToGallons(), allInputs.thirdGrainAmount.kilosToPounds(), allInputs.thirdGrainInfo.0);
let totalGrain4 = grainToGravity(allInputs.wortAmount.litresToGallons(), allInputs.fourthGrainAmount.kilosToPounds(), allInputs.fourthGrainInfo.0);
let totalGrain5 = grainToGravity(allInputs.wortAmount.litresToGallons(), allInputs.fifthGrainAmount.kilosToPounds(), allInputs.fifthGrainInfo.0);
let totalGrain6 = grainToGravity(allInputs.wortAmount.litresToGallons(), allInputs.sixthGrainAmount.kilosToPounds(), allInputs.sixthGrainInfo.0);
let totalGrain7 = grainToGravity(allInputs.wortAmount.litresToGallons(), allInputs.seventhGrainAmount.kilosToPounds(), allInputs.seventhGrainInfo.0);
let grainSum = 1.0 + &totalGrain1 % 1.0 + &totalGrain2 % 1.0 + &totalGrain3 % 1.0 + &totalGrain4 % 1.0 + &totalGrain5 % 1.0 + &totalGrain6 % 1.0 + &totalGrain7 % 1.0;
let startingBrix = grainSum.gravityToBrix();
let estimatedBrix = format!("{:.2}°Bx", startingBrix);
......
......@@ -74,8 +74,8 @@ fn differenceBrixMaths(allInputs: increaseABVData) {
if allInputs.imperialOrMetric == imperialOrMetric::imperial {
let sugarToAddImperial = (allInputs.desiredWortVolume * 1.5 * differenceBrix) / 16.0;
let honeyToAddImperial = sugarToAddImperial * 1.25;
let sugar = format!("{} lbs {:.2} oz", sugarToAddImperial as u32, sugarToAddImperial % 1.0 * 16.0);
let honey = format!("{} lbs {:.2} oz", honeyToAddImperial as u32, honeyToAddImperial % 1.0 * 16.0);
let sugar = format!("{} lbs {:.2} oz", sugarToAddImperial as u64, sugarToAddImperial % 1.0 * 16.0);
let honey = format!("{} lbs {:.2} oz", honeyToAddImperial as u64, honeyToAddImperial % 1.0 * 16.0);
increaseABVNewBrixOutput.set_text(&newSB);
increaseABVSugarAddOutput.set_text(&sugar);
increaseABVHoneyAddOutput.set_text(&honey);
......
......@@ -2770,7 +2770,7 @@
<property name="can_focus">False</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">Version 5.2.0</property>
<property name="label" translatable="yes">Version 5.3.0</property>
</object>
<packing>
<property name="expand">False</property>
......@@ -2838,7 +2838,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title">BrewStillery</property>
<property name="subtitle">5.2.0</property>
<property name="subtitle">5.3.0</property>
<property name="show_close_button">True</property>
<child>
<placeholder/>
......
......@@ -14,6 +14,7 @@ use std::env::args;
mod gui;
mod functions;
mod light;
mod tests;
fn main() {
let application = gtk::Application::new("in.monkeylog.BrewStillery",
......
#[allow(unused_imports)]
use functions::commonFunctions::*;
#[allow(unused_imports)]
use functions::champagneCarbonation::champagneCarbonationMaths;
#[allow(unused_imports)]
use light::lightFunctions::*;
#[test]
fn champagneImperialTest() {
let champagneVolume = 20.0;
let switchState = imperialOrMetric::imperial;
assert_eq!(champagneCarbonationMaths(champagneVolume, &switchState), 4.0);
}
#[test]
fn champagneMetricTest() {
let champagneVolume = 75.708;
let switchState = imperialOrMetric::metric;
assert_eq!(champagneCarbonationMaths(champagneVolume, &switchState), 1.8159999999687);
}
#[test]
fn realABVTest() {
let startingBrix = 21.0;
let finalBrix = 14.0;
let output = realABV(startingBrix, finalBrix);
let abv = output.0;
let attenuation = output.1;
assert_eq!(abv, 4.973244658620157);
assert_eq!(attenuation, 0.37349534965963777);
}
#[test]
fn singleMCUTest() {
let volumeInGallons = 20.0;
let weightInPounds = 30.0;
let grainLVB = 1.8;
assert_eq!(singleMCU(volumeInGallons, weightInPounds, grainLVB), 2.7);
}
#[test]
fn beerSRMTest() {
assert_eq!(beerSRM(8.1), 6.265516962844715);
}
// used 20 gallons and 30lbs of 2-row in a dimple pint
#[test]
fn grainSRMToLABTest() {
let beerSRM = 2.94916751482842;
let glassDiameter = 9.8;
let output = grainSRMToLAB(glassDiameter, beerSRM);
let L = output.0;
let A = output.1;
let B = output.2;
assert_eq!(L, 65.29929503106153);
assert_eq!(A, 17.905799803172474);
assert_eq!(B, 76.97459931149983);
}
#[test]
fn grainLABToXYZTest() {
let L = 65.29929503106153;
let A = 17.905799803172474;
let B = 76.97459931149983;
let output = grainLABToXYZ(L, A, B);
let x = output.0;
let y = output.1;
let z = output.2;
assert_eq!(x, 37.99733219885034);
assert_eq!(y, 34.425984706398424);
assert_eq!(z, 3.4351935539850422);
}
#[test]
fn grainXYZToRGBATest() {
let x = 37.99733219885034;
let y = 34.425984706398424;
let z = 3.4351935539850422;
let output = grainXYZToRGBA(x, y, z);
assert_eq!(output.red, 0.842840006924834);
assert_eq!(output.green, 0.5626270741600671);
assert_eq!(output.blue, -0.16414442218027928);
assert_eq!(output.alpha, 1.0);
}
#[test]
fn grainToGravityTest() {
let volumeInGallons = 20.0;
let weightInPounds = 30.0;
let grainGravity = 1.037;
let output = grainToGravity(volumeInGallons, weightInPounds, grainGravity);
assert_eq!(output, 1.0316349999999999)
}
#[test]
fn realIBUTest() {
let brix = 20.0;
let wortVolume = 20.0;
let boilTime = 60.0;
let alphaAcid = 7.0;
let hopAmount = 3.0;
let output = realIBU(brix, wortVolume, boilTime, alphaAcid, hopAmount);
assert_eq!(output, 13.486826596469873);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment