File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 1+ import unittest
2+ from ..shuffling import knuth
3+
4+ class ShufflingAlgorithmTestCase (unittest .TestCase ):
5+ """
6+ Shared code for shuffling unit tests.
7+ """
8+
9+ def setUp (self ):
10+ self .sorted = range (10 )
11+
12+
13+ class TestKnuthShuffle (ShufflingAlgorithmTestCase ):
14+ """
15+ Tests Knuth shuffle on a small range from 0-9
16+ """
17+ def test_knuthshuffle (self ):
18+ self .shuffle = knuth .shuffle (range (10 ))
19+
20+ for i in self .shuffle :
21+ not_shuffled = 0
22+ if i == self .sorted [i ]:
23+ not_shuffled = not_shuffled + 1
24+
25+ self .assertGreater (2 , not_shuffled )
Original file line number Diff line number Diff line change @@ -12,8 +12,6 @@ def setUp(self):
1212 self .input = range (10 )
1313 random .shuffle (self .input )
1414 self .correct = range (10 )
15- print self .input
16- print self .correct
1715
1816
1917class TestBubbleSort (SortingAlgorithmTestCase ):
You can’t perform that action at this time.
0 commit comments