Created
May 27, 2011 01:44
-
-
Save poochin/994492 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| import unittest | |
| from random import randrange | |
| class TestShuffle(unittest.TestCase): | |
| def setUp(self): | |
| pass | |
| def testShuffle(self): | |
| base = range(10) | |
| self.assertNotEqual(base, shuffle(base)) | |
| def shuffle(array): | |
| result = array[:] | |
| for i in range(len(result) - 1): | |
| j = randrange(i + 1, len(result)) | |
| result[i], result[j] = result[j], result[i] | |
| return result | |
| def main(): | |
| unittest.main() | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment