def test_natsort_case_insensitive(self): """natsort should perform numeric comparisons on strings and is _not_ case-sensitive""" # string with alpha and numerics sort correctly s = [ 'sample1', 'sample2', 'sample11', 'sample12', 'SAmple1', 'Sample2' ] # expected values exp_natsort = [ 'SAmple1', 'Sample2', 'sample1', 'sample2', 'sample11', 'sample12' ] exp_natsort_case_insensitive = [ 'sample1', 'SAmple1', 'sample2', 'Sample2', 'sample11', 'sample12' ] # test natsort self.assertEqual(natsort(s), exp_natsort) # test natsort case insensitive self.assertEqual(natsort(s, case_sensitive=False), exp_natsort_case_insensitive) s.reverse() # test natsort self.assertEqual(natsort(s), exp_natsort) # test natsort case insensitive exp_natsort_case_insensitive = [ 'SAmple1', 'sample1', 'Sample2', 'sample2', 'sample11', 'sample12' ] self.assertEqual(natsort(s, case_sensitive=False), exp_natsort_case_insensitive) self.assertEqual(natsort(list('cbaA321')), list('123Aabc')) self.assertEqual(natsort(list('cbaA321'), case_sensitive=False), list('123aAbc')) # strings with alpha only sort correctly self.assertEqual(natsort(list('cdBa'), case_sensitive=False), list('aBcd')) # string of ints sort correctly s = ['11', '2', '1', '0'] exp = ['0', '1', '2', '11'] self.assertEqual(natsort(s, case_sensitive=False), exp) # strings of floats sort correctly s = ['1.11', '1.12', '1.00', '0.009'] exp = ['0.009', '1.00', '1.11', '1.12'] self.assertEqual(natsort(s, case_sensitive=False), exp) # tuples sort correctly s = [('11', 'A'), ('2', 'B'), ('1', 'C'), ('0', 'D')] exp = [('0', 'D'), ('1', 'C'), ('2', 'B'), ('11', 'A')] self.assertEqual(natsort(s, case_sensitive=False), exp)
def test_natsort_case_insensitive(self): """natsort should perform numeric comparisons on strings and is _not_ case-sensitive""" # string with alpha and numerics sort correctly s = ['sample1', 'sample2', 'sample11', 'sample12', 'SAmple1', 'Sample2'] # expected values exp_natsort = ['SAmple1', 'Sample2', 'sample1', 'sample2', 'sample11', 'sample12'] exp_natsort_case_insensitive = ['sample1', 'SAmple1', 'sample2', 'Sample2', 'sample11', 'sample12'] # test natsort self.assertEqual(natsort(s), exp_natsort) # test natsort case insensitive self.assertEqual(natsort(s, case_sensitive=False), exp_natsort_case_insensitive) s.reverse() # test natsort self.assertEqual(natsort(s), exp_natsort) # test natsort case insensitive exp_natsort_case_insensitive = ['SAmple1', 'sample1', 'Sample2', 'sample2', 'sample11', 'sample12'] self.assertEqual(natsort(s, case_sensitive=False), exp_natsort_case_insensitive) self.assertEqual(natsort(list('cbaA321')), list('123Aabc')) self.assertEqual(natsort(list('cbaA321'), case_sensitive=False), list('123aAbc')) # strings with alpha only sort correctly self.assertEqual(natsort(list('cdBa'), case_sensitive=False), list('aBcd')) # string of ints sort correctly s = ['11', '2', '1', '0'] exp = ['0', '1', '2', '11'] self.assertEqual(natsort(s, case_sensitive=False), exp) # strings of floats sort correctly s = ['1.11', '1.12', '1.00', '0.009'] exp = ['0.009', '1.00', '1.11', '1.12'] self.assertEqual(natsort(s, case_sensitive=False), exp) # tuples sort correctly s = [('11', 'A'), ('2', 'B'), ('1', 'C'), ('0', 'D')] exp = [('0', 'D'), ('1', 'C'), ('2', 'B'), ('11', 'A')] self.assertEqual(natsort(s, case_sensitive=False), exp)
def test_natsort(self): """natsort should perform numeric comparisons on strings""" # string with alpha and numerics sort correctly s = ['sample1', 'sample2', 'sample11', 'sample12'] exp = ['sample1', 'sample2', 'sample11', 'sample12'] self.assertEqual(natsort(s), exp) s.reverse() self.assertEqual(natsort(s), exp) self.assertEqual(natsort(list('cba321')), list('123abc')) # strings with alpha only sort correctly self.assertEqual(natsort(list('cdba')), list('abcd')) # string of ints sort correctly s = ['11', '2', '1', '0'] exp = ['0', '1', '2', '11'] self.assertEqual(natsort(s), exp) # strings of floats sort correctly s = ['1.11', '1.12', '1.00', '0.009'] exp = ['0.009', '1.00', '1.11', '1.12'] self.assertEqual(natsort(s), exp) # tuples sort correctly s = [('11', 'A'), ('2', 'B'), ('1', 'C'), ('0', 'D')] exp = [('0', 'D'), ('1', 'C'), ('2', 'B'), ('11', 'A')] self.assertEqual(natsort(s), exp)