コード例 #1
0
    def test_runtime(self):
        stack = TripleStack()

        start = timeit.default_timer()
        for i in range(1000000):
            stack.push(i % 3, i % 3)
        end = timeit.default_timer()
        print "Running time for pushing %d elements was: %f seconds" % (
                i + 1, end - start)
コード例 #2
0
    def test_expand(self):
        stack = TripleStack()
        for i in range(10):
            stack.push(i % 3, i % 3)

        for i in range(20):
            stack.push(0, 0)
        
        print stack
コード例 #3
0
    def test_pop_and_peek(self):
        stack = TripleStack()
        for i in range(10):
            stack.push(i % 3, i)

        for i in range(9, -1, -1):
            self.assertEquals(stack.pop(i % 3), i)

        self.assertRaises(KeyError, stack.pop, 0)
        self.assertEquals(stack.peek(0), None)
コード例 #4
0
    def test_all(self):
        stack = TripleStack()

        for i in range(50):
            stack.push(i % 3, i % 3)

        for i in range(20):
            stack.pop(i % 3)

        for i in range(10):
            stack.push(1, 1)

        for i in range(5):
            stack.pop(2)

        print stack
コード例 #5
0
    def test_grow(self):
        stack = TripleStack()
        for i in range(10):
            stack.push(i % 3, i % 3)

        for i in range(14):
            stack.push(0, 0)

        for i in range(7):
            stack.push(1, 1)

        print stack
コード例 #6
0
 def test_push_and_peek(self):
     stack = TripleStack()
     for i in range(10):
         stack.push(i % 3, i)
         self.assertEquals(stack.peek(i % 3), i)