o
    bp                     @   s   d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ G dd deZG d	d
 d
eZG dd deZdd Zdd ZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdS ) z(
Test cases for positioning primitives.
    )verify)base)Angles
Directions)IPositioningBeacon)TestCasec                   @   0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )
AngleTestsz@
    Tests for the L{twisted.positioning.base.Angle} class.
    c                 C   s   t  }| dt| dS )zd
        The repr of an empty angle says that is of unknown type and unknown
        value.
        z'<Angle of unknown type (unknown value)>Nr   AngleassertEqualreprselfa r   D/usr/lib/python3/dist-packages/twisted/positioning/test/test_base.py
test_empty   s   zAngleTests.test_emptyc                 C   s"   t jtjd}| dt| dS )zf
        The repr of an empty variation says that it is a variation of unknown
        value.
        	angleTypez<Variation (unknown value)>N)r   r   r   	VARIATIONr   r   r   r   r   r   test_variation   s   zAngleTests.test_variationc                 C   s   t d}| dt| dS )zz
        The repr of an angle of unknown type but a given value displays that
        type and value in its repr.
              ?z%<Angle of unknown type (1.0 degrees)>Nr
   r   r   r   r   test_unknownType#   s   
zAngleTests.test_unknownTypec                 C   s   | j ttjdd dS )zS
        Trying to create an angle with a bogus type raises C{ValueError}.
        BOGUSr   N)assertRaises
ValueErrorr   r   r   r   r   r   test_bogusType+      zAngleTests.test_bogusTypeN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r	      s    r	   c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.S )/HeadingTestszB
    Tests for the L{twisted.positioning.base.Heading} class.
    c                 C   sD   t d}| |jd | t|d | |j | |j dS )z
        Tests that a simple heading has a value in decimal degrees, which is
        also its value when converted to a float. Its variation, and by
        consequence its corrected heading, is L{None}.
        r   N)r   Headingr   inDecimalDegreesfloatassertIsNone	variationcorrectedHeadingr   hr   r   r   test_simple7   s
   
zHeadingTests.test_simplec                 C   s"   t d}d}| t|| dS )zt
        A repr of a heading with no variation reports its value and that the
        variation is unknown.
        r   z*<Heading (1.0 degrees, unknown variation)>N)r   r%   r   r   )r   headingexpectedReprr   r   r    test_headingWithoutVariationReprC   s   
z-HeadingTests.test_headingWithoutVariationReprc                 C   s8   d\}}t jj||d}d}| t|||| dS )zu
        A repr of a heading with known variation reports its value and the
        value of that variation.
        )r         $variationValuez2<Heading ({0} degrees, <Variation ({1} degrees)>)>N)r   r%   
fromFloatsr   r   format)r   angler)   r.   reprTemplater   r   r   test_headingWithVariationReprL   s   z*HeadingTests.test_headingWithVariationReprc                 C   s   |  tdtd dS )z>
        Headings with the same values compare equal.
        r   N)r   r   r%   r   r   r   r   test_valueEqualityV      zHeadingTests.test_valueEqualityc                 C   s   |  tdtd dS )zA
        Headings with different values compare unequal.
        r          @N)assertNotEqualr   r%   r   r   r   r   test_valueInequality\   r:   z!HeadingTests.test_valueInequalityc                 C   s   t d dS )zR
        Headings can be instantiated with a value of 0 and no variation.
        r   Nr   r%   r   r   r   r   test_zeroHeadingEdgeCaseb      z%HeadingTests.test_zeroHeadingEdgeCasec                 C   s   t dd dS )zh
        Headings can be instantiated with a value of 0 and a variation of 180
        degrees.
        r      Nr>   r   r   r   r   *test_zeroHeading180DegreeVariationEdgeCaseh   s   z7HeadingTests.test_zeroHeading180DegreeVariationEdgeCasec                 K   s   | j ttjjfi | dS )z
        Helper function for verifying that bad values raise C{ValueError}.

        @param kw: The keyword arguments passed to L{base.Heading.fromFloats}.
        N)r   r   r   r%   r4   )r   kwr   r   r   _badValueTesto   s   zHeadingTests._badValueTestc                 C      | j dd dS )zO
        Headings can not be instantiated with a value of 360 degrees.
        g     v@
