import numpy as np
import pytest



def find_beamwidth(the_wavel,dish_size):
    """
       input:  the_wavel : wavelength (cm)
               dish_size : antenna dish diameter (m)
       output: beamwidth : beamwidth angle  (degrees)
    """
    #
    # Stull eq. 8.13
    #
    a = 71.6 #constant (degrees)
    the_wavel = the_wavel/100. #convert cm to m
    beamwidth = a*the_wavel/dish_size #beamwitdh in degrees
    return beamwidth



def find_range(delT):
    """
    Stull eq. 8.16
    input:  delT : the round-trip travel times (micro sec)
    output: radar range (km)
    """
    c = 3e8 #speed of light (m/s)
    delT = delT*(1.e-6) #convert microseconds to s
    radar_range = c*delT/2
    return radar_range*1.e-3  #kilometers


def test_a10():
    the_wavel=[20,20,10,10,10,5,5,5,5,3]  #wavelength (cm)
    dish_size=[8,10,10,5,3,7,5,2,3,1]   #dishsize (meters)
    input_vals=zip(the_wavel,dish_size)
    beamwidth=[find_beamwidth(wavel,dish_size) for wavel,dish_size in input_vals]
    answer = [1.790, 1.432, 0.716, 1.432, 2.387, 0.511, 0.716, 1.790, 1.193, 2.148]
    np.testing.assert_array_almost_equal(beamwidth,answer,decimal=3)
    return None


def test_a12():
    times=[2,5,10,25,50,75,100,150,200,300]  #microseconds
    the_range=[find_range(delT) for delT in times]
    answer=[0.3  , 0.7  , 1.5  , 3.7  , 7.5  , 11.2 , 15.0 , 22.5 , 30.0 , 45.0]
    np.testing.assert_array_almost_equal(the_range,answer,decimal=1)
    return None


if __name__ == "__main__":
    print('testing __file__: {}'.format(__file__))
    pytest.main([__file__, '-q'])
