示例#1
0
 def test_order_maintained(self):
     inputs = [
         (3, 2),
         (2, 1),
         (3, 2),
         (2, 0),
         (3, 2),
     ]
     expected = [
         inputs[0],
         inputs[2],
         inputs[4],
     ]
     outputs = multimax(inputs)
     self.assertEqual(outputs, expected)
     self.assertIs(outputs[0], expected[0])
     self.assertIs(outputs[1], expected[1])
     self.assertIs(outputs[2], expected[2])
示例#2
0
 def test_key_function(self):
     words = ["alligator", "animal", "apple", "artichoke", "avalanche"]
     outputs = ["alligator", "artichoke", "avalanche"]
     self.assertEqual(multimax(words, key=len), outputs)
示例#3
0
 def test_iterator(self):
     numbers = [1, 4, 2, 4, 3]
     squares = (n**2 for n in numbers)
     self.assertEqual(multimax(squares), [16, 16])
示例#4
0
 def test_empty(self):
     self.assertEqual(multimax([]), [])
示例#5
0
 def test_lists(self):
     inputs = [[0], [1], [], [0, 1], [1]]
     expected = [[1], [1]]
     self.assertEqual(multimax(inputs), expected)
示例#6
0
 def test_all_max(self):
     self.assertEqual(multimax([1, 1, 1, 1, 1]), [1, 1, 1, 1, 1])
示例#7
0
 def test_two_max(self):
     self.assertEqual(multimax([1, 4, 2, 4, 3]), [4, 4])
示例#8
0
 def test_single_max(self):
     self.assertEqual(multimax([1, 2, 4, 3]), [4])