def test_wrong(self): with self.assertRaises(Exception): sort(same, 'desc') with self.assertRaises(Exception): sort(same, 'ascending') with self.assertRaises(Exception): sort(same, 'descending') with self.assertRaises(Exception): sort(same, 'DESC') with self.assertRaises(Exception): sort(same, 'DES') with self.assertRaises(Exception): sort(same, 'ASC')
import stalinsort print(stalinsort.sort([1, 2, 3, 2, 3, 2, 3, 4, 5, 6]))
def test_repeated(self): self.assertListEqual(sort(same, 'des'), same)
def test_right(self): self.assertListEqual(sort(same, 'asc'), same) self.assertListEqual(sort(same, 'des'), same)
def test_reversed(self): self.assertListEqual(sort(reversed, 'des'), reversed)
def test_almost_sorted(self): self.assertListEqual(sort(almost_sorted, 'des'), [0]) self.assertListEqual(sort(almost_sorted0, 'des'), [0, -1])
def test_empty(self): self.assertListEqual(sort([], 'des'), [])
def test_sorted(self): self.assertListEqual(sort(sorted, 'des'), [0])
def test_almost_sorted(self): self.assertListEqual(sort(almost_sorted), [0, 1, 4]) self.assertListEqual(sort(almost_sorted0), [0, 2, 4, 7])
def test_reversed(self): self.assertListEqual(sort(reversed), [3])
def test_sorted(self): self.assertListEqual(sort(sorted), sorted)