/
test_random_spike.py
49 lines (40 loc) · 1.53 KB
/
test_random_spike.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from torchio import RandomSpike
from ...utils import TorchioTestCase
class TestRandomSpike(TorchioTestCase):
"""Tests for `RandomSpike`."""
def test_with_zero_intensity(self):
transform = RandomSpike(intensity=0)
transformed = transform(self.sample_subject)
self.assertTensorAlmostEqual(
self.sample_subject.t1.data,
transformed.t1.data,
)
def test_with_zero_spike(self):
transform = RandomSpike(num_spikes=0)
transformed = transform(self.sample_subject)
self.assertTensorAlmostEqual(
self.sample_subject.t1.data,
transformed.t1.data,
)
def test_with_spikes(self):
transform = RandomSpike()
transformed = transform(self.sample_subject)
self.assertTensorNotEqual(
self.sample_subject.t1.data,
transformed.t1.data,
)
def test_negative_num_spikes(self):
with self.assertRaises(ValueError):
RandomSpike(num_spikes=-1)
def test_num_spikes_range_with_negative_min(self):
with self.assertRaises(ValueError):
RandomSpike(num_spikes=(-1, 4))
def test_not_integer_num_spikes(self):
with self.assertRaises(ValueError):
RandomSpike(num_spikes=(0.7, 4))
def test_wrong_num_spikes_type(self):
with self.assertRaises(ValueError):
RandomSpike(num_spikes='wrong')
def test_wrong_intensity_type(self):
with self.assertRaises(ValueError):
RandomSpike(intensity='wrong')