U
    ª€lj\t  ã                   @  s  d Z ddlm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dœdd„Zdddœ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.
é    )Úannotations)Úverify)Úbase)ÚAnglesÚ
Directions)ÚIPositioningBeacon)ÚTestCasec                   @  sH   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„ZdS )Ú
AngleTestsz@
    Tests for the L{twisted.positioning.base.Angle} class.
    ÚNone©Úreturnc                 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   úF/tmp/pip-unpacked-wheel-aghyhbke/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.
        ©Z	angleTypez<Variation (unknown value)>N)r   r   r   Z	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-   s    zAngleTests.test_bogusTypeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r	      s
   r	   c                   @  sF  e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„Zddœdd„Zddœdd„Z	ddœdd„Z
dddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœd d!„Zddœd"d#„Zddœd$d%„Zddœd&d'„Zddœd(d)„Zddœd*d+„Zddœd,d-„Zddœd.d/„Zddœd0d1„Zd2S )3ÚHeadingTestszB
    Tests for the L{twisted.positioning.base.Heading} class.
    r
   r   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_simple9   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_headingWithoutVariationReprE   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   ç      $À©ZvariationValuez2<Heading ({0} degrees, <Variation ({1} degrees)>)>N)r   r%   Ú
fromFloatsr   r   Úformat)r   Zangler)   r.   ZreprTemplater   r   r   Útest_headingWithVariationReprN   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_valueEqualityX   s    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^   s    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_zeroHeadingEdgeCased   s    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_zeroHeading180DegreeVariationEdgeCasej   s    z7HeadingTests.test_zeroHeading180DegreeVariationEdgeCaser'   ©Úkwr   c                 K  s   | j ttjjf|Ž 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%   r3   )r   r?   r   r   r   Ú_badValueTestq   s    zHeadingTests._badValueTestc                 C  s   | j dd� dS )zO
        Headings can not be instantiated with a value of 360 degrees.
        g     €v@©Z
angleValueN©r@   r   r   r   r   Útest_badAngleValueEdgeCasey   s    z'HeadingTests.test_badAngleValueEdgeCasec                 C  s   | j dd� dS )zT
        Headings can not be instantiated with a variation of -180 degrees.
        ç     €fÀr2   NrB   r   r   r   r   Útest_badVariationEdgeCase   s    z&HeadingTests.test_badVariationEdgeCasec                 C  s   | j dd� dS )z>
        Negative heading values raise C{ValueError}.
        r1   rA   NrB   r   r   r   r   Útest_negativeHeading…   s    z!HeadingTests.test_negativeHeadingc                 C  s   | j dd� dS )zK
        Heading values greater than C{360.0} raise C{ValueError}.
        g      w@rA   NrB   r   r   r   r   Útest_headingTooLarge‹   s    z!HeadingTests.test_headingTooLargec                 C  s   | j dd� dS )zK
        Variation values less than C{-180.0} raise C{ValueError}.
        g     ÀgÀr2   NrB   r   r   r   r   Útest_variationTooNegative‘   s    z&HeadingTests.test_variationTooNegativec                 C  s   | j dd� dS )zM
        Variation values greater than C{180.0} raise C{ValueError}.
        g     Àg@r2   NrB   r   r   r   r   Útest_variationTooPositive—   s    z&HeadingTests.test_variationTooPositivec                 C  s,   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%   r3   r   r*   r   r   ÚHEADINGr+   r   r   r   Útest_correctedHeading�   s    z"HeadingTests.test_correctedHeadingc                 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 across the 360 degree
        boundary.
        ç     pv@g       Àr2   r   NrJ   r+   r   r   r   Útest_correctedHeadingOverflow¤   s    z*HeadingTests.test_correctedHeadingOverflowc                 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 360
        degree boundary.
        rM   ç      ð¿r2   ç        NrJ   r+   r   r   r   Ú%test_correctedHeadingOverflowEdgeCase­   s    z2HeadingTests.test_correctedHeadingOverflowEdgeCasec                 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 under the 0 degree
        boundary.
        r   r7   r2   rM   NrJ   r+   r   r   r   Útest_correctedHeadingUnderflow¶   s    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   rP   NrJ   r+   r   r   r   Ú&test_correctedHeadingUnderflowEdgeCase¿   s    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   é   éÿÿÿÿrO   N)r   r%   r3   Ú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%   r3   r   r   rV   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   rT   N)	r   r%   r3   r(   r)   r&   r   r   rV   r+   r   r   r   Útest_setUnknownVariationSigná   s    z)HeadingTests.test_setUnknownVariationSignN)r    r!   r"   r#   r-   r0   r5   r6   r9   r;   r=   r@   rC   rE   rF   rG   rH   rI   rL   rN   rQ   rR   rS   rW   rZ   r[   r   r   r   r   r$   4   s.   	
				
