Home | History | Annotate | Download | only in example
      1 """An example unittest copied from python tutorial."""
      2 
      3 import random
      4 import unittest
      5 import traceback
      6 
      7 class SequenceFunctionsTestCase(unittest.TestCase):
      8 
      9     def setUp(self):
     10         #traceback.print_stack()
     11         self.seq = range(10)
     12 
     13     def tearDown(self):
     14         #traceback.print_stack()
     15         pass
     16 
     17     def test_shuffle(self):
     18         # make sure the shuffled sequence does not lose any elements
     19         random.shuffle(self.seq)
     20         self.seq.sort()
     21         self.assertEqual(self.seq, range(10))
     22 
     23     def test_choice(self):
     24         element = random.choice(self.seq)
     25         self.assertTrue(element in self.seq)
     26 
     27     def test_sample(self):
     28         self.assertRaises(ValueError, random.sample, self.seq, 20)
     29         for element in random.sample(self.seq, 5):
     30             self.assertTrue(element in self.seq)
     31 
     32     def getCategories(self):
     33         return []
     34 
     35 if __name__ == '__main__':
     36     unittest.main()
     37