|
| 1 | +"""Tests for list operations module.""" |
| 2 | + |
| 3 | +import unittest |
| 4 | + |
| 5 | +from src.basic.list import ( |
| 6 | + is_empty_using_comparison, |
| 7 | + is_empty_using_len, |
| 8 | + is_empty_using_not, |
| 9 | +) |
| 10 | + |
| 11 | + |
| 12 | +class TestEmptyListChecks(unittest.TestCase): |
| 13 | + """Test cases for empty list check functions. |
| 14 | +
|
| 15 | + This test suite verifies different methods of checking if a list is empty. |
| 16 | + Each test method validates both empty and non-empty list cases. |
| 17 | + """ |
| 18 | + |
| 19 | + def setUp(self): |
| 20 | + """Initialize test data. |
| 21 | +
|
| 22 | + Creates two test lists: |
| 23 | + - empty_list: An empty list for testing empty case |
| 24 | + - non_empty_list: A list with elements for testing non-empty case |
| 25 | + """ |
| 26 | + self.empty_list = [] |
| 27 | + self.non_empty_list = [1, 2, 3] |
| 28 | + |
| 29 | + def test_is_empty_using_len(self): |
| 30 | + """Test empty list check using len() function. |
| 31 | +
|
| 32 | + Tests: |
| 33 | + 1. Empty list should return True |
| 34 | + 2. Non-empty list should return False |
| 35 | +
|
| 36 | + This test verifies that the len() based empty check works correctly |
| 37 | + for both empty and non-empty lists. |
| 38 | + """ |
| 39 | + self.assertTrue(is_empty_using_len(self.empty_list)) |
| 40 | + self.assertFalse(is_empty_using_len(self.non_empty_list)) |
| 41 | + |
| 42 | + def test_is_empty_using_not(self): |
| 43 | + """Test empty list check using not operator. |
| 44 | +
|
| 45 | + Tests: |
| 46 | + 1. Empty list should return True |
| 47 | + 2. Non-empty list should return False |
| 48 | +
|
| 49 | + This test verifies that the recommended method using 'not' operator |
| 50 | + works correctly for both empty and non-empty lists. |
| 51 | + """ |
| 52 | + self.assertTrue(is_empty_using_not(self.empty_list)) |
| 53 | + self.assertFalse(is_empty_using_not(self.non_empty_list)) |
| 54 | + |
| 55 | + def test_is_empty_using_comparison(self): |
| 56 | + """Test empty list check using comparison with empty list. |
| 57 | +
|
| 58 | + Tests: |
| 59 | + 1. Empty list should return True |
| 60 | + 2. Non-empty list should return False |
| 61 | +
|
| 62 | + This test verifies that comparing with an empty list [] |
| 63 | + works correctly for both empty and non-empty lists. |
| 64 | + """ |
| 65 | + self.assertTrue(is_empty_using_comparison(self.empty_list)) |
| 66 | + self.assertFalse(is_empty_using_comparison(self.non_empty_list)) |
0 commit comments