angleValueNrD   r   r   r   r   test_badAngleValueEdgeCasew      z'HeadingTests.test_badAngleValueEdgeCasec                 C   rE   )zT
        Headings can not be instantiated with a variation of -180 degrees.
             fr2   NrH   r   r   r   r   test_badVariationEdgeCase}   rJ   z&HeadingTests.test_badVariationEdgeCasec                 C   rE   )z>
        Negative heading values raise C{ValueError}.
        r1   rF   NrH   r   r   r   r   test_negativeHeading   rJ   z!HeadingTests.test_negativeHeadingc                 C   rE   )zK
        Heading values greater than C{360.0} raise C{ValueError}.
        g      w@rF   NrH   r   r   r   r   test_headingTooLarge   rJ   z!HeadingTests.test_headingTooLargec                 C   rE   )zK
        Variation values less than C{-180.0} raise C{ValueError}.
        g     gr2   NrH   r   r   r   r   test_variationTooNegative   rJ   z&HeadingTests.test_variationTooNegativec                 C   rE   )zM
        Variation values greater than C{180.0} raise C{ValueError}.
        g     g@r2   NrH   r   r   r   r   test_variationTooPositive   rJ   z&HeadingTests.test_variationTooPositivec                 C   ,   t jjddd}| |jt dtj dS )zQ
        A heading with a value and a variation has a corrected heading.
        r   r1   r2   g      &@Nr   r%   r4   r   r*   r   r   HEADINGr+   r   r   r   test_correctedHeading   s   z"HeadingTests.test_correctedHeadingc                 C   rQ   )z
        A heading with a value and a variation has the appropriate corrected
        heading value, even when the variation puts it across the 360 degree
        boundary.
             pv@g       r2   r   NrR   r+   r   r   r   test_correctedHeadingOverflow      z*HeadingTests.test_correctedHeadingOverflowc                 C   rQ   )z
        A heading with a value and a variation has the appropriate corrected
        heading value, even when the variation puts it exactly at the 360
        degree boundary.
        rU         r2           NrR   r+   r   r   r   %test_correctedHeadingOverflowEdgeCase   rW   z2HeadingTests.test_correctedHeadingOverflowEdgeCasec                 C   rQ   )z
        A heading with a value and a variation has the appropriate corrected
        heading value, even when the variation puts it under the 0 degree
        boundary.
        r   r;   r2   rU   NrR   r+   r   r   r   test_correctedHeadingUnderflow   rW   z+HeadingTests.test_correctedHeadingUnderflowc                 C   s,   t jjddd}| |jt dtj dS )z
        A heading with a value and a variation has the appropriate corrected
        heading value, even when the variation puts it exactly at the 0
        degree boundary.
        r   r2   rY   NrR   r+   r   r   r   &test_correctedHeadingUnderflowEdgeCase   rW   z3HeadingTests.test_correctedHeadingUnderflowEdgeCasec                 C   sH   t jjddd}|d | |jjd |d | |jjd dS )zK
        Setting the sign of a heading changes the variation sign.
        r   r2      rX   N)r   r%   r4   setSignr   r)   r&   r+   r   r   r   test_setVariationSign   s
   

z"HeadingTests.test_setVariationSignc                 C   st   t jjddd}| t|jd | |jjd | t|jd | |jjd | t|jd | |jjd dS )z
        Setting the sign of a heading to values that aren't C{-1} or C{1}
        raises C{ValueError} and does not affect the heading.
        r   r2   r   2   N)	r   r%   r4   r   r   r_   r   r)   r&   r+   r   r   r   test_setBadVariationSign   s   z%HeadingTests.test_setBadVariationSignc                 C   s.   t jd}| |jj | t|jd dS )zd
        Setting the sign on a heading with unknown variation raises
        C{ValueError}.
        r   r]   N)	r   r%   r4   r(   r)   r&   r   r   r_   r+   r   r   r   test_setUnknownVariationSign   s   z)HeadingTests.test_setUnknownVariationSignN)r    r!   r"   r#   r-   r0   r8   r9   r=   r?   rB   rD   rI   rL   rM   rN   rO   rP   rT   rV   rZ   r[   r\   r`   rc   rd   r   r   r   r   r$   2   s0    	
				
r$   c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1S )2CoordinateTestsc                 C   s   t d}| t|d dS )z9
        Coordinates can be converted to floats.
              $@N)r   
