88
99import unittest
1010
11- from celerity .light import get_light_travel_distance
11+ from celerity .light import get_light_travel_distance , get_photon_frequency
1212
1313# **************************************************************************************
1414
15+
1516class TestLightTravelDistance (unittest .TestCase ):
1617 def test_light_travel_distance (self ):
1718 """
@@ -33,4 +34,36 @@ def test_light_travel_distance(self):
3334 expected_distance = 149896229.0 # Speed of light in m/s * 0.5 seconds
3435 self .assertAlmostEqual (get_light_travel_distance (time ), expected_distance )
3536
36- # **************************************************************************************
37+
38+ # **************************************************************************************
39+
40+
41+ class TestPhotonFrequency (unittest .TestCase ):
42+ def test_photon_frequency (self ) -> None :
43+ """
44+ Test the photon frequency calculation.
45+ """
46+ # Calculate the frequency using the wavelength of 500 nm:
47+ frequency = get_photon_frequency (500e-9 )
48+
49+ # Expected approximate frequency in Hz for 500 nm wavelength:
50+ expected_frequency = 6e14
51+
52+ self .assertAlmostEqual (
53+ frequency , expected_frequency , delta = 1e-3 * expected_frequency
54+ )
55+
56+ def test_negative_photon_frequency (self ) -> None :
57+ """
58+ Test the photon frequency calculation with a negative wavelength.
59+ """
60+ with self .assertRaises (ValueError ):
61+ get_photon_frequency (- 500e-9 )
62+
63+
64+ # **************************************************************************************
65+
66+ if __name__ == "__main__" :
67+ unittest .main ()
68+
69+ # **************************************************************************************
0 commit comments