+ def set_max_attempts(self, max_attempts):
+ """Set maximum number of traffic runs during one rate step.
+
+ :param max_attempts: Number of traffic runs.
+ :type max_attempts: int
+ :returns: nothing
+ :raises ValueError: If max attempts is lower than zero.
+ """
+ if int(max_attempts) > 0:
+ self._max_attempts = int(max_attempts)
+ else:
+ raise ValueError("Max attempt must by greater than zero")
+
+ def get_max_attempts(self):
+ """Return maximum number of traffic runs during one rate step.
+
+ :returns: Number of traffic runs.
+ :rtype: int
+ """
+ return self._max_attempts
+
+ def set_search_result_type_best_of_n(self):
+ """Set type of search result evaluation to Best of N.
+
+ :returns: nothing
+ """
+ self._set_search_result_type(SearchResultType.BEST_OF_N)
+
+ def set_search_result_type_worst_of_n(self):
+ """Set type of search result evaluation to Worst of N.
+
+ :returns: nothing
+ """
+ self._set_search_result_type(SearchResultType.WORST_OF_N)
+
+ def _set_search_result_type(self, search_type):
+ """Set type of search result evaluation to one of SearchResultType.
+
+ :param search_type: Type of search result evaluation to set.
+ :type search_type: SearchResultType
+ :returns: nothing
+ :raises ValueError: If search type is unknown.
+ """
+ if search_type not in SearchResultType:
+ raise ValueError("search_type unknown: {}".format(search_type))
+ else:
+ self._search_result_type = search_type
+
+ @staticmethod
+ def _get_best_of_n(res_list):
+ """Return best result of N traffic runs.
+
+ :param res_list: List of return values from all runs at one rate step.
+ :type res_list: list
+ :returns: True if at least one run is True, False otherwise.
+ :rtype: boolean
+ """
+ # Return True if any element of the iterable is True.
+ return any(res_list)
+
+ @staticmethod
+ def _get_worst_of_n(res_list):
+ """Return worst result of N traffic runs.
+
+ :param res_list: List of return values from all runs at one rate step.
+ :type res_list: list
+ :returns: False if at least one run is False, True otherwise.
+ :rtype: boolean
+ """
+ # Return False if not all elements of the iterable are True.
+ return all(res_list)
+
+ def _get_res_based_on_search_type(self, res_list):
+ """Return result of search based on search evaluation type.
+
+ :param res_list: List of return values from all runs at one rate step.
+ :type res_list: list
+ :returns: Boolean based on search result type.
+ :rtype: boolean
+ :raises ValueError: If search result type is unknown.
+ """
+ if self._search_result_type == SearchResultType.BEST_OF_N:
+ return self._get_best_of_n(res_list)
+ elif self._search_result_type == SearchResultType.WORST_OF_N:
+ return self._get_worst_of_n(res_list)
+ else:
+ raise ValueError("Unknown search result type")
+