Coverage for tests/tests_advertrain/test_dependencies/test_cleverhans/test_fast_gradient_method.py: 100%
19 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-09-10 08:11 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-09-10 08:11 +0000
1import pytest
2import torch
4from robustML.advertrain.dependencies.cleverhans.fast_gradient_method import \
5 fast_gradient_method
7torch.manual_seed(0)
10def mock_model_fn(x):
11 return x
14def test_adversarial_example_generation():
15 x = torch.randn(3, 3)
16 eps = 0.1
17 norm = 2
19 adv_x = fast_gradient_method(mock_model_fn, x, eps, norm)
21 assert adv_x.shape == x.shape
22 assert torch.max(torch.abs(adv_x - x)) <= eps
25def test_error_on_negative_eps():
26 x = torch.randn(3, 3)
27 eps = -0.1
28 norm = 2
30 with pytest.raises(ValueError):
31 fast_gradient_method(mock_model_fn, x, eps, norm)