# Path: diffprivlib/tools/utils.py
# def std(array, epsilon=1.0, bounds=None, axis=None, dtype=None, keepdims=False, accountant=None, **unused_args):
#     r"""
#     Compute the standard deviation along the specified axis.
# 
#     Returns the standard deviation of the array elements, a measure of the spread of a distribution, with differential
#     privacy.  The standard deviation is computed for the flattened array by default, otherwise over the specified axis.
#     Noise is added using :class:`.LaplaceBoundedDomain` to satisfy differential privacy, where sensitivity is
#     calculated using `bounds`.  Users are advised to consult the documentation of :obj:`numpy.std` for further details,
#     as the behaviour of `std` closely follows its Numpy variant.
# 
#     Parameters
#     ----------
#     array : array_like
#         Calculate the standard deviation of these values.
# 
#     epsilon : float, default: 1.0
#         Privacy parameter :math:`\epsilon`.
# 
#     bounds : tuple, optional
#         Bounds of the values of the array, of the form (min, max).
# 
#     axis : int or tuple of ints, optional
#         Axis or axes along which the standard deviation is computed.  The default is to compute the standard deviation
#         of the flattened array.
# 
#         If this is a tuple of ints, a standard deviation is performed over multiple axes, instead of a single axis or
#         all the axes as before.
# 
#     dtype : dtype, optional
#         Type to use in computing the standard deviation.  For arrays of integer type the default is float64, for arrays
#         of float types it is the same as the array type.
# 
#     keepdims : bool, default: False
#         If this is set to True, the axes which are reduced are left in the result as dimensions with size one.  With
#         this option, the result will broadcast correctly against the input array.
# 
#     accountant : BudgetAccountant, optional
#         Accountant to keep track of privacy budget.
# 
#     Returns
#     -------
#     standard_deviation : ndarray, see dtype parameter above.
#         Return a new array containing the standard deviation.
# 
#     See Also
#     --------
#     var, mean, nanstd
# 
#     """
#     warn_unused_args(unused_args)
# 
#     return _std(array, epsilon=epsilon, bounds=bounds, axis=axis, dtype=dtype, keepdims=keepdims,
#                 accountant=accountant, nan=False)
# 
# Path: diffprivlib/utils.py
# class PrivacyLeakWarning(RuntimeWarning):
#     """Custom warning to capture privacy leaks resulting from incorrect parameter setting.
# 
#     For example, this warning may occur when the user:
# 
#         - fails to specify the bounds or range of data to a model where required (e.g., `bounds=None` to
#           :class:`.GaussianNB`).
#         - inputs data to a model that falls outside the bounds or range originally specified.
# 
#     """
# 
# def global_seed(seed):
#     """Sets the seed for all random number generators, to guarantee reproducibility in experiments.
# 
#     Parameters
#     ----------
#     seed : int
#         The seed value for the random number generators.
# 
#     Returns
#     -------
#     None
# 
#     """
#     np.random.seed(seed)
# 
# class BudgetError(ValueError):
#     """Custom exception to capture the privacy budget being exceeded, typically controlled by a
#     :class:`.BudgetAccountant`.
# 
#     For example, this exception may be raised when the user:
# 
#         - Attempts to execute a query which would exceed the privacy budget of the accountant.
#         - Attempts to change the slack of the accountant in such a way that the existing budget spends would exceed the
#           accountant's budget.
# 
#     """


from unittest import TestCase
from diffprivlib.tools.utils import std
from diffprivlib.utils import PrivacyLeakWarning, global_seed, BudgetError
        from diffprivlib.accountant import BudgetAccountant
import numpy as np



class TestStd(TestCase):
    def test_not_none(self):
        mech = std
        self.assertIsNotNone(mech)

    def test_no_params(self):
        a = np.array([1, 2, 3])
        with self.assertWarns(PrivacyLeakWarning):
            res = std(a)
        self.assertIsNotNone(res)

    def test_no_epsilon(self):
        a = np.array([1, 2, 3])
        self.assertIsNotNone(std(a, bounds=(0, 1)))

    def test_no_bounds(self):
        a = np.array([1, 2, 3])
        with self.assertWarns(PrivacyLeakWarning):
            std(a, epsilon=1)

    def test_bad_bounds(self):
        a = np.array([1, 2, 3])
        with self.assertRaises(ValueError):
            std(a, epsilon=1, bounds=(0, -1))

    def test_missing_bounds(self):
        a = np.array([1, 2, 3])

