From ec30480a7121956b0ccde353180d1656fce866af Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 11 Apr 2022 14:05:57 +0300 Subject: Implement MVP for valid_value functions * Implement the minimum viable functions for the average and standard error `valid_value` functions. --- quality_control/average.py | 7 ++++++- quality_control/standard_error.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'quality_control') diff --git a/quality_control/average.py b/quality_control/average.py index 6ed0da7..1a7bf5f 100644 --- a/quality_control/average.py +++ b/quality_control/average.py @@ -4,4 +4,9 @@ import re from .errors import InvalidValue def valid_value(val): - return None + if re.search("^[0-9]+\.[0-9]{3}$", val): + return float(val) + raise InvalidValue( + f"Invalid value '{val}'.\n" + "Expected string representing a number with exactly three decimal " + "places.") diff --git a/quality_control/standard_error.py b/quality_control/standard_error.py index 9a91d1b..ae1e378 100644 --- a/quality_control/standard_error.py +++ b/quality_control/standard_error.py @@ -4,4 +4,9 @@ import re from .errors import InvalidValue def valid_value(val): - return None + if re.search("^[0-9]+\.[0-9]{6,}$", val): + return float(val) + raise InvalidValue( + f"Invalid value '{val}'.\n" + "Expected string representing a number with at least six decimal " + "places.") -- cgit v1.2.3