Commit 5bc0d967 authored by Meade's avatar Meade

Added version 6.2.0. Annotated types to all variables. Cleaned up logic in...

Added version 6.2.0. Annotated types to all variables. Cleaned up logic in realABVFormatting(). Updated tests.
parent e393f718
## New In 6.2.0
* * Annotated types to all variables
* * Cleaned up unnecessary logic in `realABVFormatting()`
* * Updated tests to include all logic cases
## New In 6.1.0
* * Made use lines explicit
* * Fixed strict floating point comparisons
......
[[package]]
name = "BrewStillery"
version = "6.1.0"
version = "6.2.0"
dependencies = [
"gdk 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gio 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
......
[package]
name = "BrewStillery"
version = "6.1.0"
version = "6.2.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,10 +4,10 @@ It has a multitude of great functions, such as calculating ABV, determining carb
Written in Rust, using GTK3
## New In 6.1.0
* * Made use lines explicit
* * Fixed strict floating point comparisons
* * Changed `.validInput()` to return NAN instead of 0.0. Also changed all logic to use `.is_nan()` to match.
## New In 6.2.0
* * Annotated types to all variables
* * Cleaned up unnecessary logic in `realABVFormatting()`
* * Updated tests to include all logic cases
## Full Changelog
* [Available Here](CHANGELOG.md)
......
......@@ -4,27 +4,27 @@ use functions::commonFunctions::{imperialOrMetric, inputMatching, singleInput};
pub fn champagneCarbonationPrep(champagneCarbonationBuilder: &gtk::Builder) {
let champagneCarbonationVolume: gtk::Entry = champagneCarbonationBuilder.get_object("champagneCarbonationVolume").expect("champagneCarbonationPrep(), champagneCarbonationVolume");
let champagneCarbonationVolumeBuffer = champagneCarbonationVolume.get_text().expect("champagneCarbonationPrep(), champagneCarbonationVolumeBuffer");
let champagneVolume = champagneCarbonationVolumeBuffer.validInput();
let champagneCarbonationVolumeBuffer: String = champagneCarbonationVolume.get_text().expect("champagneCarbonationPrep(), champagneCarbonationVolumeBuffer");
let champagneVolume: f64 = champagneCarbonationVolumeBuffer.validInput();
let champagneCarbonationSugar: gtk::Entry = champagneCarbonationBuilder.get_object("champagneCarbonationSugar").expect("champagneCarbonationPrep(), champagneCarbonationSugar");
let champagneCarbonationUnits: gtk::ComboBoxText = champagneCarbonationBuilder.get_object("champagneCarbonationUnits").expect("champagneCarbonationPrep(), champagneCarbonationUnits");
let champagneCarbonationUnitsBuffer = champagneCarbonationUnits.get_active_id().expect("champagneCarbonationPrep(), champagneCarbonationUnitsBuffer");
let imperialOrMetric = champagneCarbonationUnitsBuffer.unitMatch();
let champagneCarbonationUnitsBuffer: String = champagneCarbonationUnits.get_active_id().expect("champagneCarbonationPrep(), champagneCarbonationUnitsBuffer");
let imperialOrMetric: imperialOrMetric = champagneCarbonationUnitsBuffer.unitMatch();
if champagneVolume.is_nan() {
champagneCarbonationSugar.set_text("Enter a number");
} else if champagneVolume <= 0.0 {
champagneCarbonationSugar.set_text("Enter a positive number");
} else {
let totalSugar = champagneCarbonationMaths(champagneVolume, imperialOrMetric);
let totalSugar: f64 = champagneCarbonationMaths(champagneVolume, imperialOrMetric);
champagneOutput(totalSugar, imperialOrMetric, champagneCarbonationBuilder)
}
}
pub fn champagneCarbonationMaths(champagneVolume: f64, imperialOrMetric: imperialOrMetric) -> f64 {
let mut totalSugar = 0.0;
let mut totalSugar: f64 = 0.0;
if imperialOrMetric == imperialOrMetric::imperialGB {
totalSugar = champagneVolume.gallonsGBToGallonsUS().volumeToSugarChampagne();
......@@ -38,7 +38,7 @@ pub fn champagneCarbonationMaths(champagneVolume: f64, imperialOrMetric: imperia
}
pub fn champagneCarbonationFormatting(totalSugar: f64, imperialOrMetric: imperialOrMetric) -> String {
let mut sugar = String::from("");
let mut sugar: String = String::from("");
if imperialOrMetric == imperialOrMetric::imperialGB || imperialOrMetric == imperialOrMetric::imperialUS {
if totalSugar < 0.995 {
......@@ -68,7 +68,7 @@ pub fn champagneCarbonationFormatting(totalSugar: f64, imperialOrMetric: imperia
fn champagneOutput(totalSugar: f64, imperialOrMetric: imperialOrMetric, champagneCarbonationBuilder: &gtk::Builder) {
let champagneCarbonationSugar: gtk::Entry = champagneCarbonationBuilder.get_object("champagneCarbonationSugar").expect("champagneCarbonationPrep(), champagneCarbonationSugar");
let sugar = champagneCarbonationFormatting(totalSugar, imperialOrMetric);
let sugar: String = champagneCarbonationFormatting(totalSugar, imperialOrMetric);
champagneCarbonationSugar.set_text(&sugar);
}
\ No newline at end of file
......@@ -36,7 +36,7 @@ pub trait allOverlays {
impl allOverlays for gtk::Builder {
fn new(&self) -> colourOverlay {
let allOverlays = colourOverlay {
let allOverlays: colourOverlay = colourOverlay {
overlay: self.get_object("grainABVColourOverlay").expect("commonFunctions, allOverlays"),
colourOutput: gtk::ColorButton::new(),
dimplePint: gtk::Image::new_from_file("/usr/share/BrewStillery/glassware/Dimple.png"),
......@@ -239,28 +239,28 @@ pub fn realIBU(brix: f64, wortVolume: f64, alphaAcid: f64, hopAmount: f64, boilT
pub fn realABVAndAttenuation(startingBrix: f64, finalBrix: f64) -> (f64, f64) {
let wortCorrectionFactor: f64 = 1.040;
let initialRefractiveIndex = startingBrix / wortCorrectionFactor;
let finalRefractiveIndex = finalBrix / wortCorrectionFactor;
let initialRefractiveIndex: f64 = startingBrix / wortCorrectionFactor;
let finalRefractiveIndex: f64 = finalBrix / wortCorrectionFactor;
let newCubic = (1.0 - 0.0044992999999999995 * initialRefractiveIndex) + (0.0117741 * finalRefractiveIndex) + (0.000275806 * initialRefractiveIndex.powi(2)) - (0.00127169 * finalRefractiveIndex.powi(2)) - (7.27999e-06 * initialRefractiveIndex.powi(3)) + (6.32929e-05 * finalRefractiveIndex.powi(3));
let newCubic: f64 = (1.0 - 0.0044992999999999995 * initialRefractiveIndex) + (0.0117741 * finalRefractiveIndex) + (0.000275806 * initialRefractiveIndex.powi(2)) - (0.00127169 * finalRefractiveIndex.powi(2)) - (7.27999e-06 * initialRefractiveIndex.powi(3)) + (6.32929e-05 * finalRefractiveIndex.powi(3));
let apparentAttenuation = 1.0 - (0.18080000000000002 * (668.72 * newCubic - 463.37 - 205.347 * newCubic.powi(2)) + 0.8192 * (668.72 * newCubic - 463.37 - 205.347 * newCubic.powi(2))) / (initialRefractiveIndex);
let apparentAttenuation: f64 = 1.0 - (0.18080000000000002 * (668.72 * newCubic - 463.37 - 205.347 * newCubic.powi(2)) + 0.8192 * (668.72 * newCubic - 463.37 - 205.347 * newCubic.powi(2))) / (initialRefractiveIndex);
let attenuation = apparentAttenuation * 0.8192 * 100.0;
let attenuation: f64 = apparentAttenuation * 0.8192 * 100.0;
let abv = ((0.01 / 0.8192) * (initialRefractiveIndex - (0.18080000000000002 * initialRefractiveIndex + 0.8192 * (668.72 * newCubic - 463.37 - 205.347 * newCubic.powi(2)))) / (2.0665-0.010665 * initialRefractiveIndex)) * 100.0;
let abv: f64 = ((0.01 / 0.8192) * (initialRefractiveIndex - (0.18080000000000002 * initialRefractiveIndex + 0.8192 * (668.72 * newCubic - 463.37 - 205.347 * newCubic.powi(2)))) / (2.0665-0.010665 * initialRefractiveIndex)) * 100.0;
(abv, attenuation)
}
pub fn grainToGravity(volumeInGallonsUS: f64, weightInPounds: f64, grainGravity: f64) -> f64 {
let extractPotential = grainGravity.fract() * 1000.0;
let extractionEfficiency = 0.57;
let extractPotential: f64 = grainGravity.fract() * 1000.0;
let extractionEfficiency: f64 = 0.57;
// sane default here of 57%
let mut originalGravity = 1.0;
let mut originalGravity: f64 = 1.0;
// set to the gravity of water
let specificGravityPoints = (weightInPounds * extractPotential * extractionEfficiency) / volumeInGallonsUS;
let specificGravityPoints: f64 = (weightInPounds * extractPotential * extractionEfficiency) / volumeInGallonsUS;
if specificGravityPoints != 0.0 {
originalGravity = specificGravityPoints / 1000.0 + 1.0;
......
This diff is collapsed.
......@@ -4,8 +4,8 @@ use functions::commonFunctions::{inputMatching, realABVAndAttenuation, FINAL_BRI
pub fn guestimateABVPrep(guestimatorBuilder: &gtk::Builder) {
let guestimatorStartingBrix: gtk::Entry = guestimatorBuilder.get_object("guestimatorStartingBrix").expect("guestimateABVPrep(), guestimatorStartingBrix");
let guestimatorStartingBrixBuffer = guestimatorStartingBrix.get_text().expect("guestimateABVPrep(), guestimatorStartingBrixBuffer");
let startingBrix = guestimatorStartingBrixBuffer.validInput();
let guestimatorStartingBrixBuffer: String = guestimatorStartingBrix.get_text().expect("guestimateABVPrep(), guestimatorStartingBrixBuffer");
let startingBrix: f64 = guestimatorStartingBrixBuffer.validInput();
let guestimatorTemporaryOutput: gtk::Entry = guestimatorBuilder.get_object("guestimatorABV").expect("guestimateABVPrep(), guestimatorTemporaryOutput");
if startingBrix.is_nan() {
......@@ -20,14 +20,14 @@ pub fn guestimateABVPrep(guestimatorBuilder: &gtk::Builder) {
}
pub fn guestimateABVFormatting(startingBrix: f64) -> String {
let finalABV = format!("{:.2}%", realABVAndAttenuation(startingBrix, FINAL_BRIX_IDEAL).0);
let finalABV: String = format!("{:.2}%", realABVAndAttenuation(startingBrix, FINAL_BRIX_IDEAL).0);
finalABV
}
fn guestimateABVOutput(startingBrix: f64, guestimatorBuilder: &gtk::Builder) {
let guestimatorABV: gtk::Entry = guestimatorBuilder.get_object("guestimatorABV").expect("guestimateABVOutput(), guestimatorABV");
let finalABV = guestimateABVFormatting(startingBrix);
let finalABV: String = guestimateABVFormatting(startingBrix);
guestimatorABV.set_text(&finalABV);
}
\ No newline at end of file
This diff is collapsed.
......@@ -13,22 +13,22 @@ pub struct gyleData {
pub fn gyleCarbonationPrep(gyleBuilder: &gtk::Builder) {
let gyleStartingBrix: gtk::Entry = gyleBuilder.get_object("gyleStartingBrix").expect("gyleCarbonationPrep(), gyleStartingBrix");
let gyleStartingBrixBuffer = gyleStartingBrix.get_text().expect("gyleCarbonationPrep(), gyleStartingBrixBuffer");
let startingBrix = gyleStartingBrixBuffer.validInput();
let gyleStartingBrixBuffer: String = gyleStartingBrix.get_text().expect("gyleCarbonationPrep(), gyleStartingBrixBuffer");
let startingBrix: f64 = gyleStartingBrixBuffer.validInput();
let gyleDesiredCO2: gtk::Entry = gyleBuilder.get_object("gyleDesiredCO2").expect("gyleCarbonationPrep(), gyleDesiredCO2");
let gyleDesiredCO2Buffer = gyleDesiredCO2.get_text().expect("gyleCarbonationPrep(), gyleDesiredCO2Buffer");
let desiredCO2LevelTemp = gyleDesiredCO2Buffer.validInput();
let gyleDesiredCO2Buffer: String = gyleDesiredCO2.get_text().expect("gyleCarbonationPrep(), gyleDesiredCO2Buffer");
let desiredCO2LevelTemp: f64 = gyleDesiredCO2Buffer.validInput();
let gyleWortVolume: gtk::Entry = gyleBuilder.get_object("gyleWortVolume").expect("gyleCarbonationPrep(), gyleWortVolume");
let gyleWortVolumeBuffer = gyleWortVolume.get_text().expect("gyleCarbonationPrep(), gyleWortVolumeBuffer");
let finalVolumeTemp = gyleWortVolumeBuffer.validInput();
let gyleWortVolumeBuffer: String = gyleWortVolume.get_text().expect("gyleCarbonationPrep(), gyleWortVolumeBuffer");
let finalVolumeTemp: f64 = gyleWortVolumeBuffer.validInput();
let gyleTemporaryOutput: &gtk::Entry = &gyleBuilder.get_object("gyleCarbonationOutput").expect("gyleCarbonationPrep(), gyleTemporaryOutput");
let gyleCarbonationUnits: gtk::ComboBoxText = gyleBuilder.get_object("gyleCarbonationUnits").expect("gyleCarbonationPrep(), gyleCarbonationUnits");
let gyleCarbonationUnitsBuffer = gyleCarbonationUnits.get_active_id().expect("gyleCarbonationPrep(), gyleCarbonationUnitsBuffer");
let imperialOrMetric = gyleCarbonationUnitsBuffer.unitMatch();
let gyleCarbonationUnitsBuffer: String = gyleCarbonationUnits.get_active_id().expect("gyleCarbonationPrep(), gyleCarbonationUnitsBuffer");
let imperialOrMetric: imperialOrMetric = gyleCarbonationUnitsBuffer.unitMatch();
if startingBrix < 2.57 {
gyleTemporaryOutput.set_text("Enter a Starting Brix greater than 2.57");
......@@ -39,7 +39,7 @@ pub fn gyleCarbonationPrep(gyleBuilder: &gtk::Builder) {
} else if startingBrix <= 0.0 || desiredCO2LevelTemp <= 0.0 || finalVolumeTemp <= 0.0 {
gyleTemporaryOutput.set_text("Enter a positive number");
} else {
let allInputs = gyleData {
let allInputs: gyleData = gyleData {
startingGravity: startingBrix.brixToGravity(),
desiredCO2Level: desiredCO2LevelTemp,
finalVolume: finalVolumeTemp,
......@@ -62,8 +62,8 @@ pub fn gyleCarbonationVolumeUnits(allInputs: &mut gyleData) -> &mut gyleData {
}
pub fn gyleCarbonationMaths(mut allInputs: gyleData) -> gyleData {
let startingPlato = allInputs.startingGravity.gravityToPlato();
let finalPlatoIdeal = FINAL_GRAVITY_IDEAL.gravityToPlato();
let startingPlato: f64 = allInputs.startingGravity.gravityToPlato();
let finalPlatoIdeal: f64 = FINAL_GRAVITY_IDEAL.gravityToPlato();
allInputs.gyleVolumeFloat = (0.24 * allInputs.finalVolume * allInputs.desiredCO2Level) / (startingPlato - finalPlatoIdeal);
......@@ -72,11 +72,13 @@ pub fn gyleCarbonationMaths(mut allInputs: gyleData) -> gyleData {
pub fn gyleCarbonationFormatting(allInputs: gyleData) -> String {
let mut finalOutput = String::from("");
let mut finalOutput: String = String::from("");
let gyleCarbonationMathsOutput: gyleData;
let gyleVolumeFinal: f64;
if allInputs.imperialOrMetric == imperialOrMetric::imperialGB {
let gyleCarbonationMathsOutput = gyleCarbonationMaths(allInputs);
let gyleVolumeFinal = gyleCarbonationMathsOutput.gyleVolumeFloat.litresToGallonsGB();
gyleCarbonationMathsOutput = gyleCarbonationMaths(allInputs);
gyleVolumeFinal = gyleCarbonationMathsOutput.gyleVolumeFloat.litresToGallonsGB();
if gyleVolumeFinal >= 0.995 && gyleVolumeFinal < 1.005 {
finalOutput = format!("{:.0} gallon", gyleVolumeFinal);
} else if gyleVolumeFinal.fract() >= 0.995 || gyleVolumeFinal.fract() < 0.005 {
......@@ -85,8 +87,8 @@ pub fn gyleCarbonationFormatting(allInputs: gyleData) -> String {
finalOutput = format!("{:.2} gallons", gyleVolumeFinal);
}
} else if allInputs.imperialOrMetric == imperialOrMetric::imperialUS {
let gyleCarbonationMathsOutput = gyleCarbonationMaths(allInputs);
let gyleVolumeFinal = gyleCarbonationMathsOutput.gyleVolumeFloat.litresToGallonsUS();
gyleCarbonationMathsOutput = gyleCarbonationMaths(allInputs);
gyleVolumeFinal = gyleCarbonationMathsOutput.gyleVolumeFloat.litresToGallonsUS();
if gyleVolumeFinal >= 0.995 && gyleVolumeFinal < 1.005 {
finalOutput = format!("{:.0} gallon", gyleVolumeFinal);
} else if gyleVolumeFinal.fract() >= 0.995 || gyleVolumeFinal.fract() < 0.005 {
......@@ -95,8 +97,8 @@ pub fn gyleCarbonationFormatting(allInputs: gyleData) -> String {
finalOutput = format!("{:.2} gallons", gyleVolumeFinal);
}
} else if allInputs.imperialOrMetric == imperialOrMetric::metric {
let gyleCarbonationMathsOutput = gyleCarbonationMaths(allInputs);
let gyleVolumeFinal = gyleCarbonationMathsOutput.gyleVolumeFloat;
gyleCarbonationMathsOutput = gyleCarbonationMaths(allInputs);
gyleVolumeFinal = gyleCarbonationMathsOutput.gyleVolumeFloat;
if gyleVolumeFinal >= 0.995 && gyleVolumeFinal < 1.005 {
finalOutput = format!("{:.0} litre", gyleVolumeFinal);
} else if gyleVolumeFinal.fract() >= 0.995 || gyleVolumeFinal.fract() < 0.005 {
......@@ -114,9 +116,9 @@ fn gyleCarbonationOutput(mut allInputs: gyleData, gyleBuilder: &gtk::Builder) {
gyleCarbonationVolumeUnits(&mut allInputs);
let finalOutputFloat = gyleCarbonationMaths(allInputs);
let finalOutputFloat: gyleData = gyleCarbonationMaths(allInputs);
let finalOutput = gyleCarbonationFormatting(finalOutputFloat);
let finalOutput: String = gyleCarbonationFormatting(finalOutputFloat);
gyleCarbonationOutput.set_text(&finalOutput);
}
\ No newline at end of file
......@@ -26,20 +26,20 @@ pub struct sugarOutputStrings {
pub fn increaseABVPrep(increaseABVBuilder: &gtk::Builder) {
let increaseABVStartingBrix: gtk::Entry = increaseABVBuilder.get_object("increaseABVStartingBrix").expect("increaseABVPrep(), increaseABVStartingBrix");
let increaseABVBrixBuffer = increaseABVStartingBrix.get_text().expect("increaseABVPrep(), increaseABVBrixBuffer");
let increaseABVBrixBuffer: String = increaseABVStartingBrix.get_text().expect("increaseABVPrep(), increaseABVBrixBuffer");
let increaseABVDesiredABV: gtk::Entry = increaseABVBuilder.get_object("increaseABVDesiredABV").expect("increaseABVPrep(), increaseABVDesiredABV");
let increaseABVABVBuffer = increaseABVDesiredABV.get_text().expect("increaseABVPrep(), increaseABVABVBuffer");
let increaseABVABVBuffer: String = increaseABVDesiredABV.get_text().expect("increaseABVPrep(), increaseABVABVBuffer");
let increaseABVCurrentVolume: gtk::Entry = increaseABVBuilder.get_object("increaseABVCurrentVolume").expect("increaseABVPrep(), increaseABVCurrentVolume");
let increaseABVVolumeBuffer = increaseABVCurrentVolume.get_text().expect("increaseABVPrep(), increaseABVVolumeBuffer");
let increaseABVVolumeBuffer: String = increaseABVCurrentVolume.get_text().expect("increaseABVPrep(), increaseABVVolumeBuffer");
let increaseABVFinalBrix: gtk::Entry = increaseABVBuilder.get_object("increaseABVFinalBrix").expect("increaseABVPrep(), increaseABVFinalBrix");
let increaseABVSugar: gtk::Entry = increaseABVBuilder.get_object("increaseABVSugar").expect("increaseABVPrep(), increaseABVSugar");
let increaseABVHoney: gtk::Entry = increaseABVBuilder.get_object("increaseABVHoney").expect("increaseABVPrep(), increaseABVHoney");
let increaseABVUnits: gtk::ComboBoxText = increaseABVBuilder.get_object("increaseABVUnits").expect("increaseABVPrep(), increaseABVUnits");
let increaseABVUnitsBuffer = increaseABVUnits.get_active_id().expect("increaseABVPrep(), increaseABVUnitsBuffer");
let increaseABVUnitsBuffer: String = increaseABVUnits.get_active_id().expect("increaseABVPrep(), increaseABVUnitsBuffer");
let allInputs = increaseABVData {
startingBrix: increaseABVBrixBuffer.validInput(),
......@@ -70,17 +70,17 @@ pub fn increaseABVPrep(increaseABVBuilder: &gtk::Builder) {
}
pub fn increaseABVMaths(allInputs: &increaseABVData) -> finalSugarFloat {
let mut newStartingBrix = allInputs.startingBrix;
let mut newEstimatedABV = realABVAndAttenuation(newStartingBrix, FINAL_BRIX_IDEAL).0;
let mut newStartingBrix: f64 = allInputs.startingBrix;
let mut newEstimatedABV: f64 = realABVAndAttenuation(newStartingBrix, FINAL_BRIX_IDEAL).0;
while newEstimatedABV <= allInputs.desiredABV {
newStartingBrix = newStartingBrix + 0.001;
newEstimatedABV = realABVAndAttenuation(newStartingBrix, FINAL_BRIX_IDEAL).0;
}
let differenceBrix = newStartingBrix - allInputs.startingBrix;
let differenceBrix: f64 = newStartingBrix - allInputs.startingBrix;
let mut finalOutputFloat = finalSugarFloat {
let mut finalOutputFloat: finalSugarFloat = finalSugarFloat {
newStartingBrixFinal: newStartingBrix,
sugarToAdd: 0.0,
honeyToAdd: 0.0,
......@@ -103,7 +103,7 @@ pub fn increaseABVMaths(allInputs: &increaseABVData) -> finalSugarFloat {
}
pub fn increaseABVFormatting(allInputs: &increaseABVData, finalOutputFloat: finalSugarFloat) -> sugarOutputStrings {
let mut finalOutput = sugarOutputStrings {
let mut finalOutput: sugarOutputStrings = sugarOutputStrings {
newStartingBrixFinal: format!("{:.2}°Bx", finalOutputFloat.newStartingBrixFinal),
sugarAmount: String::from(""),
honeyAmount: String::from(""),
......@@ -159,8 +159,8 @@ fn increaseABVOutput(allInputs: increaseABVData, increaseABVBuilder: &gtk::Build
let increaseABVSugar: gtk::Entry = increaseABVBuilder.get_object("increaseABVSugar").expect("increaseABVOutput(), increaseABVFinalBrix");
let increaseABVHoney: gtk::Entry = increaseABVBuilder.get_object("increaseABVHoney").expect("increaseABVOutput(), increaseABVFinalBrix");
let finalOutputFloat = increaseABVMaths(&allInputs);
let finalOutput = increaseABVFormatting(&allInputs, finalOutputFloat);
let finalOutputFloat: finalSugarFloat = increaseABVMaths(&allInputs);
let finalOutput: sugarOutputStrings = increaseABVFormatting(&allInputs, finalOutputFloat);
increaseABVFinalBrix.set_text(&finalOutput.newStartingBrixFinal);
increaseABVSugar.set_text(&finalOutput.sugarAmount);
......
......@@ -4,12 +4,12 @@ use functions::commonFunctions::{inputMatching, realABVAndAttenuation};
pub fn realABVPrep(realABVBuilder: &gtk::Builder) {
let realABVStartingBrix: gtk::Entry = realABVBuilder.get_object("realABVStartingBrix").expect("realABVPrep(), realABVStartingBrix");
let realABVStartingBrixBuffer = realABVStartingBrix.get_text().expect("realABVPrep(), realABVStartingBrixBuffer");
let startingBrix = realABVStartingBrixBuffer.validInput();
let realABVStartingBrixBuffer: String = realABVStartingBrix.get_text().expect("realABVPrep(), realABVStartingBrixBuffer");
let startingBrix: f64 = realABVStartingBrixBuffer.validInput();
let realABVFinalBrix: gtk::Entry = realABVBuilder.get_object("realABVFinalBrix").expect("realABVPrep(), realABVFinalrealABVFinalBrixBrixInput");
let realABVFinalBrixInputBuffer = realABVFinalBrix.get_text().expect("realABVPrep(), realABVFinalBrixInputBuffer");
let finalBrix = realABVFinalBrixInputBuffer.validInput();
let realABVFinalBrixInputBuffer: String = realABVFinalBrix.get_text().expect("realABVPrep(), realABVFinalBrixInputBuffer");
let finalBrix: f64 = realABVFinalBrixInputBuffer.validInput();
let realABVFinalABV: gtk::Entry = realABVBuilder.get_object("realABVFinalABV").expect("realABVPrep(), realABVFinalABV");
let realABVRealAttenuation: gtk::Entry = realABVBuilder.get_object("realABVRealAttenuation").expect("realABVPrep(), realABVRealAttenuation");
......@@ -35,13 +35,10 @@ pub fn realABVPrep(realABVBuilder: &gtk::Builder) {
}
pub fn realABVFormatting(abvFloat: f64, attenuationFloat: f64) -> (String, String) {
let abvFormatted;
let attenuationFormatted;
let mut abvFormatted: String = String::from("");
let mut attenuationFormatted: String = String::from("Enter legimate amounts");
if abvFloat > 26.0 || abvFloat <= 0.0 {
abvFormatted = String::from("");
attenuationFormatted = String::from("Enter legimate amounts");
} else {
if abvFloat > 0.0 && abvFloat < 26.0 {
abvFormatted = format!("{:.2}%", abvFloat);
attenuationFormatted = format!("{:.2}%", attenuationFloat);
}
......
......@@ -30,22 +30,22 @@ pub struct spargeOutputStrings {
pub fn waterSpargePrep(waterSpargeBuilder: &gtk::Builder) {
let spargePreFermentVolume: gtk::Entry = waterSpargeBuilder.get_object("spargePreFermentVolume").expect("waterSpargePrep(), spargePreFermentVolume");
let spargePreFermentVolumeBuffer = spargePreFermentVolume.get_text().expect("waterSpargePrep(), spargePreFermentVolumeBuffer");
let spargePreFermentVolumeBuffer: String = spargePreFermentVolume.get_text().expect("waterSpargePrep(), spargePreFermentVolumeBuffer");
let spargeTotalGrain: gtk::Entry = waterSpargeBuilder.get_object("spargeTotalGrain").expect("waterSpargePrep(), spargeTotalGrain");
let spargeTotalGrainBuffer = spargeTotalGrain.get_text().expect("waterSpargePrep(), spargeTotalGrainBuffer");
let spargeTotalGrainBuffer: String = spargeTotalGrain.get_text().expect("waterSpargePrep(), spargeTotalGrainBuffer");
let spargeBoilTime: gtk::Entry = waterSpargeBuilder.get_object("spargeBoilTime").expect("waterSpargePrep(), spargeBoilTime");
let spargeBoilTimeBuffer = spargeBoilTime.get_text().expect("waterSpargePrep(), spargeBoilTimeBuffer");
let spargeBoilTimeBuffer: String = spargeBoilTime.get_text().expect("waterSpargePrep(), spargeBoilTimeBuffer");
let spargeMashWater: gtk::Entry = waterSpargeBuilder.get_object("spargeMashWater").expect("waterSpargePrep(), spargeMashWater");
let spargeSpargeWater: gtk::Entry = waterSpargeBuilder.get_object("spargeSpargeWater").expect("waterSpargePrep(), spargeSpargeWater");
let spargeTotalWater: gtk::Entry = waterSpargeBuilder.get_object("spargeTotalWater").expect("waterSpargePrep(), spargeTotalWater");
let waterSpargeUnits: gtk::ComboBoxText = waterSpargeBuilder.get_object("waterSpargeUnits").expect("waterSpargePrep(), waterSpargeUnits");
let waterSpargeUnitsBuffer = waterSpargeUnits.get_active_id().expect("waterSpargePrep(), waterSpargeUnitsBuffer");
let waterSpargeUnitsBuffer: String = waterSpargeUnits.get_active_id().expect("waterSpargePrep(), waterSpargeUnitsBuffer");
let mut allInputs = waterSpargeData {
let mut allInputs: waterSpargeData = waterSpargeData {
preFermentVolume: spargePreFermentVolumeBuffer.validInput(),
totalGrain: spargeTotalGrainBuffer.validInput(),
boilTime: spargeBoilTimeBuffer.validInput(),
......@@ -87,17 +87,17 @@ fn waterSpargeSetValues(mut allInputs: waterSpargeData) -> waterSpargeData {
}
pub fn waterSpargeMaths(allInputs: &waterSpargeData) -> finalSpargeFloat {
let trubLoss = allInputs.preFermentVolume * 0.05;
let trubLoss: f64 = allInputs.preFermentVolume * 0.05;
// 5% is an acceptable norm
let equipmentLoss = allInputs.preFermentVolume * 0.08;
let equipmentLoss: f64 = allInputs.preFermentVolume * 0.08;
// 8% is an acceptable norm
let totalWater = (((allInputs.preFermentVolume + trubLoss) / (1.0 - allInputs.wortShrinkage)) / (1.0 - ((allInputs.boilTime / 60.0) * allInputs.percentBoiloff))) + equipmentLoss + (allInputs.totalGrain * allInputs.grainAbsorption);
let totalWater: f64 = (((allInputs.preFermentVolume + trubLoss) / (1.0 - allInputs.wortShrinkage)) / (1.0 - ((allInputs.boilTime / 60.0) * allInputs.percentBoiloff))) + equipmentLoss + (allInputs.totalGrain * allInputs.grainAbsorption);
// dividing boilTime by 60.0 because the formula requires hours
let mashWater = (allInputs.totalGrain * allInputs.mashThickness) / 4.0;
let spargeWater = totalWater - mashWater;
let mashWater: f64 = (allInputs.totalGrain * allInputs.mashThickness) / 4.0;
let spargeWater: f64 = totalWater - mashWater;
let finalOutputFloat = finalSpargeFloat {
let finalOutputFloat: finalSpargeFloat = finalSpargeFloat {
mashVolume: mashWater,
spargeVolume: spargeWater,
totalVolume: totalWater,
......@@ -107,7 +107,7 @@ pub fn waterSpargeMaths(allInputs: &waterSpargeData) -> finalSpargeFloat {
}
pub fn waterSpargeFormatting(allInputs: &waterSpargeData, finalOutputFloat: finalSpargeFloat) -> spargeOutputStrings {
let mut finalOutput = spargeOutputStrings {
let mut finalOutput: spargeOutputStrings = spargeOutputStrings {
mashVolumeFinal: String::from(""),
spargeVolumeFinal: String::from(""),
totalVolumeFinal: String::from(""),
......@@ -197,8 +197,8 @@ fn waterSpargeOutput(allInputs: waterSpargeData, waterSpargeBuilder: &gtk::Build
let spargeSpargeWater: gtk::Entry = waterSpargeBuilder.get_object("spargeSpargeWater").expect("waterSpargeOutput(), spargeSpargeWater");
let spargeTotalWater: gtk::Entry = waterSpargeBuilder.get_object("spargeTotalWater").expect("waterSpargeOutput(), spargeTotalWater");
let finalOutputFloat = waterSpargeMaths(&allInputs);
let finalOutput = waterSpargeFormatting(&allInputs, finalOutputFloat);
let finalOutputFloat: finalSpargeFloat = waterSpargeMaths(&allInputs);
let finalOutput: spargeOutputStrings = waterSpargeFormatting(&allInputs, finalOutputFloat);
spargeMashWater.set_text(&finalOutput.mashVolumeFinal);
spargeSpargeWater.set_text(&finalOutput.spargeVolumeFinal);
......
......@@ -2657,7 +2657,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 6.1.0</property>
<property name="label" translatable="yes">Version 6.2.0</property>
</object>
<packing>
<property name="expand">False</property>
......@@ -2740,7 +2740,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title">BrewStillery</property>
<property name="subtitle">6.1.0</property>
<property name="subtitle">6.2.0</property>
<property name="show_close_button">True</property>
<child>
<placeholder/>
......
......@@ -3,36 +3,36 @@ use functions::champagneCarbonation::{champagneCarbonationMaths, champagneCarbon
#[test]
fn champagneMathsImperialGBTest() {
let champagneVolume = 20.0;
let imperialOrMetric = imperialOrMetric::imperialGB;
let champagneVolume: f64 = 20.0;
let imperialOrMetric: imperialOrMetric = imperialOrMetric::imperialGB;
assert_eq!(champagneCarbonationMaths(champagneVolume, imperialOrMetric), 4.8038);
}
#[test]
fn champagneMathsImperialUSTest() {
let champagneVolume = 20.0;
let imperialOrMetric = imperialOrMetric::imperialUS;
let champagneVolume: f64 = 20.0;
let imperialOrMetric: imperialOrMetric = imperialOrMetric::imperialUS;
assert_eq!(champagneCarbonationMaths(champagneVolume, imperialOrMetric), 4.0);
}
#[test]
fn champagneMathsMetricTest() {
let champagneVolume = 60.0;
let imperialOrMetric = imperialOrMetric::metric;
let champagneVolume: f64 = 60.0;
let imperialOrMetric: imperialOrMetric = imperialOrMetric::metric;
assert_eq!(champagneCarbonationMaths(champagneVolume, imperialOrMetric), 1.437917125853319);
}
#[test]
fn champagneFormattingGBTest() {
let totalSugarUnderOne = 0.72057;
let totalSugarOne = 0.9967885000000001;
let totalSugarPoundWithOunces = 1.68133;
let totalSugarPounds = 4.00012426;
let totalSugarPoundsWithOunces = 4.8038;
let imperialOrMetric = imperialOrMetric::imperialGB;
let totalSugarUnderOne: f64 = 0.72057;
let totalSugarOne: f64 = 0.9967885000000001;
let totalSugarPoundWithOunces: f64 = 1.68133;
let totalSugarPounds: f64 = 4.00012426;
let totalSugarPoundsWithOunces: f64 = 4.8038;
let imperialOrMetric: imperialOrMetric = imperialOrMetric::imperialGB;
assert_eq!(champagneCarbonationFormatting(totalSugarUnderOne, imperialOrMetric), "11.53 oz");
assert_eq!(champagneCarbonationFormatting(totalSugarOne, imperialOrMetric), "1 lb");
......@@ -43,12 +43,12 @@ fn champagneFormattingGBTest() {
#[test]
fn champagneFormattingUSTest() {
let totalSugarUnderOne = 0.6000000000000001;
let totalSugarOne = 1.0;
let totalSugarPoundWithOunces = 1.4000000000000001;
let totalSugarPounds = 4.0;
let totalSugarPoundsWithOunces = 4.6000000000000005;
let imperialOrMetric = imperialOrMetric::imperialUS;
let totalSugarUnderOne: f64 = 0.6000000000000001;
let totalSugarOne: f64 = 1.0;
let totalSugarPoundWithOunces: f64 = 1.4000000000000001;
let totalSugarPounds: f64 = 4.0;
let totalSugarPoundsWithOunces: f64 = 4.6000000000000005;
let imperialOrMetric: imperialOrMetric = imperialOrMetric::imperialUS;
assert_eq!(champagneCarbonationFormatting(totalSugarUnderOne, imperialOrMetric), "9.60 oz");
assert_eq!(champagneCarbonationFormatting(totalSugarOne, imperialOrMetric), "1 lb");
......@@ -59,10 +59,10 @@ fn champagneFormattingUSTest() {
#[test]
fn champagneFormattingMetricTest() {
let totalSugarOne = 0.9969558739249678;
let totalSugarWithDecimals = 1.437917125853319;
let totalSugarWithoutDecimals = 2.0011013334792023;
let imperialOrMetric = imperialOrMetric::metric;
let totalSugarOne: f64 = 0.9969558739249678;
let totalSugarWithDecimals: f64 = 1.437917125853319;
let totalSugarWithoutDecimals: f64 = 2.0011013334792023;
let imperialOrMetric: imperialOrMetric = imperialOrMetric::metric;
assert_eq!(champagneCarbonationFormatting(totalSugarOne, imperialOrMetric), "1 kilo");
assert_eq!(champagneCarbonationFormatting(totalSugarWithDecimals, imperialOrMetric), "1.44 kilos");
......
use gdk::RGBA;
use functions::commonFunctions::imperialOrMetric;
use functions::grainToABV::{grainABVData, grainToABVMaths, grainToABVFormatting, grainToABVColour};
#[test]
fn grainToABVMathsImperialGBTest() {
let mut allInputs = grainABVData {
let mut allInputs: grainABVData = grainABVData {
wortAmount: 20.0,
firstGrainAmount: 60.0,
firstGrainGravity: 1.037,
......@@ -95,7 +96,7 @@ fn grainToABVMathsImperialUSTest() {
#[test]
fn grainToABVMathsMetricTest() {
let mut allInputs = grainABVData {
let mut allInputs: grainABVData = grainABVData {
wortAmount: 75.0,
firstGrainAmount: 27.0,
firstGrainGravity: 1.037,
......@@ -141,7 +142,7 @@ fn grainToABVMathsMetricTest() {
#[test]
fn grainToABVFormattingTest() {
let mut allInputs = grainABVData {
let mut allInputsLegitimateABV: grainABVData = grainABVData {
wortAmount: 75.0,
firstGrainAmount: 27.0,
firstGrainGravity: 1.037,
......@@ -179,15 +180,103 @@ fn grainToABVFormattingTest() {
imperialOrMetric: imperialOrMetric::metric,
};
grainToABVFormatting(&mut allInputs);
grainToABVFormatting(&mut allInputsLegitimateABV);
assert_eq!(allInputsLegitimateABV.estimatedBrixFormatted, "15.52°Bx");
assert_eq!(allInputsLegitimateABV.abvFormatted, "7.71%");
let mut allInputsLowABV: grainABVData = grainABVData {
wortAmount: 75.0,
firstGrainAmount: 27.0,
firstGrainGravity: 1.037,
firstGrainLovibond: 1.8,
secondGrainAmount: 0.0,
secondGrainGravity: 1.0,
secondGrainLovibond:0.0 ,
thirdGrainAmount: 0.0,
thirdGrainGravity: 1.0,
thirdGrainLovibond: 0.0,
fourthGrainAmount: 0.0,
fourthGrainGravity: 1.0,
fourthGrainLovibond: 0.0,
fifthGrainAmount: 0.0,
fifthGrainGravity: 1.0,
fifthGrainLovibond: 0.0,
sixthGrainAmount: 0.0,
sixthGrainGravity: 1.0,
sixthGrainLovibond: 0.0,
seventhGrainAmount: 0.0,
seventhGrainGravity: 1.0,
seventhGrainLovibond: 0.0,
totalGrain1: 0.0,
totalGrain2: 0.0,
totalGrain3: 0.0,
totalGrain4: 0.0,
totalGrain5: 0.0,
totalGrain6: 0.0,
totalGrain7: 0.0,
glassSize: 9.8,
startingBrix: 15.520375373329689,
abvFinal: -3.0,
estimatedBrixFormatted: String::from("Enter legimate amounts"),
abvFormatted: String::from(""),
imperialOrMetric: imperialOrMetric::metric,
};
grainToABVFormatting(&mut allInputsLowABV);
assert_eq!(allInputsLowABV.estimatedBrixFormatted, "Enter legimate amounts");
assert_eq!(allInputsLowABV.abvFormatted, "");
let mut allInputsHighABV: grainABVData = grainABVData {
wortAmount: 75.0,
firstGrainAmount: 27.0,
firstGrainGravity: 1.037,
firstGrainLovibond: 1.8,
secondGrainAmount: 0.0,
secondGrainGravity: 1.0,
secondGrainLovibond:0.0 ,
thirdGrainAmount: 0.0,
thirdGrainGravity: 1.0,
thirdGrainLovibond: 0.0,
fourthGrainAmount: 0.0,
fourthGrainGravity: 1.0,
fourthGrainLovibond: 0.0,
fifthGrainAmount: 0.0,
fifthGrainGravity: 1.0,
fifthGrainLovibond: 0.0,
sixthGrainAmount: 0.0,
sixthGrainGravity: 1.0,
sixthGrainLovibond: 0.0,
seventhGrainAmount: 0.0,
seventhGrainGravity: 1.0,
seventhGrainLovibond: 0.0,
totalGrain1: 0.0,
totalGrain2: 0.0,
totalGrain3: 0.0,
totalGrain4: 0.0,
totalGrain5: 0.0,
totalGrain6: 0.0,
totalGrain7: 0.0,
glassSize: 9.8,
startingBrix: 15.520375373329689,
abvFinal: 333.333,
estimatedBrixFormatted: String::from("Enter legimate amounts"),
abvFormatted: String::from(""),
imperialOrMetric: imperialOrMetric::metric,
};
grainToABVFormatting(&mut allInputsHighABV);
assert_eq!(allInputs.estimatedBrixFormatted, "15.52°Bx");
assert_eq!(allInputs.abvFormatted, "7.71%");
assert_eq!(allInputsHighABV.estimatedBrixFormatted, "Enter legimate amounts");
assert_eq!(allInputsHighABV.abvFormatted, "");
}
#[test]
fn grainToABVColourTest() {
let allInputs = grainABVData {
let allInputs: grainABVData = grainABVData {
wortAmount: 75.0,
firstGrainAmount: 27.0,
firstGrainGravity: 1.037,
......@@ -225,7 +314,7 @@ fn grainToABVColourTest() {
imperialOrMetric: imperialOrMetric::metric,
};