Coordinater   r'   r   
coordinater   r   r   
test_float      
zCoordinateTests.test_floatc                 C   s*   t d}dd d}| t|| dS )zn
        Coordinates that aren't explicitly latitudes or longitudes have an
        appropriate repr.
        rf   z<Angle of unknown type (
 degrees)>N)r   rg   r   r   r   ri   r/   r   r   r   	test_repr   s   
zCoordinateTests.test_reprc                 C   .   t dtj}dd d}| t|| dS )zU
        Positive latitudes have a repr that specifies their type and value.
        rf   <Latitude (rl   Nr   rg   r   LATITUDEr   r   rm   r   r   r   test_positiveLatitude      z%CoordinateTests.test_positiveLatitudec                 C   ro   )zU
        Negative latitudes have a repr that specifies their type and value.
              Irp   rl   Nrq   rm   r   r   r   test_negativeLatitude  rt   z%CoordinateTests.test_negativeLatitudec                 C   ro   )zV
        Positive longitudes have a repr that specifies their type and value.
              I@<Longitude (rl   Nr   rg   r   	LONGITUDEr   r   r   	longituder/   r   r   r   test_positiveLongitude
  rt   z&CoordinateTests.test_positiveLongitudec                 C   ro   )zV
        Negative longitudes have a repr that specifies their type and value.
        ru   rx   rl   Nry   r{   r   r   r   test_negativeLongitude  rt   z&CoordinateTests.test_negativeLongitudec                 C   s   |  ttjdd dS )zM
        Creating coordinates with bogus types rasies C{ValueError}.
             b@r   N)r   r   r   rg   r   r   r   r   test_bogusCoordinateType  r   z(CoordinateTests.test_bogusCoordinateTypec                 C   s   |  ttjdtj dS )zm
        Creating coordinates with angle types that aren't coordinates raises
        C{ValueError}.
        r   N)r   r   r   rg   r   rS   r   r   r   r   test_angleTypeNotCoordinate   s   z+CoordinateTests.test_angleTypeNotCoordinatec                 C   s   dd }|  | |  dS )zE
        Coordinates with the same value and type are equal.
        c                   S   s   t dtjS )Nr   r   rg   r   rz   r   r   r   r   makeCoordinate,  s   z5CoordinateTests.test_equality.<locals>.makeCoordinateN)r   )r   r   r   r   r   test_equality'  s   zCoordinateTests.test_equalityc                 C   $   t d}t d}| || dS )zA
        Coordinates with different values aren't equal.
        r   rX   N)r   rg   r<   r   c1c2r   r   r   test_differentAnglesInequality1     

z.CoordinateTests.test_differentAnglesInequalityc                 C   s,   t dtj}t dtj}| || dS )zT
        Coordinates with the same values but different types aren't equal.
        r   N)r   rg   r   rr   rz   r<   r   r   r   r   test_differentTypesInequality9  s   z-CoordinateTests.test_differentTypesInequalityc                 C   sB   t dtj}|d | |jd |d | |jd dS )zh
        Setting the sign on a coordinate sets the sign of the value of the
        coordinate.
        rw   r]   r^   ru   N)r   rg   r   rr   r_   r   r&   r   cr   r   r   	test_signA  s
   

zCoordinateTests.test_signc                 C   sp   d}t |tj}| t|jd | |jd | t|jd | |jd | t|jd | |jd dS )z
        Setting a bogus sign value (not -1 or 1) on a coordinate raises
        C{ValueError} and doesn't affect the coordinate.
        rw   ra   r   rb   N)	r   rg   r   rr   r   r   r_   r   r&   )r   valuer   r   r   r   test_badVariationSignL  s   z%CoordinateTests.test_badVariationSignc                 C   "   t dtj}| |jtj dS )zD
        Positive latitudes are in the northern hemisphere.
        r   N)r   rg   r   rr   r   
