19707bb6e50715489119bd756f208d3e9b7072848Johnny Chen"""An example unittest copied from python tutorial."""
29707bb6e50715489119bd756f208d3e9b7072848Johnny Chen
39707bb6e50715489119bd756f208d3e9b7072848Johnny Chenimport random
49707bb6e50715489119bd756f208d3e9b7072848Johnny Chenimport unittest
59707bb6e50715489119bd756f208d3e9b7072848Johnny Chenimport traceback
69707bb6e50715489119bd756f208d3e9b7072848Johnny Chen
71c42e8684d26e1473f92c799eeae65a3eec991d6Johnny Chenclass SequenceFunctionsTestCase(unittest.TestCase):
89707bb6e50715489119bd756f208d3e9b7072848Johnny Chen
99707bb6e50715489119bd756f208d3e9b7072848Johnny Chen    def setUp(self):
109707bb6e50715489119bd756f208d3e9b7072848Johnny Chen        #traceback.print_stack()
119707bb6e50715489119bd756f208d3e9b7072848Johnny Chen        self.seq = range(10)
129707bb6e50715489119bd756f208d3e9b7072848Johnny Chen
139707bb6e50715489119bd756f208d3e9b7072848Johnny Chen    def tearDown(self):
149707bb6e50715489119bd756f208d3e9b7072848Johnny Chen        #traceback.print_stack()
159707bb6e50715489119bd756f208d3e9b7072848Johnny Chen        pass
169707bb6e50715489119bd756f208d3e9b7072848Johnny Chen
179707bb6e50715489119bd756f208d3e9b7072848Johnny Chen    def test_shuffle(self):
189707bb6e50715489119bd756f208d3e9b7072848Johnny Chen        # make sure the shuffled sequence does not lose any elements
199707bb6e50715489119bd756f208d3e9b7072848Johnny Chen        random.shuffle(self.seq)
209707bb6e50715489119bd756f208d3e9b7072848Johnny Chen        self.seq.sort()
219707bb6e50715489119bd756f208d3e9b7072848Johnny Chen        self.assertEqual(self.seq, range(10))
229707bb6e50715489119bd756f208d3e9b7072848Johnny Chen
239707bb6e50715489119bd756f208d3e9b7072848Johnny Chen    def test_choice(self):
249707bb6e50715489119bd756f208d3e9b7072848Johnny Chen        element = random.choice(self.seq)
259707bb6e50715489119bd756f208d3e9b7072848Johnny Chen        self.assertTrue(element in self.seq)
269707bb6e50715489119bd756f208d3e9b7072848Johnny Chen
279707bb6e50715489119bd756f208d3e9b7072848Johnny Chen    def test_sample(self):
289707bb6e50715489119bd756f208d3e9b7072848Johnny Chen        self.assertRaises(ValueError, random.sample, self.seq, 20)
299707bb6e50715489119bd756f208d3e9b7072848Johnny Chen        for element in random.sample(self.seq, 5):
309707bb6e50715489119bd756f208d3e9b7072848Johnny Chen            self.assertTrue(element in self.seq)
319707bb6e50715489119bd756f208d3e9b7072848Johnny Chen
32ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata    def getCategories(self):
33ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata        return []
349707bb6e50715489119bd756f208d3e9b7072848Johnny Chen
359707bb6e50715489119bd756f208d3e9b7072848Johnny Chenif __name__ == '__main__':
369707bb6e50715489119bd756f208d3e9b7072848Johnny Chen    unittest.main()
37