r$   c                   @  s\  e Zd Zddœdd„Zddœdd„Zddœdd„Zddœd	d
„Zddœdd„Zddœdd„Zddœdd„Z	ddœdd„Z
ddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd„Zddœdd „Zddœd!d"„Zddœd#d$„Zddœd%d&„Zddœd'd(„Zddœd)d*„Zddœd+d,„Zddœd-d.„Zddœd/d0„Zddœd1d2„Zd3S )4ÚCoordinateTestsr
   r   c                 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ì   s    
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.
        r]   z<Angle of unknown type (ú
 degrees)>N)r   r^   r   r   ©r   r`   r/   r   r   r   Ú	test_repró   s    
zCoordinateTests.test_reprc                 C  s.   t  dtj¡}dd› d�}|  t|ƒ|¡ dS )zU
        Positive latitudes have a repr that specifies their type and value.
        r]   ú<Latitude (rb   N©r   r^   r   ÚLATITUDEr   r   rc   r   r   r   Útest_positiveLatitudeü   s    z%CoordinateTests.test_positiveLatitudec                 C  s.   t  dtj¡}dd› d�}|  t|ƒ|¡ dS )zU
        Negative latitudes have a repr that specifies their type and value.
        ç      IÀre   rb   Nrf   rc   r   r   r   Útest_negativeLatitude  s    z%CoordinateTests.test_negativeLatitudec                 C  s.   t  dtj¡}dd› d�}|  t|ƒ|¡ dS )zV
        Positive longitudes have a repr that specifies their type and value.
        ç      I@ú<Longitude (rb   N©r   r^   r   Ú	LONGITUDEr   r   ©r   Z	longituder/   r   r   r   Útest_positiveLongitude  s    z&CoordinateTests.test_positiveLongitudec                 C  s.   t  dtj¡}dd› d�}|  t|ƒ|¡ dS )zV
        Negative longitudes have a repr that specifies their type and value.
        ri   rl   rb   Nrm   ro   r   r   r   Útest_negativeLongitude  s    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   r^   r   r   r   r   Útest_bogusCoordinateType  s    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}.
        rr   N)r   r   r   r^   r   rK   r   r   r   r   Útest_angleTypeNotCoordinate"  s    z+CoordinateTests.test_angleTypeNotCoordinatec                 C  s"   ddœdd„}|   |ƒ |ƒ ¡ dS )zE
        Coordinates with the same value and type are equal.
        úbase.Coordinater   c                   S  s   t  dtj¡S )Nr   ©r   r^   r   rn   r   r   r   r   ÚmakeCoordinate.  s    z5CoordinateTests.test_equality.<locals>.makeCoordinateN)r   )r   rw   r   r   r   Útest_equality)  s    zCoordinateTests.test_equalityc                 C  s$   t  d¡}t  d¡}|  ||¡ dS )zA
        Coordinates with different values aren't equal.
        r   rO   N)r   r^   r8   ©r   Zc1Úc2r   r   r   Útest_differentAnglesInequality3  s    

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   r^   r   rg   rn   r8   ry   r   r   r   Útest_differentTypesInequality;  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.
        rk   rT   rU   ri   N)r   r^   r   rg   rV   r   r&   ©r   Úcr   r   r   Ú	test_signC  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.
        rk   rX   r   rY   N)	r   r^   r   rg   r   r   rV   r   r&   )r   Úvaluer~   r   r   r   Útest_badVariationSignN  s    z%CoordinateTests.test_badVariationSignc                 C  s"   t  dtj¡}|  |jtj¡ dS )zD
        Positive latitudes are in the northern hemisphere.
        r   N)r   r^   r   rg   r   Ú
hemispherer   ZNORTHr_   r   r   r   Útest_northernHemisphere_  s    z'CoordinateTests.test_northernHemispherec                 C  s"   t  dtj¡}|  |jtj¡ dS )zD
        Positive longitudes are in the eastern hemisphere.
        r   N)r   r^   r   rn   r   r‚   r   ZEASTr_   r   r   r   Útest_easternHemispheref  s    z&CoordinateTests.test_easternHemispherec                 C  s"   t  dtj¡}|  |jtj¡ dS )zD
        Negative latitudes are in the southern hemisphere.
        rO   N)r   r^   r   rg   r   r‚   r   ZSOUTHr_   r   r   r   Útest_southernHemispherem  s    z'CoordinateTests.test_southernHemispherec                 C  s"   t  dtj¡}|  |jtj¡ dS )zD
        Negative longitudes are in the western hemisphere.
        rO   N)r   r^   r   rn   r   r‚   r   ZWESTr_   r   r   r   Útest_westernHemispheret  s    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   ©r`   r   r   Ú<lambda>�  ó    z4CoordinateTests.test_badHemisphere.<locals>.<lambda>)r   r^   r   r   r   r   rˆ   r   Útest_badHemisphere{  s    z"CoordinateTests.test_badHemispherec                 C  s    |   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}.
        rr   g     €V@N©r   r   Ú_makeLatituder   r   r   r   Útest_latitudeTooLargeƒ  s    z%CoordinateTests.test_latitudeTooLargec                 C  s    |   ttd¡ |   ttd¡ dS )zr
        Creating a latitude with a value less than or equal to -90 degrees
        raises C{ValueError}.
        g     ÀbÀg     €VÀNrŒ   r   r   r   r   Útest_latitudeTooSmall‹  s    z%CoordinateTests.test_latitudeTooSmallc                 C  s    |   ttd¡ |   ttd¡ dS )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“  s    z&CoordinateTests.test_longitudeTooLargec                 C  s    |   ttd¡ |   ttd¡ dS )zt
        Creating a longitude with a value less than or equal to -180 degrees
        raises C{ValueError}.
        g     @oÀrD   Nr�   r   r   r   r   Útest_longitudeTooSmall›  s    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@)rY   é   r   g%�•CI@)rY   é   é.   N)r   r^   r   rg   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   r^   r(   r—   r}   r   r   r   Ú(test_unknownAngleInDegreesMinutesSeconds­  s    z8CoordinateTests.test_unknownAngleInDegreesMinutesSecondsN)r    r!   r"   ra   rd   rh   rj   rp   rq   rs   rt   rx   r{   r|   r   r�   rƒ   r„   r…   r†   r‹   rŽ   r�   r’   r“   r˜   r™   r   r   r   r   r\   ë   s0   	