hemispherer   NORTHrh   r   r   r   test_northernHemisphere]     z'CoordinateTests.test_northernHemispherec                 C   r   )zD
        Positive longitudes are in the eastern hemisphere.
        r   N)r   rg   r   rz   r   r   r   EASTrh   r   r   r   test_easternHemisphered  r   z&CoordinateTests.test_easternHemispherec                 C   r   )zD
        Negative latitudes are in the southern hemisphere.
        rX   N)r   rg   r   rr   r   r   r   SOUTHrh   r   r   r   test_southernHemispherek  r   z'CoordinateTests.test_southernHemispherec                 C   r   )zD
        Negative longitudes are in the western hemisphere.
        rX   N)r   rg   r   rz   r   r   r   WESTrh   r   r   r   test_westernHemispherer  r   z&CoordinateTests.test_westernHemispherec                    s$   t dd | t fdd dS )zo
        Accessing the hemisphere for a coordinate that can't compute it
        raises C{ValueError}.
        r   Nc                      s    j S )N)r   r   ri   r   r   <lambda>  s    z4CoordinateTests.test_badHemisphere.<locals>.<lambda>)r   rg   r   r   r   r   r   r   test_badHemispherey  s   z"CoordinateTests.test_badHemispherec                 C       |  ttd |  ttd dS )zt
        Creating a latitude with a value greater than or equal to 90 degrees
        raises C{ValueError}.
        r   g     V@Nr   r   _makeLatituder   r   r   r   test_latitudeTooLarge     z%CoordinateTests.test_latitudeTooLargec                 C   r   )zr
        Creating a latitude with a value less than or equal to -90 degrees
        raises C{ValueError}.
        g     bg     VNr   r   r   r   r   test_latitudeTooSmall  r   z%CoordinateTests.test_latitudeTooSmallc                 C   r   )zv
        Creating a longitude with a value greater than or equal to 180 degrees
        raises C{ValueError}.
        g     @o@g     f@Nr   r   _makeLongituder   r   r   r   test_longitudeTooLarge  r   z&CoordinateTests.test_longitudeTooLargec                 C   r   )zt
        Creating a longitude with a value less than or equal to -180 degrees
        raises C{ValueError}.
        g     @orK   Nr   r   r   r   r   test_longitudeTooSmall  r   z&CoordinateTests.test_longitudeTooSmallc                 C   s<   t dtj}| |jd t dtj}| |jd dS )zQ
        Coordinate values can be accessed in degrees, minutes, seconds.
        g     @I@)rb      r   g%CI@)rb      .   N)r   rg   r   rr   r   inDegreesMinutesSecondsr   r   r   r   test_inDegreesMinutesSeconds  s   z,CoordinateTests.test_inDegreesMinutesSecondsc                 C   s   t dd}| |j dS )zz
        If the vaue of a coordinate is L{None}, its values in degrees,
        minutes, seconds is also L{None}.
        N)r   rg   r(   r   r   r   r   r   (test_unknownAngleInDegreesMinutesSeconds  s   z8CoordinateTests.test_unknownAngleInDegreesMinutesSecondsN)r    r!   r"   rj   rn   rs   rv   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   re      s2    	

re   c                 C      t | tjS )z7
    Builds and returns a latitude of given value.
    )r   rg   r   rr   r   r   r   r   r     r@   r   c                 C   r   )z8
    Builds and returns a longitude of given value.
    r   r   r   r   r   r     r@   r   c                   @   r   )AltitudeTestszC
    Tests for the L{twisted.positioning.base.Altitude} class.
    c                 C   s@   t d}| t|d | |jd | |jdt j  dS )z
        Altitudes can be instantiated and reports the correct value in
        meters and feet, as well as when converted to float.
        r   N)r   Altituder   r'   inMetersinFeetMETERS_PER_FOOTr   altituder   r   r   
test_value  s   
zAltitudeTests.test_valuec                 C      t d}| t|d dS )zF
        Altitudes report their type and value in their repr.
        r   z<Altitude (1.0 m)>N)r   r   r   r   r   r   r   r   rn     rk   zAltitudeTests.test_reprc                 C   s$   t d}t d}| || dS )z<
        Altitudes with equal values compare equal.
        r   N)r   r   r   r   firstAltitudesecondAltituder   r   r   r     r   zAltitudeTests.test_equalityc                 C   r   )zF
        Altitudes with different values don't compare equal.
        r   rX   N)r   r   r<   r   r   r   r   test_inequality  r   zAltitudeTests.test_inequalityN)r    r!   r"   r#   r   rn   r   r   r   r   r   r   r     s    
