Function goose::util::get_hatch_rate

source ·
pub fn get_hatch_rate(hatch_rate: Option<String>) -> f32
Expand description

Convert optional string to f32, otherwise defaulting to 1.0.

Example

use goose::util;

// No decimal returns a proper float.
assert_eq!(util::get_hatch_rate(Some("1".to_string())), 1.0);

// Leading decimal returns a proper float.
assert_eq!(util::get_hatch_rate(Some(".1".to_string())), 0.1);

// Valid float string returns a proper float.
assert_eq!(util::get_hatch_rate(Some("1.1".to_string())), 1.1);

// Invalid number with too many decimals returns the defaut of 1.0.
assert_eq!(util::get_hatch_rate(Some("1.1.1".to_string())), 1.0);

// No number returns the defaut of 1.0.
assert_eq!(util::get_hatch_rate(None), 1.0);