
    tf\t                    ~   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	e          Z G d
 de          Z G d de          Zd#dZd#dZ G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d  d!e          Zd"S )$z(
Test cases for positioning primitives.
    )annotations)verify)base)Angles
Directions)IPositioningBeacon)TestCasec                  2    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.
    returnNonec                r    t          j                    }|                     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as     a/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/positioning/test/test_base.py
test_emptyzAngleTests.test_empty   s2    
 JLLBDGGLLLLL    c                    t          j        t          j                  }|                     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   s     r   test_variationzAngleTests.test_variation   s<    
 J!12226Q@@@@@r   c                t    t          j        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   s     r   test_unknownTypezAngleTests.test_unknownType%   s4    
 JsOO@$q''JJJJJr   c                T    |                      t          t          j        d           dS )zS
        Trying to create an angle with a bogus type raises C{ValueError}.
        BOGUSr   N)assertRaises
ValueErrorr   r   r   s    r   test_bogusTypezAngleTests.test_bogusType-   s'     	*djGDDDDDr   Nr   r   )__name__
__module____qualname____doc__r   r   r    r&    r   r   r   r      s         M M M MA A A AK K K KE E E E E Er   r   c                      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.
    r   r   c                   t          j        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   hs     r   test_simplezHeadingTests.test_simple9   s{     L+S111q3'''!+&&&!,-----r   c                x    t          j        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   r0   r   r   )r   headingexpectedReprs      r    test_headingWithoutVariationReprz-HeadingTests.test_headingWithoutVariationReprE   s:    
 ,s##Cg55555r   c                    d\  }}t           j                            ||          }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   r0   
fromFloatsr   r   format)r   angler4   r:   reprTemplates        r   test_headingWithVariationReprz*HeadingTests.test_headingWithVariationReprN   s_    
 &y,))%	)JJKg(;(;E9(M(MNNNNNr   c                z    |                      t          j        d          t          j        d                     dS )z>
        Headings with the same values compare equal.
        r   N)r   r   r0   r%   s    r   test_valueEqualityzHeadingTests.test_valueEqualityX   s4     	c**DL,=,=>>>>>r   c                z    |                      t          j        d          t          j        d                     dS )zA
        Headings with different values compare unequal.
        r          @N)assertNotEqualr   r0   r%   s    r   test_valueInequalityz!HeadingTests.test_valueInequality^   s4     	DL--t|C/@/@AAAAAr   c                .    t          j        d           dS )zR
        Headings can be instantiated with a value of 0 and no variation.
        r   Nr   r0   r%   s    r   test_zeroHeadingEdgeCasez%HeadingTests.test_zeroHeadingEdgeCased   s     	Qr   c                0    t          j        dd           dS )zh
        Headings can be instantiated with a value of 0 and a variation of 180
        degrees.
        r      NrM   r%   s    r   *test_zeroHeading180DegreeVariationEdgeCasez7HeadingTests.test_zeroHeading180DegreeVariationEdgeCasej   s    
 	Qr   kwr2   c                L     | 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   r0   rA   )r   rR   s     r   _badValueTestzHeadingTests._badValueTestq   s,     	*dl&=DDDDDDDr   c                2    |                      d           dS )zO
        Headings can not be instantiated with a value of 360 degrees.
        g     v@
angleValueNrT   r%   s    r   test_badAngleValueEdgeCasez'HeadingTests.test_badAngleValueEdgeCasey   !     	e,,,,,r   c                2    |                      d           dS )zT
        Headings can not be instantiated with a variation of -180 degrees.
             fr?   NrX   r%   s    r   test_badVariationEdgeCasez&HeadingTests.test_badVariationEdgeCase   !     	&11111r   c                2    |                      d           dS )z>
        Negative heading values raise C{ValueError}.
        r>   rV   NrX   r%   s    r   test_negativeHeadingz!HeadingTests.test_negativeHeading   rZ   r   c                2    |                      d           dS )zK
        Heading values greater than C{360.0} raise C{ValueError}.
        g      w@rV   NrX   r%   s    r   test_headingTooLargez!HeadingTests.test_headingTooLarge   rZ   r   c                2    |                      d           dS )zK
        Variation values less than C{-180.0} raise C{ValueError}.
        g     gr?   NrX   r%   s    r   test_variationTooNegativez&HeadingTests.test_variationTooNegative   r^   r   c                2    |                      d           dS )zM
        Variation values greater than C{180.0} raise C{ValueError}.
        g     g@r?   NrX   r%   s    r   test_variationTooPositivez&HeadingTests.test_variationTooPositive   s!     	%00000r   c                    t           j                            dd          }|                     |j        t          j        dt          j                             dS )zQ
        A heading with a value and a variation has a corrected heading.
        r   r>   r?   g      &@Nr   r0   rA   r   r5   r   r   HEADINGr6   s     r   test_correctedHeadingz"HeadingTests.test_correctedHeading   sK     L##C#>>+TZfn-M-MNNNNNr   c                    t           j                            dd          }|                     |j        t          j        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       r?   r   Nrh   r6   s     r   test_correctedHeadingOverflowz*HeadingTests.test_correctedHeadingOverflow   K     L##E$#??+TZV^-L-LMMMMMr   c                    t           j                            dd          }|                     |j        t          j        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.
        rl         r?           Nrh   r6   s     r   %test_correctedHeadingOverflowEdgeCasez2HeadingTests.test_correctedHeadingOverflowEdgeCase   rn   r   c                    t           j                            dd          }|                     |j        t          j        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   rI   r?   rl   Nrh   r6   s     r   test_correctedHeadingUnderflowz+HeadingTests.test_correctedHeadingUnderflow   sK     L##C#<<+TZv~-N-NOOOOOr   c                    t           j                            dd          }|                     |j        t          j        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   r?   rq   Nrh   r6   s     r   &test_correctedHeadingUnderflowEdgeCasez3HeadingTests.test_correctedHeadingUnderflowEdgeCase   sK     L##C#<<+TZV^-L-LMMMMMr   c                   t           j                            dd          }|                    d           |                     |j        j        d           |                    d           |                     |j        j        d           dS )zK
        Setting the sign of a heading changes the variation sign.
        r   r?      rp   N)r   r0   rA   setSignr   r4   r1   r6   s     r   test_setVariationSignz"HeadingTests.test_setVariationSign   sx     L##C#<<			!5s;;;			"5t<<<<<r   c                   t           j                            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   r?   r   2   N)	r   r0   rA   r#   r$   rz   r   r4   r1   r6   s     r   test_setBadVariationSignz%HeadingTests.test_setBadVariationSign   s    
 L##C#<<*ai5555s;;;*ai3335s;;;*ai4445s;;;;;r   c                    t           j                            d          }|                     |j        j                   |                     t          |j        d           dS )zd
        Setting the sign on a heading with unknown variation raises
        C{ValueError}.
        r   rx   N)	r   r0   rA   r3   r4   r1   r#   r$   rz   r6   s     r   test_setUnknownVariationSignz)HeadingTests.test_setUnknownVariationSign   sR    
 L##C((!+6777*ai33333r   Nr'   )rR   r2   r   r   )r(   r)   r*   r+   r8   r<   rE   rG   rK   rN   rQ   rT   rY   r]   r`   rb   rd   rf   rj   rm   rr   rt   rv   r{   r   r   r,   r   r   r.   r.   4   s        
. 
. 
. 
.6 6 6 6O O O O? ? ? ?B B B B      E E E E- - - -2 2 2 2- - - -- - - -2 2 2 21 1 1 1O O O ON N N NN N N NP P P PN N N N= = = =< < < <4 4 4 4 4 4r   r.   c                      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dZdS )CoordinateTestsr   r   c                t    t          j        d          }|                     t          |          d           dS )z9
        Coordinates can be converted to floats.
              $@N)r   
Coordinater   r2   r   
coordinates     r   
test_floatzCoordinateTests.test_float   s7     _T**
z**D11111r   c                    t          j        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;   s      r   	test_reprzCoordinateTests.test_repr   sG    
 _T**
B$BBBj))<88888r   c                    t          j        dt          j                  }dd d}|                     t          |          |           dS )zU
        Positive latitudes have a repr that specifies their type and value.
        r   <Latitude (r   Nr   r   r   LATITUDEr   r   r   s      r   test_positiveLatitudez%CoordinateTests.test_positiveLatitude   sK     _T6?;;
5T555j))<88888r   c                    t          j        dt          j                  }dd d}|                     t          |          |           dS )zU
        Negative latitudes have a repr that specifies their type and value.
              Ir   r   Nr   r   s      r   test_negativeLatitudez%CoordinateTests.test_negativeLatitude  sK     _UFO<<
6U666j))<88888r   c                    t          j        dt          j                  }dd d}|                     t          |          |           dS )zV
        Positive longitudes have a repr that specifies their type and value.
              I@<Longitude (r   Nr   r   r   	LONGITUDEr   r   r   	longituder;   s      r   test_positiveLongitudez&CoordinateTests.test_positiveLongitude  sJ     OD&*:;;	6d666i,77777r   c                    t          j        dt          j                  }dd d}|                     t          |          |           dS )zV
        Negative longitudes have a repr that specifies their type and value.
        r   r   r   Nr   r   s      r   test_negativeLongitudez&CoordinateTests.test_negativeLongitude  sJ     OE6+;<<	7e777i,77777r   c                T    |                      t          t          j        dd           dS )zM
        Creating coordinates with bogus types rasies C{ValueError}.
             b@r"   N)r#   r$   r   r   r%   s    r   test_bogusCoordinateTypez(CoordinateTests.test_bogusCoordinateType  s&     	*dougFFFFFr   c                h    |                      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   r   r   ri   r%   s    r   test_angleTypeNotCoordinatez+CoordinateTests.test_angleTypeNotCoordinate"  s(    
 	*doufnMMMMMr   c                Z    dd}|                       |             |                       dS )zE
        Coordinates with the same value and type are equal.
        r   base.Coordinatec                 @    t          j        dt          j                  S )Nr   r   r   r   r   r,   r   r   makeCoordinatez5CoordinateTests.test_equality.<locals>.makeCoordinate.  s    ?3(8999r   N)r   r   )r   )r   r   s     r   test_equalityzCoordinateTests.test_equality)  sD    
	: 	: 	: 	: 	))>>+;+;<<<<<r   c                    t          j        d          }t          j        d          }|                     ||           dS )zA
        Coordinates with different values aren't equal.
        r   rp   N)r   r   rJ   r   c1c2s      r   test_differentAnglesInequalityz.CoordinateTests.test_differentAnglesInequality3  s>     _S!!_T""B#####r   c                    t          j        dt          j                  }t          j        dt          j                  }|                     ||           dS )zT
        Coordinates with the same values but different types aren't equal.
        r   N)r   r   r   r   r   rJ   r   s      r   test_differentTypesInequalityz-CoordinateTests.test_differentTypesInequality;  sG     _S&/22_S&"233B#####r   c                   t          j        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.
        r   rx   ry   r   N)r   r   r   r   rz   r   r1   r   cs     r   	test_signzCoordinateTests.test_signC  sm    
 OD&/22			!+T222			"+U33333r   c                   d}t          j        |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.
        r   r}   r   r~   N)	r   r   r   r   r#   r$   rz   r   r1   )r   valuer   s      r   test_badVariationSignz%CoordinateTests.test_badVariationSignN  s    
 OE6?33*ai555+T222*ai333+T222*ai444+T22222r   c                    t          j        dt          j                  }|                     |j        t          j                   dS )zD
        Positive latitudes are in the northern hemisphere.
        r   N)r   r   r   r   r   
hemispherer   NORTHr   s     r   test_northernHemispherez'CoordinateTests.test_northernHemisphere_  s9     _S&/::
.
0@AAAAAr   c                    t          j        dt          j                  }|                     |j        t          j                   dS )zD
        Positive longitudes are in the eastern hemisphere.
        r   N)r   r   r   r   r   r   r   EASTr   s     r   test_easternHemispherez&CoordinateTests.test_easternHemispheref  s9     _S&*:;;
.
@@@@@r   c                    t          j        dt          j                  }|                     |j        t          j                   dS )zD
        Negative latitudes are in the southern hemisphere.
        rp   N)r   r   r   r   r   r   r   SOUTHr   s     r   test_southernHemispherez'CoordinateTests.test_southernHemispherem  s9     _T6?;;
.
0@AAAAAr   c                    t          j        dt          j                  }|                     |j        t          j                   dS )zD
        Negative longitudes are in the western hemisphere.
        rp   N)r   r   r   r   r   r   r   WESTr   s     r   test_westernHemispherez&CoordinateTests.test_westernHemispheret  s9     _T6+;<<
.
@@@@@r   c                n    t          j        dd          |                     t          fd           dS )zo
        Accessing the hemisphere for a coordinate that can't compute it
        raises C{ValueError}.
        r   Nc                      j         S )N)r   )r   s   r   <lambda>z4CoordinateTests.test_badHemisphere.<locals>.<lambda>  s
    j.C r   )r   r   r#   r$   r   s    @r   test_badHemispherez"CoordinateTests.test_badHemisphere{  s<    
 _S$//
*&C&C&C&CDDDDDr   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%   s    r   test_latitudeTooLargez%CoordinateTests.test_latitudeTooLarge  s:    
 	*mU;;;*mT:::::r   c                    |                      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     bg     VNr   r%   s    r   test_latitudeTooSmallz%CoordinateTests.test_latitudeTooSmall  s:    
 	*mV<<<*mU;;;;;r   c                    |                      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%   s    r   test_longitudeTooLargez&CoordinateTests.test_longitudeTooLarge  s:    
 	*ne<<<*ne<<<<<r   c                    |                      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     @or\   Nr   r%   s    r   test_longitudeTooSmallz&CoordinateTests.test_longitudeTooSmall  s:    
 	*nf===*nf=====r   c                    t          j        dt          j                  }|                     |j        d           t          j        dt          j                  }|                     |j        d           dS )zQ
        Coordinate values can be accessed in degrees, minutes, seconds.
        g     @I@)r~      r   g%CI@)r~      .   N)r   r   r   r   r   inDegreesMinutesSecondsr   s     r   test_inDegreesMinutesSecondsz,CoordinateTests.test_inDegreesMinutesSeconds  sb     OD&/222K@@@OFFO442LAAAAAr   c                d    t          j        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   r3   r   r   s     r   (test_unknownAngleInDegreesMinutesSecondsz8CoordinateTests.test_unknownAngleInDegreesMinutesSeconds  s2    
 OD$''!344444r   Nr'   )r(   r)   r*   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r,   r   r   r   r      s       2 2 2 29 9 9 99 9 9 99 9 9 98 8 8 88 8 8 8G G G GN N N N= = = =$ $ $ $$ $ $ $	4 	4 	4 	43 3 3 3"B B B BA A A AB B B BA A A AE E E E; ; ; ;< < < <= = = => > > >B B B B5 5 5 5 5 5r   r   r   r2   r   r   c                @    t          j        | t          j                  S )z7
    Builds and returns a latitude of given value.
    )r   r   r   r   r   s    r   r   r     s     ?5&/222r   c                @    t          j        | t          j                  S )z8
    Builds and returns a longitude of given value.
    r   r   s    r   r   r     s     ?5&"2333r   c                  2    e Zd ZdZd	dZd	dZd	dZd	dZdS )
AltitudeTestszC
    Tests for the L{twisted.positioning.base.Altitude} class.
    r   r   c                    t          j        d          }|                     t          |          d           |                     |j        d           |                     |j        dt           j        z             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   r2   inMetersinFeetMETERS_PER_FOOTr   altitudes     r   
test_valuezAltitudeTests.test_value  sn    
 =%%x#...*C000#0D*DEEEEEr   c                t    t          j        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   s     r   r   zAltitudeTests.test_repr  s6     =%%h)=>>>>>r   c                    t          j        d          }t          j        d          }|                     ||           dS )z<
        Altitudes with equal values compare equal.
        r   N)r   r   r   r   firstAltitudesecondAltitudes      r   r   zAltitudeTests.test_equality  s>     c**s++77777r   c                    t          j        d          }t          j        d          }|                     ||           dS )zF
        Altitudes with different values don't compare equal.
        r   rp   N)r   r   rJ   r   s      r   test_inequalityzAltitudeTests.test_inequality  s>     c**t,,M>:::::r   Nr'   )r(   r)   r*   r+   r   r   r   r   r,   r   r   r   r     sr         F F F F? ? ? ?8 8 8 8; ; ; ; ; ;r   r   c                  :    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.
    r   r   c                    t          j        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.
        r   N)r   Speedr   inMetersPerSecondr2   r   speeds     r   r   zSpeedTests.test_value  N    
 
4  0$777ut,,,,,r   c                t    t          j        d          }|                     t          |          d           dS )zC
        Speeds report their type and value in their repr.
        r   z<Speed (50.0 m/s)>N)r   r   r   r   r   s     r   r   zSpeedTests.test_repr  6     
4  e&:;;;;;r   c                R    |                      t          t          j        d           dS )zA
        Creating a negative speed raises C{ValueError}.
        rp   N)r#   r$   r   r   r%   s    r   test_negativeSpeedszSpeedTests.test_negativeSpeeds   s$     	*dj$77777r   c                ~    t          j        d          }|                     dt           j        z  |j                   dS )zC
        A speed can be converted into its value in knots.
        r   rx   N)r   r   r   MPS_PER_KNOTinKnotsr   s     r   test_inKnotszSpeedTests.test_inKnots  7     
3T..>>>>>r   c                p    |                      dt          t          j        d                               dS )z;
        A speed can be converted into a C{float}.
        r   N)r   r2   r   r   r%   s    r   test_asFloatzSpeedTests.test_asFloat  0     	eDJsOO4455555r   Nr'   )	r(   r)   r*   r+   r   r   r   r  r  r,   r   r   r   r     s         - - - -< < < <8 8 8 8? ? ? ?6 6 6 6 6 6r   r   c                  :    e Zd ZdZd
dZd
dZd
dZd
dZd
dZd	S )
ClimbTestsz6
    Tests for L{twisted.positioning.base.Climb}.
    r   r   c                    t          j        d          }|                     |j        d           |                     t	          |          d           dS )r         E@Nr   Climbr   r   r2   r   climbs     r   r8   zClimbTests.test_simple  r   r   c                t    t          j        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  s     r   r   zClimbTests.test_repr"  r   r   c                    t          j        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      ENr  r  s     r   test_negativeClimbszClimbTests.test_negativeClimbs)  sN    
 
5!!0%888uu-----r   c                ~    t          j        d          }|                     dt           j        z  |j                   dS )zC
        A climb can be converted into its value in knots.
        r   rx   N)r   r  r   r   r  r  s     r   test_speedInKnotszClimbTests.test_speedInKnots2  r  r   c                p    |                      dt          t          j        d                               dS )z;
        A climb can be converted into a C{float}.
        r   N)r   r2   r   r  r%   s    r   r  zClimbTests.test_asFloat9  r  r   Nr'   )	r(   r)   r*   r+   r8   r   r  r  r  r,   r   r   r  r    s         - - - -< < < <. . . .? ? ? ?6 6 6 6 6 6r   r  c                  v    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}.
    r   r   c                    t          j                    }|                     |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   PositionErrorr3   pdophdopvdopr   positionErrors     r   test_allUnsetz PositionErrorTests.test_allUnsetE  s]    
 *,,-,----,----,-----r   c                    t          j        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  s     r   test_allUnsetWithInvariantz-PositionErrorTests.test_allUnsetWithInvariantO  sb    
 *>>>-,----,----,-----r   c                f    t          j        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  s     r   test_withoutInvariantz(PositionErrorTests.test_withoutInvariantY  s6     *444+S11111r   c                h    t          j        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  s     r   test_withInvariantz%PositionErrorTests.test_withInvariant`  s8    
 *4HHH+S11111r   c                    t          j        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   errors     r   test_invalidWithoutInvariantz/PositionErrorTests.test_invalidWithoutInvarianth  si    
 "#C@@@S)))S)))S)))))r   c                Z    |                      t          t          j        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%   s    r   test_invalidWithInvariantz,PositionErrorTests.test_invalidWithInvariantr  s@    
 	 	 	
 	
 	
 	
 	
r   c                v    t          j        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   pes     r   test_setDOPWithoutInvariantz.PositionErrorTests.test_setDOPWithoutInvariant  s>    
 Ss333%(((((r   c                    t          j        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!  r0  base.PositionErrorr   r   c                    d| _         d S )Nr/  )r  )r0  s    r   setPDOPz<PositionErrorTests.test_setDOPWithInvariant.<locals>.setPDOP  s    BGGGr   N)r0  r3  r   r   )r   r  r  r#   r$   r   )r   r0  r  r5  s       r   test_setDOPWithInvariantz+PositionErrorTests.test_setDOPWithInvariant  sn    
 Ss$GGGw	 	 	 	 	*gr222$'''''r   z.<PositionError (pdop: %s, hdop: %s, vdop: %s)>r0  r3  r  float | Noner  r  c                   |                      |j        |           |                      |j        |           |                      |j        |           |                      t	          |          | j        |||fz             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   r0  r  r  r  s        r   _testDOPzPositionErrorTests._testDOP  s}    ( 	$'''$'''$'''b4#5tT8J#JKKKKKr   c                    d\  }}|dz  |dz  z
  dz  }t          j        ||          }|                     ||||           dS )zF
        The VDOP is correctly determined from PDOP and HDOP.
        rI   r            ?)r  r  Nr   r  r:  )r   r  r  r  r0  s        r   test_positionAndHorizontalSetz0PositionErrorTests.test_positionAndHorizontalSet  W     
da$'!c)T555b$d+++++r   c                    d\  }}|dz  |dz  z
  dz  }t          j        ||          }|                     ||||           dS )zF
        The HDOP is correctly determined from PDOP and VDOP.
        r<  r=  r>  )r  r  Nr?  )r   r  r  r  r0  s        r   test_positionAndVerticalSetz.PositionErrorTests.test_positionAndVerticalSet  rA  r   c                    d\  }}|dz  |dz  z   dz  }t          j        ||          }|                     ||||           dS )zF
        The PDOP is correctly determined from HDOP and VDOP.
        )r   r   r=  r>  r.  Nr?  )r   r  r  r  r0  s        r   test_horizontalAndVerticalSetz0PositionErrorTests.test_horizontalAndVerticalSet  rA  r   Nr'   )
r0  r3  r  r7  r  r7  r  r7  r   r   )r(   r)   r*   r+   r  r"  r%  r'  r*  r,  r1  r6  r9  r:  r@  rC  rE  r,   r   r   r  r  @  s        . . . .. . . .2 2 2 22 2 2 2* * * *
 
 
 
) ) ) )( ( ( ( EML L L L2, , , ,, , , ,, , , , , ,r   r  c                  6    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}.
    r   r   c                    t          j                    }|                     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;   s      r   test_minimalz#BeaconInformationTests.test_minimal  s^     #%%R^,,a000R 	 	b<00000r   rx   r   )azimuth	elevationsignalToNoiseRatioc                    d fd}t                      }t          dd          D ]!}|                     ||                     "t          j        |          }                     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.
        rR   r2   r   base.Satellitec                 x    t          j                  }|                    |            t          j        di |S )Nr,   )dictsatelliteKwargsupdater   	Satellite)rR   kwargsr   s     r   _buildSatellitez;BeaconInformationTests.test_simple.<locals>._buildSatellite  s;    $.//FMM">++F+++r   rx   
   )
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)rR   r2   r   rR  )
setrangeaddr   rI  r   rJ  seenBeaconsrK  r   )r   rY  beaconsprnrL  s   `    r   r8   z"BeaconInformationTests.test_simple  s    	, 	, 	, 	, 	, 	,
 %%B<< 	9 	9CKK37778888#G,,R^,,a000R^,,a000HH	
 	
 	
 	
 	
r   c                   t          j                    }t          dd          D ]S}t          j        d	d|i| j        }|j                            |           |dz  r|j                            |           T|                     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.
        rx   rZ  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   rI  r^  rW  rU  r`  r_  rK  r   rJ  r   )r   rL  rb  	satellites       r   test_someSatellitesUsedz.BeaconInformationTests.test_someSatellitesUsed  s    
 #%%B<< 	. 	.CNN#N9MNNINy)))Qw .""9---R^,,a000R^,,a000HH
E	
 	
 	
 	
 	
r   Nr'   )r(   r)   r*   r+   rM  rU  r8   rf  r,   r   r   rG  rG    sl         1 1 1 1 #$!3OOO!
 !
 !
 !
F
 
 
 
 
 
r   rG  c                  "    e Zd ZdZddZddZdS )PositioningBeaconTestsz.
    Tests for L{base.PositioningBeacon}.
    r   r   c                    t          j        t          j                  }|                     |           t          j        t           t          j        d                     dS )zX
        Tests that L{base.PositioningBeacon} implements L{IPositioningBeacon}.
        rx   N)r   implementedByr   PositioningBeacon
assertTruer   verifyObject)r   
implementss     r   test_interfacez%PositioningBeaconTests.test_interface*  sN     (5d6LMM

###.0Fq0I0IJJJJJr   c                p    |                      t          t          j        d                    d           dS )z9
        Tests the repr of a positioning beacon.
        Az<Beacon (A)>N)r   r   r   rk  r%   s    r   r   z PositioningBeaconTests.test_repr2  s3     	d4S99::NKKKKKr   Nr'   )r(   r)   r*   r+   ro  r   r,   r   r   rh  rh  %  sP         K K K KL L L L L Lr   rh  c                  "    e Zd ZdZddZddZdS )SatelliteTestsz:
    Tests for L{twisted.positioning.base.Satellite}.
    r   r   c                F   t          j        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.
        rx   z:<Satellite (1), azimuth: None, elevation: None, snr: None>N)	r   rW  r   r[  r3   rN  rO  rP  r   r   ss     r   rM  zSatelliteTests.test_minimal>  s     N1q)))!)$$$!+&&&!.///GGT	
 	
 	
 	
 	
r   c                T   t          j        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.
        rx   g     p@g      >@g      9@)r[  rN  rO  rP  z;<Satellite (1), azimuth: 270.0, elevation: 30.0, snr: 25.0>N)r   rW  r   r[  rN  rO  rP  r   ru  s     r   r8   zSatelliteTests.test_simpleN  s     N%4D
 
 
 	q)))E***d+++-t444GGU	
 	
 	
 	
 	
r   Nr'   )r(   r)   r*   r+   rM  r8   r,   r   r   rs  rs  9  sF         
 
 
 
 
 
 
 
 
 
r   rs  N)r   r2   r   r   )r+   
__future__r   zope.interfacer   twisted.positioningr   twisted.positioning.baser   r    twisted.positioning.ipositioningr   twisted.trial.unittestr	   r   r.   r   r   r   r   r   r  r  rG  rh  rs  r,   r   r   <module>r~     s    # " " " " " ! ! ! ! ! ! $ $ $ $ $ $ 7 7 7 7 7 7 7 7 ? ? ? ? ? ? + + + + + +!E !E !E !E !E !E !E !EHt4 t4 t4 t4 t48 t4 t4 t4nH5 H5 H5 H5 H5h H5 H5 H5V3 3 3 34 4 4 4$; $; $; $; $;H $; $; $;N&6 &6 &6 &6 &6 &6 &6 &6R)6 )6 )6 )6 )6 )6 )6 )6XK, K, K, K, K, K, K, K,\T
 T
 T
 T
 T
X T
 T
 T
nL L L L LX L L L(&
 &
 &
 &
 &
X &
 &
 &
 &
 &
r   