r   c                   @   8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )
SpeedTestsz@
    Tests for the L{twisted.positioning.base.Speed} class.
    c                 C   ,   t d}| |jd | t|d dS )
        Speeds can be instantiated, and report their value in meters
        per second, and can be converted to floats.
        rw   N)r   Speedr   inMetersPerSecondr'   r   speedr   r   r   r        
zSpeedTests.test_valuec                 C   r   )zC
        Speeds report their type and value in their repr.
        rw   z<Speed (50.0 m/s)>N)r   r   r   r   r   r   r   r   rn     rk   zSpeedTests.test_reprc                 C   s   |  ttjd dS )zA
        Creating a negative speed raises C{ValueError}.
        rX   N)r   r   r   r   r   r   r   r   test_negativeSpeeds  s   zSpeedTests.test_negativeSpeedsc                 C   "   t d}| dt j |j dS )zC
        A speed can be converted into its value in knots.
        r   r]   N)r   r   r   MPS_PER_KNOTinKnotsr   r   r   r   test_inKnots     
zSpeedTests.test_inKnotsc                 C      |  dttd dS )z;
        A speed can be converted into a C{float}.
        r   N)r   r'   r   r   r   r   r   r   test_asFloat     zSpeedTests.test_asFloatN)	r    r!   r"   r#   r   rn   r   r   r   r   r   r   r   r     s    	r   c                   @   r   )
ClimbTestsz6
    Tests for L{twisted.positioning.base.Climb}.
    c                 C   r   )r         E@Nr   Climbr   r   r'   r   climbr   r   r   r-     r   zClimbTests.test_simplec                 C   r   )zC
        Climbs report their type and value in their repr.
        r   z<Climb (42.0 m/s)>N)r   r   r   r   r   r   r   r   rn      rk   zClimbTests.test_reprc                 C   r   )z
        Climbs can have negative values, and still report that value
        in meters per second and when converted to floats.
        g      ENr   r   r   r   r   test_negativeClimbs'  r   zClimbTests.test_negativeClimbsc                 C   r   )zC
        A climb can be converted into its value in knots.
        r   r]   N)r   r   r   r   r   r   r   r   r   test_speedInKnots0  r   zClimbTests.test_speedInKnotsc                 C   r   )z;
        A climb can be converted into a C{float}.
        r   N)r   r'   r   r   r   r   r   r   r   7  r   zClimbTests.test_asFloatN)	r    r!   r"   r#   r-   rn   r   r   r   r   r   r   r   r     s    		r   c                   @   st   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdZdd Zdd Zdd Zdd ZdS )PositionErrorTestsz>
    Tests for L{twisted.positioning.base.PositionError}.
    c                 C   s0   t  }| |j | |j | |j dS )z~
        In an empty L{base.PositionError} with no invariant testing, all
        dilutions of positions are L{None}.
        Nr   PositionErrorr(   pdophdopvdopr   positionErrorr   r   r   test_allUnsetC  s   z PositionErrorTests.test_allUnsetc                 C   s4   t jdd}| |j | |j | |j dS )z{
        In an empty L{base.PositionError} with invariant testing, all
        dilutions of positions are L{None}.
        T)testInvariantNr   r   r   r   r   test_allUnsetWithInvariantM  s   z-PositionErrorTests.test_allUnsetWithInvariantc                 C   s   t jdd}| |jd dS )zN
        L{base.PositionError}s can be instantiated with just a HDOP.
        r   )r   Nr   r   r   r   r   r   r   r   test_withoutInvariantW  s   z(PositionErrorTests.test_withoutInvariantc                 C   s    t jddd}| |jd dS )zv
        Creating a simple L{base.PositionError} with just a HDOP while
        checking the invariant works.
        r   T)r   r   Nr   r   r   r   r   test_withInvariant^  r   z%PositionErrorTests.test_withInvariantc                 C   s>   t jdddd}| |jd | |jd | |jd dS )z
        Creating a L{base.PositionError} with values set to an impossible
        combination works if the invariant is not checked.
        r   )r   r   r   N)r   r   r   r   r   r   )r   errorr   r   r   test_invalidWithoutInvariantf  s   z/PositionErrorTests.test_invalidWithoutInvariantc                 C   s   | j ttjddddd dS )z
        Creating a L{base.PositionError} with values set to an impossible
        combination raises C{ValueError} if the invariant is being tested.
        r   T)r   r   r   r   N)r   r   r   r   r   r   r   r   test_invalidWithInvariantp  s   
