def test (): '''Mainly call some functions.''' for i in range(0, 100): wl_nm = 1000.0 * random.random() rayleigh.rayleigh_scattering (wl_nm) rayleigh.rayleigh_scattering_spectrum() illum = illuminants.get_illuminant_D65() rayleigh.rayleigh_illuminated_spectrum (illum) rayleigh.rayleigh_illuminated_color (illum) print('test_rayleigh.test() passed.') # didnt exception
def test (): '''Mainly call some functions.''' for i in xrange (0, 100): wl_nm = 1000.0 * random.random() rayleigh.rayleigh_scattering (wl_nm) rayleigh.rayleigh_scattering_spectrum() illum = illuminants.get_illuminant_D65() rayleigh.rayleigh_illuminated_spectrum (illum) rayleigh.rayleigh_illuminated_color (illum) print 'test_rayleigh.test() passed.' # didnt exception
def test_wavelength_4(self, verbose=False): ''' Test that scattering scales as 1/wl^4. ''' for i in range(20): # Two random wavelengths, avoiding zero. wl_1 = 1.0 + 999.0 * random.random() wl_2 = 1.0 + 999.0 * random.random() # Scattering. sc_1 = rayleigh.rayleigh_scattering(wl_1) sc_2 = rayleigh.rayleigh_scattering(wl_2) # Ratios, avoiding pow() for more independence from implementation. r_sc = sc_1 / sc_2 r_wl = wl_2 / wl_1 r4_wl = r_wl * r_wl * r_wl * r_wl # Check. actual = r_sc / r4_wl expect = 1.0 error = math.fabs(actual - expect) tolerance = 1.0e-12 self.assertLessEqual(error, tolerance) msg = 'Wavelength: %g, %g Scattering: %g, %g Ratio of Powers: %.8f' % ( wl_1, wl_2, sc_1, sc_2, actual) if verbose: print(msg)
def test_wavelength_4(self, verbose=False): ''' Test that scattering scales as 1/wl^4. ''' for i in range(20): # Two random wavelengths, avoiding zero. wl_1 = 1.0 + 999.0 * random.random() wl_2 = 1.0 + 999.0 * random.random() # Scattering. sc_1 = rayleigh.rayleigh_scattering(wl_1) sc_2 = rayleigh.rayleigh_scattering(wl_2) # Ratios, avoiding pow() for more independence from implementation. r_sc = sc_1 / sc_2 r_wl = wl_2 / wl_1 r4_wl = r_wl * r_wl * r_wl * r_wl # Check. actual = r_sc / r4_wl expect = 1.0 error = math.fabs(actual - expect) tolerance = 1.0e-12 self.assertLessEqual(error, tolerance) msg = 'Wavelength: %g, %g Scattering: %g, %g Ratio of Powers: %.8f' % ( wl_1, wl_2, sc_1, sc_2, actual) if verbose: print (msg)