Skip to content

Commit

Permalink
Coverage back up to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
Myoldmopar committed Jul 30, 2024
1 parent 9d29608 commit 17cefbb
Showing 1 changed file with 62 additions and 3 deletions.
65 changes: 62 additions & 3 deletions solar_angles/test/test_solar.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def test_construction(self):
with self.assertRaises(ValueError):
Angular(degrees=180, radians=2 * 3.14)

def test_string(self):
a = Angular(degrees=1)
self.assertIsInstance(str(a), str)


class TestDayOfYear(TestCase):

Expand Down Expand Up @@ -107,6 +111,10 @@ def test_example_5_6_1(self):
standard_meridian = Angular(degrees=90)
self.assertAlmostEqual(local_civil_time(dt, dst_on, longitude, standard_meridian), 9.67, delta=0.01)

def test_bad_arguments(self):
with self.assertRaises(ValueError):
local_civil_time(datetime.now(), True, Angular(), Angular())


class TestLocalSolarTime(TestCase):

Expand All @@ -118,6 +126,10 @@ def test_example_5_6_1(self):
standard_meridian = Angular(degrees=90)
self.assertAlmostEqual(local_solar_time(dt, dst_on, longitude, standard_meridian), 9.43, delta=0.01)

def test_bad_arguments(self):
with self.assertRaises(ValueError):
local_solar_time(datetime.now(), True, Angular(), Angular())


class TestHourAngle(TestCase):

Expand All @@ -142,6 +154,10 @@ def test_solar_noon(self):
standard_meridian = Angular(degrees=90)
self.assertAlmostEqual(hour_angle(dt, dst_on, longitude, standard_meridian).degrees, 0, delta=0.1)

def test_bad_arguments(self):
with self.assertRaises(ValueError):
hour_angle(datetime.now(), True, Angular(), Angular())


class TestAltitudeAngle(TestCase):

Expand All @@ -152,8 +168,13 @@ def test_example_5_6_2(self):
longitude = Angular(degrees=85)
standard_meridian = Angular(degrees=90)
latitude = Angular(degrees=40)
self.assertAlmostEqual(altitude_angle(dt, dst_on, longitude, standard_meridian, latitude).degrees, 49.7,
delta=0.1)
self.assertAlmostEqual(
altitude_angle(dt, dst_on, longitude, standard_meridian, latitude).degrees, 49.7, delta=0.1
)

def test_bad_arguments(self):
with self.assertRaises(ValueError):
altitude_angle(datetime.now(), True, Angular(), Angular(), Angular())


class TestAzimuthAngle(TestCase):
Expand All @@ -170,6 +191,16 @@ def test_example_5_6_2(self):
self.assertAlmostEqual(azimuth_angle(dt, dst_on, longitude, standard_meridian, latitude).degrees,
expected_azimuth_from_north, delta=0.1)

# how about an afternoon one?
def test_afternoon(self):
dt = datetime(2001, 7, 21, 16, 00, 00)
dst_on = True
longitude = Angular(degrees=85)
standard_meridian = Angular(degrees=90)
latitude = Angular(degrees=40)
# I just made up this example to ensure the code path works, so I'm not validating it against a value
self.assertTrue(azimuth_angle(dt, dst_on, longitude, standard_meridian, latitude).valued)

# test one with the sun down to get a null-ish response
def test_sun_is_down(self):
dt = datetime(2001, 3, 21, 22, 00, 00)
Expand All @@ -179,10 +210,14 @@ def test_sun_is_down(self):
latitude = Angular(degrees=40)
self.assertFalse(azimuth_angle(dt, dst_on, longitude, standard_meridian, latitude).valued)

def test_bad_arguments(self):
with self.assertRaises(ValueError):
azimuth_angle(datetime.now(), True, Angular(), Angular(), Angular())


class TestWallAzimuthAngle(TestCase):

# test east facing wall where the solar_angles azimuth is known from a prior unit test
# test south? facing wall where the solar_angles azimuth is known from a prior unit test
def test_gamma_south_facing(self):
dt = datetime(2001, 7, 21, 10, 00, 00)
dst_on = True
Expand All @@ -198,6 +233,16 @@ def test_gamma_south_facing(self):
delta=0.1
)

# test north facing wall where the azimuth should be behind the wall
def test_gamma_north_facing(self):
dt = datetime(2001, 7, 21, 10, 00, 00)
dst_on = True
longitude = Angular(degrees=85)
standard_meridian = Angular(degrees=90)
latitude = Angular(degrees=40)
wall_normal = Angular(degrees=270)
self.assertFalse(wall_azimuth_angle(dt, dst_on, longitude, standard_meridian, latitude, wall_normal).valued)

# test one with the sun down to get a null-ish response
def test_sun_is_down(self):
dt = datetime(2001, 3, 21, 22, 00, 00)
Expand All @@ -208,6 +253,10 @@ def test_sun_is_down(self):
wall_normal = Angular(degrees=90)
self.assertFalse(wall_azimuth_angle(dt, dst_on, longitude, standard_meridian, latitude, wall_normal).valued)

def test_bad_arguments(self):
with self.assertRaises(ValueError):
wall_azimuth_angle(datetime.now(), True, Angular(), Angular(), Angular(), Angular())


class TestSolarAngleOfIncidence(TestCase):

Expand Down Expand Up @@ -252,6 +301,10 @@ def test_sun_is_down(self):
solar_angle_of_incidence(dt, dst_on, longitude, standard_meridian, latitude, wall_normal).valued
)

def test_bad_arguments(self):
with self.assertRaises(ValueError):
solar_angle_of_incidence(datetime.now(), True, Angular(), Angular(), Angular(), Angular())


class TestRadiationOnSurface(TestCase):

Expand All @@ -267,3 +320,9 @@ def test_direct_radiation_on_surface_south_facing(self):
self.assertAlmostEqual(
direct_radiation_on_surface(dt, dst_on, longitude, standard_meridian, latitude, wall_normal, insolation),
insolation * cos(theta), delta=0.1)

def test_bad_arguments(self):
with self.assertRaises(ValueError):
direct_radiation_on_surface(
datetime.now(), True, Angular(), Angular(), Angular(), Angular(), 1000
)

0 comments on commit 17cefbb

Please sign in to comment.