Пример #1
0
def test_scramble():
    for s in ['a', 'rat', 'JavaScript testing', '', 'zzz', '^*&^*&^▱ÄÈËɡɳɷ']:
        assert sorted(s) == sorted(scramble(s))
    possibilities = set(['ABC', 'ACB', 'BAC', 'BCA', 'CAB', 'CBA'])
    for i in range(200):
        possibilities.discard(scramble('ABC'))
    assert len(possibilities) == 0
Пример #2
0
    def test_scramble(self):
        """Test scrampling a string.

        Aside from ensuring that no characters are lost
        in the translation, this is rather hard to test
        programatically, because randomness can't easily
        be measured. Printing out the output shows this
        to be pseudorandom.
        """
        from collections import Counter
        self.assertEqual(Counter(scramble('Hello, world')),
                         Counter('Hello, world'))
Пример #3
0
 def test_scramble_is_really_random(self):
     # Make sure we get all 8 possible scrambles; 200 runs should be sufficient.
     possibilities = set('ABC ACB BAC BCA CAB CBA'.split(' '))
     for i in range(200):
         possibilities.discard(scramble('ABC'))
     self.assertEqual(possibilities, set([]))
Пример #4
0
 def test_scramble_scrambles(self):
     data = ["", "a", "rat", "BSOD", "BDFL", "Python testing"]
     for s in data:
         self.assertEqual(sorted(s), sorted(scramble(s)))
Пример #5
0
 def test_scramble_is_really_random(self):
     # Make sure we get all 8 possible scrambles; 200 runs should be sufficient.
     possibilities = set("ABC ACB BAC BCA CAB CBA".split(" "))
     for i in range(200):
         possibilities.discard(scramble("ABC"))
     self.assertEqual(possibilities, set([]))
Пример #6
0
 def test_scramble_scrambles(self):
     data = ["", "a", "rat", "BSOD", "BDFL", "Python testing"]
     for s in data:
         self.assertEqual(sorted(s), sorted(scramble(s)))