diff --git a/camera.py b/camera.py index be0f482..9137d0c 100644 --- a/camera.py +++ b/camera.py @@ -2,13 +2,21 @@ class exposureCalc: def __init__(self, sunrise, sunset): self.sunrise=sunrise self.sunset=sunset + self.span_midnight=self.sunset < self.sunrise def get_exposure(self, time): - if(time >=self.sunrise and time <=self.sunset): + + if not self.span_midnight and (time >=self.sunrise and time <=self.sunset): return 'auto' - return 'night' + elif self.span_midnight and (time >= self.sunrise or time <= self.sunset): + return 'auto' + else: + return 'night' #One hour either side of sunrise/set def take_shot(self, time): - if(time >=self.sunrise and time <=self.sunset): + if not self.span_midnight and (time >=self.sunrise and time <=self.sunset): + return True + elif self.span_midnight and (time >= self.sunrise or time <= self.sunset): return True - return False + else: + return False diff --git a/test_camera.py b/test_camera.py index 731e2fa..44256e0 100644 --- a/test_camera.py +++ b/test_camera.py @@ -20,6 +20,18 @@ def test_exposureCalc_outsideLowerBounds(self): exposureCalc1=exposureCalc(700,1700) self.assertEqual(exposureCalc1.get_exposure(600), "night") + def test_exposureCalc_spanMidNight_middleBounds_beforeMidnight(self): + exposureCalc1=exposureCalc(1700, 700) + self.assertEqual(exposureCalc1.get_exposure(1900), 'auto') + + def test_exposureCalc_spanMidNight_middleBounds_afterMidnight(self): + exposureCalc1=exposureCalc(1700, 700) + self.assertEqual(exposureCalc1.get_exposure(500), 'auto') + + def test_exposureCalc_spanMidNight_outsideBounds(self): + exposureCalc1=exposureCalc(1700, 700) + self.assertEqual(exposureCalc1.get_exposure(1000), 'night') + def test_take_shot(self): exp=exposureCalc(700,1700) self.assertEqual(exp.take_shot(1700), True)