r\   r'   ru   )r€   r   c                 C  s   t  | tj¡S )z7
    Builds and returns a latitude of given value.
    )r   r^   r   rg   ©r€   r   r   r   r�   ¶  s    r�   c                 C  s   t  | tj¡S )z8
    Builds and returns a longitude of given value.
    rv   rš   r   r   r   r‘   ½  s    r‘   c                   @  sH   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„ZdS )ÚAltitudeTestszC
    Tests for the L{twisted.positioning.base.Altitude} class.
    r
   r   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'   ZinMetersZinFeetZMETERS_PER_FOOT©r   Zaltituder   r   r   Ú
test_valueÉ  s    
zAltitudeTests.test_valuec                 C  s   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   rd   Ó  s    
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   ZfirstAltitudeZsecondAltituder   r   r   rx   Ú  s    

zAltitudeTests.test_equalityc                 C  s$   t  d¡}t  d¡}|  ||¡ dS )zF
        Altitudes with different values don't compare equal.
        r   rO   N)r   rœ   r8   rŸ   r   r   r   Útest_inequalityâ  s    

zAltitudeTests.test_inequalityN)r    r!   r"   r#   rž   rd   rx   r    r   r   r   r   r›   Ä  s
   
r›   c                   @  sV   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„Zddœdd„ZdS )Ú
SpeedTestsz@
    Tests for the L{twisted.positioning.base.Speed} class.
    r
   r   c                 C  s,   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.
        rk   N)r   ÚSpeedr   ÚinMetersPerSecondr'   ©r   Úspeedr   r   r   rž   ð  s    
zSpeedTests.test_valuec                 C  s   t  d¡}|  t|ƒd¡ dS )zC
        Speeds report their type and value in their repr.
        rk   z<Speed (50.0 m/s)>N)r   r£   r   r   r¥   r   r   r   rd   ù  s    
zSpeedTests.test_reprc                 C  s   |   ttjd¡ dS )zA
        Creating a negative speed raises C{ValueError}.
        rO   N)r   r   r   r£   r   r   r   r   Útest_negativeSpeeds   s    zSpeedTests.test_negativeSpeedsc                 C  s"   t  d¡}|  dt j |j¡ dS )zC
        A speed can be converted into its value in knots.
        r   rT   N)r   r£   r   ÚMPS_PER_KNOTÚinKnotsr¥   r   r   r   Útest_inKnots  s    
zSpeedTests.test_inKnotsc                 C  s   |   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  s    zSpeedTests.test_asFloatN)	r    r!   r"   r#   rž   rd   r§   rª   r«   r   r   r   r   r¡   ë  s   	r¡   c                   @  sV   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„Zddœdd„ZdS )Ú
ClimbTestsz6
    Tests for L{twisted.positioning.base.Climb}.
    r
   r   c                 C  s,   t  d¡}|  |jd¡ |  t|ƒd¡ dS )r¢   ç      E@N©r   ÚClimbr   r¤   r'   ©r   Zclimbr   r   r   r-     s    