z,PositionErrorTests.test_invalidWithInvariantc                 C   s&   t jddd}d|_| |jd dS )z}
        You can set the PDOP value to value inconsisted with HDOP and VDOP
        when not checking the invariant.
        r   r   r         Y@N)r   r   r   r   )r   per   r   r   test_setDOPWithoutInvariant~  s   z.PositionErrorTests.test_setDOPWithoutInvariantc                 C   s>   t jdddd}|j}dd }| t|| | |j| dS )z
        Attempting to set the PDOP value to value inconsisted with HDOP and
        VDOP when checking the invariant raises C{ValueError}.
        r   T)r   r   r   c                 S   s
   d| _ d S )Nr   )r   )r   r   r   r   setPDOP  s   
z<PositionErrorTests.test_setDOPWithInvariant.<locals>.setPDOPN)r   r   r   r   r   r   )r   r   r   r   r   r   r   test_setDOPWithInvariant  s
   z+PositionErrorTests.test_setDOPWithInvariantz.<PositionError (pdop: %s, hdop: %s, vdop: %s)>c                 C   sJ   |  |j| |  |j| |  |j| |  t|| j|||f  dS )a  
        Tests the DOP values in a position error, and the repr of that
        position error.

        @param pe: The position error under test.
        @type pe: C{PositionError}
        @param pdop: The expected position dilution of precision.
        @type pdop: C{float} or L{None}
        @param hdop: The expected horizontal dilution of precision.
        @type hdop: C{float} or L{None}
        @param vdop: The expected vertical dilution of precision.
        @type vdop: C{float} or L{None}
        N)r   r   r   r   r   REPR_TEMPLATE)r   r   r   r   r   r   r   r   _testDOP  s    zPositionErrorTests._testDOPc                 C   s>   d\}}|d |d  d }t j||d}| |||| dS )zF
        The VDOP is correctly determined from PDOP and HDOP.
        r;   r            ?)r   r   Nr   r   r   )r   r   r   r   r   r   r   r   test_positionAndHorizontalSet     z0PositionErrorTests.test_positionAndHorizontalSetc                 C   s>   d\}}|d |d  d }t j||d}| |||| dS )zF
        The HDOP is correctly determined from PDOP and VDOP.
        r   r   r   )r   r   Nr   )r   r   r   r   r   r   r   r   test_positionAndVerticalSet  r   z.PositionErrorTests.test_positionAndVerticalSetc                 C   s>   d\}}|d |d  d }t j||d}| |||| dS )zF
        The PDOP is correctly determined from HDOP and VDOP.
        )r   r   r   r   r   Nr   )r   r   r   r   r   r   r   r   test_horizontalAndVerticalSet  r   z0PositionErrorTests.test_horizontalAndVerticalSetN)r    r!   r"   r#   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   >  s    


			r   c                   @   s4   e Zd ZdZdd ZddddZdd Zd	d
 ZdS )BeaconInformationTestszB
    Tests for L{twisted.positioning.base.BeaconInformation}.
    c                 C   s2   t  }| t|jd d}| t|| dS )z
        For an empty beacon information object, the number of used
        beacons is zero, the number of seen beacons is zero, and the
        repr of the object reflects that.
        r   z><BeaconInformation (used beacons (0): [], unused beacons: [])>N)r   BeaconInformationr   lenusedBeaconsr   )r   bir/   r   r   r   test_minimal  s
   z#BeaconInformationTests.test_minimalr]   r   )azimuth	elevationsignalToNoiseRatioc                    st    fdd}t  }tddD ]
}|||d qt|} t|jd  t|jd  t	|d d	S )
zw
        Tests a beacon information with a bunch of satellites, none of
        which used in computing a fix.
        c                     s$   t  j}||  tjdi |S )Nr   )dictsatelliteKwargsupdater   	Satellite)rC   kwargsr   r   r   _buildSatellite  s   

z;BeaconInformationTests.test_simple.<locals>._buildSatelliter]   
   )
