@@ -75,91 +75,103 @@ class ResponseListTestCase(unittest.TestCase):
7575    """Tests for ResponseList""" 
7676
7777    @staticmethod  
78-     def  responses_from_times (times ):
79-         """Generates a list of empty  responses from a list of time elapsed 
78+     def  responses_from_times_success (times ):
79+         """Generates a list of successful  responses from a list of time elapsed 
8080
8181        :param times: List of time elapsed for each response 
8282        :type times: list 
8383        :return: List of responses 
8484        :rtype: executor.ResponseList""" 
85-         return  executor .ResponseList ([executor .Response (None , _ ) for  _  in  times ])
85+         return  executor .ResponseList ([SuccessfulResponseMock (None , _ ) for  _  in  times ])
86+ 
87+     @staticmethod  
88+     def  responses_from_times_failed (times ):
89+         """Generates a list of failing responses from a list of time elapsed 
90+ 
91+         :param time_messages: List of [time,message] time is elapsed for each response, 
92+         message is error message 
93+         :type times: list 
94+         :return: List of responses 
95+         :rtype: executor.ResponseList""" 
96+ 
97+         return  executor .ResponseList ([FailingResponseMock (None , _ ) for  _  in  times ])
8698
8799    def  test_rtt_min_ms (self ):
88100        """Verifies the minimum RTT is found correctly""" 
89101        self .assertEqual (
90-             self .responses_from_times ([0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]).rtt_min ,
102+             self .responses_from_times_success ([0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]).rtt_min ,
91103            0 ,
92104            'Unable to identify minimum RTT of 0' 
93105        )
94106        self .assertEqual (
95-             self .responses_from_times ([38 , 11 , 93 , 100 , 38 , 11 , 0.1 ]).rtt_min ,
107+             self .responses_from_times_success ([38 , 11 , 93 , 100 , 38 , 11 , 0.1 ]).rtt_min ,
96108            0.1 ,
97109            'Unable to identify minimum RTT of 0.1' 
98110        )
99111        self .assertEqual (
100-             self .responses_from_times ([10 , 10 , 10 , 10 ]).rtt_min ,
112+             self .responses_from_times_success ([10 , 10 , 10 , 10 ]).rtt_min ,
101113            10 ,
102114            'Unable to identify minimum RTT of 10 on a series of only 10s' 
103115        )
104116
105117    def  test_rtt_max_ms (self ):
106118        """Verifies the maximum RTT is found correctly""" 
107119        self .assertEqual (
108-             self .responses_from_times ([0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]).rtt_max ,
120+             self .responses_from_times_success ([0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]).rtt_max ,
109121            9 ,
110122            'Unable to identify maximum RTT of 9' 
111123        )
112124        self .assertEqual (
113-             self .responses_from_times ([38 , 11 , 93 , 100 , 38 , 11 , 0.1 ]).rtt_max ,
125+             self .responses_from_times_success ([38 , 11 , 93 , 100 , 38 , 11 , 0.1 ]).rtt_max ,
114126            100 ,
115127            'Unable to identify maximum RTT of 100' 
116128        )
117129        self .assertEqual (
118-             self .responses_from_times ([10 , 10 , 10 , 10 ]).rtt_max ,
130+             self .responses_from_times_success ([10 , 10 , 10 , 10 ]).rtt_max ,
119131            10 ,
120132            'Unable to identify maximum RTT of 10 on a series of only 10s' 
121133        )
122134
123135    def  test_rtt_avg_ms (self ):
124136        """Verifies the average RTT is found correctly""" 
125137        self .assertEqual (
126-             self .responses_from_times ([0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]).rtt_avg ,
138+             self .responses_from_times_success ([0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]).rtt_avg ,
127139            4.5 ,
128140            'Unable to identify average RTT of 4.5' 
129141        )
130142        self .assertEqual (
131-             self .responses_from_times ([38 , 11 , 93 , 100 , 38 , 11 , 0.1 ]).rtt_avg ,
143+             self .responses_from_times_success ([38 , 11 , 93 , 100 , 38 , 11 , 0.1 ]).rtt_avg ,
132144            41.58571428571429 ,
133145            'Unable to identify average RTT of 41.58571428571429' 
134146        )
135147        self .assertEqual (
136-             self .responses_from_times ([10 , 10 , 10 , 10 ]).rtt_avg ,
148+             self .responses_from_times_success ([10 , 10 , 10 , 10 ]).rtt_avg ,
137149            10 ,
138150            'Unable to identify average RTT of 10 on a series of only 10s' 
139151        )
140152
141153    def  test_len (self ):
142154        """Verifies the length is returned correctly""" 
143155        self .assertEqual (
144-             len (self .responses_from_times (list (range (10 )))),
156+             len (self .responses_from_times_success (list (range (10 )))),
145157            10 ,
146158            'Unable identify the length of 10' 
147159        )
148160        self .assertEqual (
149-             len (self .responses_from_times (list (range (0 )))),
161+             len (self .responses_from_times_success (list (range (0 )))),
150162            0 ,
151163            'Unable identify the length of 0' 
152164        )
153165        self .assertEqual (
154-             len (self .responses_from_times (list (range (23 )))),
166+             len (self .responses_from_times_success (list (range (23 )))),
155167            23 ,
156168            'Unable identify the length of 23' 
157169        )
158170
159171    def  test_iterable (self ):
160172        """Verifies it is iterable""" 
161173        self .assertTrue (
162-             isinstance (self .responses_from_times ([0 , 1 , 2 , 3 ]), collections .abc .Iterable ),
174+             isinstance (self .responses_from_times_success ([0 , 1 , 2 , 3 ]), collections .abc .Iterable ),
163175            'Unable to iterate over ResponseList object' 
164176        )
165177
@@ -303,6 +315,80 @@ def test_some_packets_lost_mixed(self):
303315            "Unable to calculate packet loss correctly when failing responses are mixed with successful responses" 
304316        )
305317
318+     def  test_rtt_max_ms_lost (self ):
319+         """Verifies the maximum RTT is found correctly even with lost packets""" 
320+         self .assertEqual (
321+             self .responses_from_times_failed ([0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]).rtt_max ,
322+             0 ,
323+             'Unable to identify maximum RTT of 0 when all packets are lost' 
324+         )
325+         test  =  executor .ResponseList (
326+             self .responses_from_times_failed ([2000 , 2000 , 2000 ])._responses  +  self .responses_from_times_success (
327+                 [100 , 38 , 11 , 0.1 ])._responses )
328+         self .assertEqual (
329+             test .rtt_max ,
330+             100 ,
331+             'Unable to identify maximum RTT of 100 when half packets are lost' 
332+         )
333+         test  =  executor .ResponseList (
334+             self .responses_from_times_success ([10 ])._responses  +  self .responses_from_times_failed (
335+                 [2000 ])._responses  +  self .responses_from_times_success (
336+                 [10 , 10 ])._responses )
337+         self .assertEqual (
338+             test .rtt_max ,
339+             10 ,
340+             'Unable to identify maximum RTT of 10 when some packets are lost' 
341+         )
342+ 
343+     def  test_rtt_avg_ms_lost (self ):
344+         """Verifies the average RTT is found correctly even with lost packets""" 
345+         test  =  executor .ResponseList (self .responses_from_times_failed (
346+             [2000 , 2000 , 2000 , 2000 , 2000 ])._responses  +  self .responses_from_times_success (
347+             [1 , 3 , 5 , 7 , 9 ])._responses )
348+         self .assertEqual (
349+             test .rtt_avg ,
350+             5 ,
351+             'Unable to identify average RTT of 5 when half the packets are lost' 
352+         )
353+         test  =  executor .ResponseList (
354+             self .responses_from_times_success ([38 ])._responses  +  self .responses_from_times_failed (
355+                 [2000 ])._responses  +  self .responses_from_times_success (
356+                 [93 , 100 , 38 , 11 , 0.1 ])._responses )
357+         self .assertEqual (
358+             test .rtt_avg ,
359+             46.68333333333334 ,
360+             'Unable to identify average RTT of 46.68333333333334 when some packets are lost' 
361+         )
362+         self .assertEqual (
363+             self .responses_from_times_failed ([10 , 10 , 10 , 10 ]).rtt_avg ,
364+             10 ,
365+             'Unable to identify average RTT of 0 when all packets are lost' 
366+         )
367+ 
368+     def  test_rtt_min_ms_lost (self ):
369+         """Verifies the minimum RTT is found correctly even with lost packets""" 
370+         test  =  executor .ResponseList (
371+             self .responses_from_times_failed ([2000 , 2000 ])._responses  +  self .responses_from_times_success (
372+                 [2 , 3 , 4 , 5 ])._responses  + 
373+             self .responses_from_times_failed ([2000 , 2000 , 2000 , 2000 ])._responses )
374+         self .assertEqual (
375+             test .rtt_min ,
376+             2 ,
377+             'Unable to identify minimum RTT of 2 when some packets are lost' 
378+         )
379+         self .assertEqual (
380+             self .responses_from_times_failed ([2000 , 2000 , 2000 , 2000 , 2000 , 2000 , 2000 ]).rtt_min ,
381+             0 ,
382+             'Unable to identify minimum RTT of 0 when all packets are lost' 
383+         )
384+         test  =  executor .ResponseList (
385+             self .responses_from_times_failed ([2000 , 2000 ])._responses  +  self .responses_from_times_success (
386+                 [10 , 10 ])._responses )
387+         self .assertEqual (
388+             self .responses_from_times_success ([10 , 10 , 10 , 10 ]).rtt_min ,
389+             10 ,
390+             'Unable to identify minimum RTT of 10 when half packets are lost' 
391+         )
306392
307393class  CommunicatorTestCase (unittest .TestCase ):
308394    """Tests for Communicator""" 
0 commit comments