zClimbTests.test_simplec                 C  s   t  d¡}|  t|ƒd¡ dS )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   rd   "  s    
zClimbTests.test_reprc                 C  s,   t  d¡}|  |jd¡ |  t|ƒd¡ dS )z‰
        Climbs can have negative values, and still report that value
        in meters per second and when converted to floats.
        g      EÀNr®   r°   r   r   r   Útest_negativeClimbs)  s    
zClimbTests.test_negativeClimbsc                 C  s"   t  d¡}|  dt j |j¡ dS )zC
        A climb can be converted into its value in knots.
        r   rT   N)r   r¯   r   r¨   r©   r°   r   r   r   Útest_speedInKnots2  s    
zClimbTests.test_speedInKnotsc                 C  s   |   dtt d¡ƒ¡ dS )z;
        A climb can be converted into a C{float}.
        r   N)r   r'   r   r¯   r   r   r   r   r«   9  s    zClimbTests.test_asFloatN)	r    r!   r"   r#   r-   rd   r±   r²   r«   r   r   r   r   r¬     s   		r¬   c                   @  sÄ   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zddœd
d„Zddœdd„Zddœdd„Z	ddœdd„Z
ddœdd„ZdZddddddœdd„Zddœdd„Zddœdd„Zddœdd„Zd S )!ÚPositionErrorTestsz>
    Tests for L{twisted.positioning.base.PositionError}.
    r
   r   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   ZpositionErrorr   r   r   Útest_allUnsetE  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_allUnsetWithInvariantO  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_withoutInvariantY  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`  s    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_invalidWithoutInvarianth  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_invalidWithInvariantr  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  sF   t jdddd�}|j}dddœ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»   úbase.PositionErrorr
   )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)>rÇ   zfloat | None)rÅ   r¶   r·   r¸   r   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.
        ©r7   r   é   ç      à?)r¶   r·   N©r   rµ   rË   )r   r¶   r·   r¸   rÅ   r   r   r   Útest_positionAndHorizontalSet²  s    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»  s    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Ä  s    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                   @  sF   e Zd ZdZddœdd„ZddddœZddœd	d
„Zddœdd„ZdS )ÚBeaconInformationTestszB
    Tests for L{twisted.positioning.base.BeaconInformation}.
    r
   r   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_minimalrT   r   )ÚazimuthÚ	elevationÚsignalToNoiseRatioc                   s|   dddœ‡ 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.
        r'   zbase.Satelliter>   c                    s    t ˆ jƒ}| | ¡ tjf |ŽS r‡   )ÚdictÚsatelliteKwargsÚupdater   Ú	Satellite)r?   Úkwargsr   r   r   Ú_buildSatelliteè  s    

z;BeaconInformationTests.test_simple.<locals>._buildSatelliterT   é
   )Ú
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á   ZbeaconsÚprnr×   r   r   r   r-   â  s    
þz"BeaconInformationTests.test_simplec                 C  s†   t  ¡ }tddƒD ]:}t jf 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.
        rT   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>])>N)r   rÔ   ræ   rß   rÝ   rè   rç   rÖ   r   rÕ   r   )r   r×   ré   Z	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                   @  s,   e Zd ZdZddœdd„Zddœdd„ZdS )	ÚPositioningBeaconTestsz.
    Tests for L{base.PositioningBeacon}.
    r
   r   c                 C  s,   t  tj¡}|  |¡ t t t d¡¡ dS )zX
        Tests that L{base.PositioningBeacon} implements L{IPositioningBeacon}.
        rT   N)r   ZimplementedByr   ÚPositioningBeaconÚ
assertTruer   ZverifyObject)r   Z
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   rd   2  s    z PositioningBeaconTests.test_reprN)r    r!   r"   r#   rï   rd   r   r   r   r   rì   %  s   rì   c                   @  s,   e Zd ZdZddœdd„Zddœdd„ZdS )	ÚSatelliteTestsz:
    Tests for L{twisted.positioning.base.Satellite}.
    r
   r   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.
        rT   z:<Satellite (1), azimuth: None, elevation: None, snr: None>N)	r   rß   r   rã   r(   rÙ   rÚ   rÛ   r   ©r   Úsr   r   r   rØ   >  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.
        rT   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-   N  s       ÿ ÿzSatelliteTests.test_simpleN)r    r!   r"   r#   rØ   r-   r   r   r   r   rñ   9  s   rñ   N)r#   Ú
__future__r   Zzope.interfacer   Ztwisted.positioningr   Ztwisted.positioning.baser   r   Z twisted.positioning.ipositioningr   Ztwisted.trial.unittestr   r	   r$   r\   r�   r‘   r›   r¡   r¬   r³   rÓ   rì   rñ   r   r   r   r   Ú<module>   s*   $ 8 L'), W