File size: 1,321 Bytes
9d61c9b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import unittest

from models.helpers.tools import calc_same_padding


class TestCalcSamePadding(unittest.TestCase):
    def test_odd_kernel_size(self):
        """Test that the padding returns correct tuple for odd-sized kernel."""
        kernel_size = 3  # an odd-sized kernel
        pad = calc_same_padding(kernel_size)
        self.assertEqual(pad, (1, 1))  # we expect padding of size 1 on both sides

    def test_even_kernel_size(self):
        """Test that the padding returns correct tuple for even-sized kernel."""
        kernel_size = 4  # an even-sized kernel
        pad = calc_same_padding(kernel_size)
        self.assertEqual(
            pad, (2, 1),
        )  # we expect padding of size 2 on one side, and size 1 on the other side

    def test_one_kernel_size(self):
        """Test that the padding returns correct tuple for kernel of size 1."""
        kernel_size = 1  # kernel of size 1
        pad = calc_same_padding(kernel_size)
        self.assertEqual(pad, (0, 0))  # we expect no padding on both sides

    def test_zero_kernel_size(self):
        """Test that the padding raises ValueError for invalid kernel size of zero."""
        with self.assertRaises(ValueError):
            calc_same_padding(0)  # a kernel of size 0 is not valid


if __name__ == "__main__":
    unittest.main()