예제 #1
0
class TestLifo(unittest.TestCase):
    def setUp(self):
        self.a = Lifo()
        self.b = Lifo([1, 2, 3])

    def test_ctor(self):
        a = Lifo()
        b = Lifo([1, 2, 3])
        self.assertEqual(len(a), 0)
        self.assertEqual(len(b), 3)

    def test_push(self):
        self.a.push(1)
        self.assertEqual(len(self.a), 1)
        self.a.push(2)
        self.assertEqual(len(self.a), 2)
        v = self.a.pop()
        self.assertEqual(v, 2)

        self.assertEqual(len(self.b), 3)
        self.b.push(1)
        self.assertEqual(len(self.b), 4)

    def test_pop(self):
        self.assertRaises(IndexError, self.a.pop)
        i = 3
        while len(self.b) > 0:
            v = self.b.pop()
            self.assertEqual(v, i)
            i -= 1

    def test_top(self):
        self.assertRaises(IndexError, self.a.top)
        self.assertEqual(self.b.top(), 3)

    def test_repr(self):
        self.assertEqual(list(self.b), list(eval(repr(self.b))))
예제 #2
0
 def __init__(self, createLifo=lambda: Lifo()):
     self.createLifo = createLifo
예제 #3
0
 def test_ctor(self):
     a = Lifo()
     b = Lifo([1, 2, 3])
     self.assertEqual(len(a), 0)
     self.assertEqual(len(b), 3)
예제 #4
0
 def setUp(self):
     self.a = Lifo()
     self.b = Lifo([1, 2, 3])
def find(S: List[Point2D]) -> List[int]:
    S1 = [Point2D(*i)
          for i in S]  # lo mismo que S1=S=[Point2D(x, y) for x,y in S]

    # Eleccion punto inicial y ordenacion
    min_y = min(p.y for p in S1)
    p = argmax((pt for pt in S1 if min_y == pt.y), lambda pt: pt.x)
    S1 = [p] + sorted((q for q in S1 if q != p),
                      key=lambda q: (atan2(p.y - q.y, p.x - q.x), q.x))
    Q = Lifo()
    Q.push(0), Q.push(1), Q.push(2)
    for pi in range(3, len(S1)):
        pj, pk = Q[-1], Q[-2]
        while not left(S1[pk], S1[pj], S1[pi]):
            Q.pop()
            pj, pk = Q[-1], Q[-2]
        Q.push(pi)
    return [S.index(S1[Q.pop()]) for i in range(len(Q))]