adding the can_also_be_decimal function
2 files changed, 34 insertions(+), 0 deletions(-)

M showcolours.py
M test_showcolours.py
M showcolours.py +17 -0
@@ 170,6 170,23 @@ def can_only_be_decimal(number):
         return False
 
 
+def can_also_be_decimal(number):
+    """Could the number string represent a decimal in the range 0-1?
+
+    For decimal fractions we obviously return true. If the number is 0 or 1, it
+    might also represent a value in the 0-255 range, but that's fine.
+    """
+    if type(number) is not str:
+        raise TypeError
+    try:
+        if 0 <= float(number) <= 1:
+            return True
+        else:
+            return False
+    except ValueError:
+        return False
+
+
 def interpret_colours(numbers, hint):
     if hint == 'rgb':
         return colours_from_rgb255_numbers(numbers)

          
M test_showcolours.py +17 -0
@@ 153,6 153,23 @@ class Test_can_only_be_decimal():
     def test_big_numbers_arent_decimal(self):
         assert not any([sc.can_only_be_decimal(num) for num in ('1.1', '8.0')])
 
+class Test_can_also_be_decimal():
+
+    def test_numbers_between_0_and_1_can_be_decimal(self):
+        assert all([
+            sc.can_also_be_decimal(num)
+            for num in ('0.1', '0.2', '0.999', '0.001')
+        ])
+
+    def test_0_and_1_can_be_decimal(self):
+        assert all([sc.can_also_be_decimal(num) for num in ('0', '1')])
+
+    def test_negative_decimals_cant_be_decimal(self):
+        assert not any([sc.can_also_be_decimal(num) for num in ('-.1', '-1')])
+
+    def test_big_numbers_cant_be_decimal(self):
+        assert not any([sc.can_also_be_decimal(num) for num in ('1.1', '8.0')])
+
 
 class Test_colours_from_rgb1_numbers():
     """Test the colours_from_rgb1_numbers function"""