class PerfPush: def setup_py(self): self.pylist = list() def execute_py(self): self.pylist.append("value") def setup_caf(self): self.cafdeque = CafDeque() def execute_caf(self): self.cafdeque.push("value") # timeit def timeit_py(self): tpy = timeit.Timer(self.execute_py, self.setup_py) return tpy.repeat(rounds, repeat) def timeit_caf(self): tcaf = timeit.Timer(self.execute_caf, self.setup_caf) return tcaf.repeat(rounds, repeat) def timeit(self): print "python list" times_py = self.timeit_py() print times_py print average(times_py) print "caffeine deque" times_caf = self.timeit_caf() print times_caf print average(times_caf)
def run_profiling(): deque = CafDeque() for i in xrange(1000000): deque.push("value") deque.pop()
def setup_caf(self): self.cafdeque = CafDeque()
__author__ = 'thomas' from pycaffeine import CafDeque cd = CafDeque() print cd.is_empty() print cd.length() print cd.pop() print cd.push("one") print cd.push("two") print cd.push("three") print cd.is_empty() print cd.length() print cd.pop() print cd.pop() print cd.pop() print cd.is_empty() print cd.length() print cd.pop() print cd.is_empty() print cd.length() print cd.pop() print cd.is_empty()
def setUp(self): pass self.deque = CafDeque()
class TestCafDeque(unittest.TestCase): def setUp(self): pass self.deque = CafDeque() def test_deque_is_empty(self): self.assertTrue(self.deque.is_empty()) def test_deque_has_zero_length(self): self.assertEqual(len(self.deque), 0) def test_push_one_item(self): self.deque.push("first") self.assertFalse(self.deque.is_empty()) self.assertEqual(len(self.deque), 1) def test_pop_one_item(self): self.deque.push("first") value = self.deque.pop() self.assertEqual(value, "first") def test_contains_false(self): self.deque.push("inqueue") self.deque.push("inqueue1") self.deque.push("inqueue2") in_queue = self.deque.__contains__("notinqueue") self.assertFalse(in_queue) def test_contains_true(self): self.deque.push("inqueue") self.deque.push("inqueue1") self.deque.push("inqueue2") self.assertTrue(self.deque.__contains__("inqueue")) self.assertTrue(self.deque.__contains__("inqueue1")) self.assertTrue(self.deque.__contains__("inqueue2")) def test_getitem(self): self.deque.push("value1") self.assertEqual(self.deque[0], "value1") def test_getitem_indexerror(self): self.deque.push("value1") self.assertRaises(IndexError, self.deque.__getitem__, 1) def test_setitem(self): self.deque.push("value1") self.deque[0] = "value2" self.assertEqual(len(self.deque), 1) self.assertEqual(self.deque[0], "value2")