Revision 9f5a3645 test/ganeti.utils_unittest.py

b/test/ganeti.utils_unittest.py
1337 1337
    self._test(["a", "b", "a"], ["a", "b"])
1338 1338

  
1339 1339

  
1340
class TestFindDuplicates(unittest.TestCase):
1341
  """Test case for FindDuplicates"""
1342

  
1343
  def _Test(self, seq, expected):
1344
    result = utils.FindDuplicates(seq)
1345
    self.assertEqual(result, utils.UniqueSequence(result))
1346
    self.assertEqual(set(result), set(expected))
1347

  
1348
  def test(self):
1349
    self._Test([], [])
1350
    self._Test([1, 2, 3], [])
1351
    self._Test([9, 8, 8, 0, 5, 1, 7, 0, 6, 7], [8, 0, 7])
1352
    for exp in [[1, 2, 3], [3, 2, 1]]:
1353
      self._Test([1, 1, 2, 2, 3, 3], exp)
1354

  
1355
    self._Test(["A", "a", "B"], [])
1356
    self._Test(["a", "A", "a", "B"], ["a"])
1357
    self._Test("Hello World out there!", ["e", " ", "o", "r", "t", "l"])
1358

  
1359
    self._Test(self._Gen(False), [])
1360
    self._Test(self._Gen(True), range(1, 10))
1361

  
1362
  @staticmethod
1363
  def _Gen(dup):
1364
    for i in range(10):
1365
      yield i
1366
      if dup:
1367
        for _ in range(i):
1368
          yield i
1369

  
1370

  
1340 1371
class TestFirstFree(unittest.TestCase):
1341 1372
  """Test case for the FirstFree function"""
1342 1373

  

Also available in: Unified diff