def bubble_sort(list):
  n = len(list)
  for i in range(n):
    for j in range(0, n-i-1):
      if list[j] > list[j+1] :
        list[j], list[j+1] = list[j+1], list[j]
  return list

import unittest

class TestBubbleSort(unittest.TestCase):

  def test_empty_list(self):
    self.assertEqual(bubble_sort([]), [])

  def test_one_element(self):
    self.assertEqual(bubble_sort([1]), [1])

  def test_already_sorted(self):
    self.assertEqual(bubble_sort([1,2,3]), [1,2,3])

  def test_reverse_sorted(self):  
    self.assertEqual(bubble_sort([3,2,1]), [1,2,3])

  def test_few_unique(self):
    self.assertEqual(bubble_sort([5,3,2,4,1]), [1,2,3,4,5])

  def test_few_duplicates(self):
    self.assertEqual(bubble_sort([5,3,2,4,2,1,5,4]), [1,2,2,3,4,4,5,5])

if __name__ == '__main__':
  unittest.main()