identifier	   r   a  <BeaconInformation (used beacons (0): [], unused beacons: [<Satellite (1), azimuth: 1, elevation: 1, snr: 1.0>, <Satellite (2), azimuth: 1, elevation: 1, snr: 1.0>, <Satellite (3), azimuth: 1, elevation: 1, snr: 1.0>, <Satellite (4), azimuth: 1, elevation: 1, snr: 1.0>, <Satellite (5), azimuth: 1, elevation: 1, snr: 1.0>, <Satellite (6), azimuth: 1, elevation: 1, snr: 1.0>, <Satellite (7), azimuth: 1, elevation: 1, snr: 1.0>, <Satellite (8), azimuth: 1, elevation: 1, snr: 1.0>, <Satellite (9), azimuth: 1, elevation: 1, snr: 1.0>])>N)
setrangeaddr   r   r   r   seenBeaconsr   r   )r   r  beaconsprnr   r   r   r   r-     s   
z"BeaconInformationTests.test_simplec                 C   s   t  }tddD ]}t jd	d|i| j}|j| |d r&|j| q	| t	|jd | t	|jd | t
|d dS )
zv
        Tests a beacon information with a bunch of satellites, some of
        them used in computing a fix.
        r]   r  r	  r   r
     a  <BeaconInformation (used beacons (5): [<Satellite (1), azimuth: 1, elevation: 1, snr: 1.0>, <Satellite (3), azimuth: 1, elevation: 1, snr: 1.0>, <Satellite (5), azimuth: 1, elevation: 1, snr: 1.0>, <Satellite (7), azimuth: 1, elevation: 1, snr: 1.0>, <Satellite (9), azimuth: 1, elevation: 1, snr: 1.0>], unused beacons: [<Satellite (2), azimuth: 1, elevation: 1, snr: 1.0>, <Satellite (4), azimuth: 1, elevation: 1, snr: 1.0>, <Satellite (6), azimuth: 1, elevation: 1, snr: 1.0>, <Satellite (8), azimuth: 1, elevation: 1, snr: 1.0>])>Nr   )r   r   r  r  r  r  r  r   r   r   r   )r   r   r  	satelliter   r   r   test_someSatellitesUsed  s   z.BeaconInformationTests.test_someSatellitesUsedN)r    r!   r"   r#   r   r  r-   r  r   r   r   r   r     s    #r   c                   @       e Zd ZdZdd Zdd ZdS )PositioningBeaconTestsz.
    Tests for L{base.PositioningBeacon}.
    c                 C   s,   t tj}| | tt td dS )zX
        Tests that L{base.PositioningBeacon} implements L{IPositioningBeacon}.
        r]   N)r   implementedByr   PositioningBeacon
assertTruer   verifyObject)r   
implementsr   r   r   test_interface"  s   
z%PositioningBeaconTests.test_interfacec                 C   s   |  ttdd dS )z9
        Tests the repr of a positioning beacon.
        Az<Beacon (A)>N)r   r   r   r  r   r   r   r   rn   *  r   z PositioningBeaconTests.test_reprN)r    r!   r"   r#   r  rn   r   r   r   r   r    s    r  c                   @   r  )SatelliteTestsz:
    Tests for L{twisted.positioning.base.Satellite}.
    c                 C   sP   t d}| |jd | |j | |j | |j | t|d dS )z
        Tests a minimal satellite that only has a known PRN.

        Tests that the azimuth, elevation and signal to noise ratios
        are L{None} and verifies the repr.
        r]   z:<Satellite (1), azimuth: None, elevation: None, snr: None>N)	r   r  r   r	  r(   r   r   r  r   r   sr   r   r   r   6  s   
zSatelliteTests.test_minimalc                 C   s^   t jddddd}| |jd | |jd | |jd | |jd | t|d dS )z
        Tests a minimal satellite that only has a known PRN.

        Tests that the azimuth, elevation and signal to noise ratios
        are correct and verifies the repr.
        r]   g     p@g      >@g      9@)r	  r   r   r  z;<Satellite (1), azimuth: 270.0, elevation: 30.0, snr: 25.0>N)r   r  r   r	  r   r   r  r   r  r   r   r   r-   F  s   zSatelliteTests.test_simpleN)r    r!   r"   r#   r   r-   r   r   r   r   r  1  s    r  N)r#   zope.interfacer   twisted.positioningr   twisted.positioning.baser   r    twisted.positioning.ipositioningr   twisted.trial.unittestr   r	   r$   re   r   r   r   r   r   r   r   r  r  r   r   r   r   <module>   s*   $ 8 L'), 	W