# Path: diffprivlib/tools/utils.py
# def std(array, epsilon=1.0, bounds=None, axis=None, dtype=None, keepdims=False, accountant=None, **unused_args):
#     r"""
#     Compute the standard deviation along the specified axis.
# 
#     Returns the standard deviation of the array elements, a measure of the spread of a distribution, with differential
#     privacy.  The standard deviation is computed for the flattened array by default, otherwise over the specified axis.
#     Noise is added using :class:`.LaplaceBoundedDomain` to satisfy differential privacy, where sensitivity is
#     calculated using `bounds`.  Users are advised to consult the documentation of :obj:`numpy.std` for further details,
#     as the behaviour of `std` closely follows its Numpy variant.
# 
#     Parameters
#     ----------
#     array : array_like
#         Calculate the standard deviation of these values.
# 
#     epsilon : float, default: 1.0
#         Privacy parameter :math:`\epsilon`.
# 
#     bounds : tuple, optional
#         Bounds of the values of the array, of the form (min, max).
# 
#     axis : int or tuple of ints, optional
#         Axis or axes along which the standard deviation is computed.  The default is to compute the standard deviation
#         of the flattened array.
# 
#         If this is a tuple of ints, a standard deviation is performed over multiple axes, instead of a single axis or
#         all the axes as before.
# 
#     dtype : dtype, optional
#         Type to use in computing the standard deviation.  For arrays of integer type the default is float64, for arrays
#         of float types it is the same as the array type.
# 
#     keepdims : bool, default: False
#         If this is set to True, the axes which are reduced are left in the result as dimensions with size one.  With
#         this option, the result will broadcast correctly against the input array.
# 
#     accountant : BudgetAccountant, optional
#         Accountant to keep track of privacy budget.
# 
#     Returns
#     -------
#     standard_deviation : ndarray, see dtype parameter above.
#         Return a new array containing the standard deviation.
# 
#     See Also
#     --------
#     var, mean, nanstd
# 
#     """
#     warn_unused_args(unused_args)
# 
#     return _std(array, epsilon=epsilon, bounds=bounds, axis=axis, dtype=dtype, keepdims=keepdims,
#                 accountant=accountant, nan=False)
# 
# Path: diffprivlib/utils.py
# class PrivacyLeakWarning(RuntimeWarning):
#     """Custom warning to capture privacy leaks resulting from incorrect parameter setting.
# 
#     For example, this warning may occur when the user:
# 
#         - fails to specify the bounds or range of data to a model where required (e.g., `bounds=None` to
#           :class:`.GaussianNB`).
#         - inputs data to a model that falls outside the bounds or range originally specified.
# 
#     """
# 
# def global_seed(seed):
#     """Sets the seed for all random number generators, to guarantee reproducibility in experiments.
# 
#     Parameters
#     ----------
#     seed : int
#         The seed value for the random number generators.
# 
#     Returns
#     -------
#     None
# 
#     """
#     np.random.seed(seed)
# 
# class BudgetError(ValueError):
#     """Custom exception to capture the privacy budget being exceeded, typically controlled by a
#     :class:`.BudgetAccountant`.
# 
#     For example, this exception may be raised when the user:
# 
#         - Attempts to execute a query which would exceed the privacy budget of the accountant.
#         - Attempts to change the slack of the accountant in such a way that the existing budget spends would exceed the
#           accountant's budget.
# 
#     """


# Path: tests/tools/test_std.py
from unittest import TestCase
from diffprivlib.tools.utils import std
from diffprivlib.utils import PrivacyLeakWarning, global_seed, BudgetError
        from diffprivlib.accountant import BudgetAccountant
import numpy as np




class TestStd(TestCase):
    def test_not_none(self):
        mech = std
        self.assertIsNotNone(mech)

    def test_no_params(self):
        a = np.array([1, 2, 3])
        with self.assertWarns(PrivacyLeakWarning):
            res = std(a)
        self.assertIsNotNone(res)

    def test_no_epsilon(self):
        a = np.array([1, 2, 3])
        self.assertIsNotNone(std(a, bounds=(0, 1)))

    def test_no_bounds(self):
        a = np.array([1, 2, 3])
        with self.assertWarns(PrivacyLeakWarning):
            std(a, epsilon=1)

    def test_bad_bounds(self):
        a = np.array([1, 2, 3])
        with self.assertRaises(ValueError):
            std(a, epsilon=1, bounds=(0, -1))

    def test_missing_bounds(self):
        a = np.array([1, 2, 3])

        with self.assertWarns(PrivacyLeakWarning):