From 39383fea8bd5bd58b063d9c9fbb44301e781fd80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Wed, 22 Jan 2014 22:47:11 +0100 Subject: fuzzy: Add FuzzyFloat (Closes #124). As suggested by @savingschampion --- factory/fuzzy.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'factory') diff --git a/factory/fuzzy.py b/factory/fuzzy.py index 2ea544a..94599b7 100644 --- a/factory/fuzzy.py +++ b/factory/fuzzy.py @@ -141,6 +141,23 @@ class FuzzyDecimal(BaseFuzzyAttribute): return base.quantize(decimal.Decimal(10) ** -self.precision) +class FuzzyFloat(BaseFuzzyAttribute): + """Random float within a given range.""" + + def __init__(self, low, high=None, **kwargs): + if high is None: + high = low + low = 0 + + self.low = low + self.high = high + + super(FuzzyFloat, self).__init__(**kwargs) + + def fuzz(self): + return random.uniform(self.low, self.high) + + class FuzzyDate(BaseFuzzyAttribute): """Random date within a given date range.""" -- cgit v1.2.3