def test_shrink_fcp_list(self): """Test shrink_fcp_list""" # Case1: only one FCP in the list. fcp_list = ['1A01'] expected_fcp_str = '1A01' result = zvmutils.shrink_fcp_list(fcp_list) self.assertEqual(expected_fcp_str, result) # Case 2: all the FCPs are continuous. expected_fcp_str = [ '1A01 - 1A0E', # continuous in last 1 digit '1A0E - 1A2E', # continuous in last 2 digits '1AEF - 1B1F'] # continuous in last 3 digits expected_fcp_count = [ 14, # continuous in last 1 digit 33, # continuous in last 2 digits 49] # continuous in last 3 digits for idx, efs in enumerate(expected_fcp_str): fcp_list = list( zvmutils.expand_fcp_list(efs)[0]) result = zvmutils.shrink_fcp_list(fcp_list.copy()) self.assertEqual(efs, result) self.assertEqual(expected_fcp_count[idx], len(fcp_list)) # Case 3: not all the FCPs are continuous. expected_fcp_str = [ '1A01, 1A0E - 1A2E', # case 3.1 '1A0E - 1A2E, 1B01', # case 3.2 '1A05, 1A0E - 1A2E, 1A4A, 1AEF - 1B1F', # case 3.3 '1A0E - 1A2E, 1A4A, 1A5B, 1AEF - 1B1F'] # case 3.4 expected_fcp_count = [ 34, # case 3.1 34, # case 3.2 84, # case 3.3 84 # case 3.4 ] for idx, efs in enumerate(expected_fcp_str): fcp_list = list( zvmutils.expand_fcp_list(efs)[0]) result = zvmutils.shrink_fcp_list(fcp_list.copy()) self.assertEqual(efs, result) self.assertEqual(expected_fcp_count[idx], len(fcp_list)) # Case 4: an empty list. fcp_list = [] expected_fcp_str = '' result = zvmutils.shrink_fcp_list(fcp_list) self.assertEqual(expected_fcp_str, result)
def test_expand_fcp_list_with_normal_plus_dash(self): fcp_list = "1f10;1f11-1f13;1f17" expected = {0: set(['1f10']), 1: set(['1f11', '1f12', '1f13']), 2: set(['1f17'])} fcp_info = zvmutils.expand_fcp_list(fcp_list) self.assertEqual(expected, fcp_info)
def test_expand_fcp_list_with_4_uncontinuous_equal_count(self): fcp_list = "5c70-5c71,5c73-5c74;5d70-5d71,\ 5d73-5d74;1111-1112,1113-1114;2211-2212,2213-2214" expected = {0: set(['5c70', '5c71', '5c73', '5c74']), 1: set(['5d70', '5d71', '5d73', '5d74']), 2: set(['1111', '1112', '1113', '1114']), 3: set(['2211', '2212', '2213', '2214']), } fcp_info = zvmutils.expand_fcp_list(fcp_list) self.assertEqual(expected, fcp_info)
def test_expand_fcp_list_normal(self): fcp_list = "1f10;1f11;1f12;1f13;1f14" expected = {0: set(['1f10']), 1: set(['1f11']), 2: set(['1f12']), 3: set(['1f13']), 4: set(['1f14'])} fcp_info = zvmutils.expand_fcp_list(fcp_list) self.assertEqual(expected, fcp_info)
def test_expand_fcp_list_with_uncontinuous_not_equal_count(self): fcp_list = "5c73-5c74;5d70-5d71,5d73-5d74" expected = {0: set(['5c73', '5c74']), 1: set(['5d70', '5d71', '5d73', '5d74'])} fcp_info = zvmutils.expand_fcp_list(fcp_list) self.assertEqual(expected, fcp_info)
def test_expand_fcp_list_with_dash(self): fcp_list = "1f10-1f14" expected = {0: set(['1f10', '1f11', '1f12', '1f13', '1f14'])} fcp_info = zvmutils.expand_fcp_list(fcp_list) self.assertEqual(expected, fcp_info)