当前位置: 首页>>代码示例>>Python>>正文


Python Solution.connect方法代码示例

本文整理汇总了Python中solution.Solution.connect方法的典型用法代码示例。如果您正苦于以下问题:Python Solution.connect方法的具体用法?Python Solution.connect怎么用?Python Solution.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在solution.Solution的用法示例。


在下文中一共展示了Solution.connect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestCase

# 需要导入模块: from solution import Solution [as 别名]
# 或者: from solution.Solution import connect [as 别名]
class TestCase(unittest.TestCase):

    def setUp(self):
        self.solution = Solution()

    def _testSolution(self, deep):
        node_count = pow(2, deep)
        node_queue = Queue.Queue(node_count)
        root_queue = Queue.Queue(node_count / 2)

        # Generate the tree
        nodes = [TreeNode(x) for x in xrange(1, node_count)]
        root_queue.put(nodes[0])
        for node in nodes[1:]:
            node_queue.put(node)

        while not node_queue.empty():
            root = root_queue.get()
            root.left = node_queue.get()
            root.right = node_queue.get()
            root_queue.put(root.left)
            root_queue.put(root.right)

        # Solution
        self.solution.connect(nodes[0])

        # Assertion
        for level in xrange(deep):
            self.assertLinkedList(nodes[pow(2, level) - 1], pow(2, level))

    def assertLinkedList(self, root, length):
        count = 0
        # linked_list = []
        while root:
            # linked_list.append(str(root.val))
            root = root.next
            count += 1
        # print ' -> '.join(linked_list)
        self.assertEqual(count, length)
开发者ID:romain-li,项目名称:leetcode,代码行数:41,代码来源:test.py

示例2: test_1

# 需要导入模块: from solution import Solution [as 别名]
# 或者: from solution.Solution import connect [as 别名]
def test_1():
    sol = Solution()
    n1 = TreeLinkNode(1)
    n2 = TreeLinkNode(2)
    n3 = TreeLinkNode(3)
    n1.left = n2
    n1.right = n3
    n4 = TreeLinkNode(4)
    n5 = TreeLinkNode(5)
    n2.left = n4
    n2.right = n5
    n6 = TreeLinkNode(6)
    n7 = TreeLinkNode(7)
    n3.left = n6
    n3.right = n7
    sol.connect(n1)
    assert n1.next is None
    assert n2.next is n3
    assert n3.next is None
    assert n4.next is n5
    assert n5.next is n6
    assert n6.next is n7
    assert n7.next is None
开发者ID:misaka-10032,项目名称:leetcode,代码行数:25,代码来源:test.py

示例3: SmithWidget

# 需要导入模块: from solution import Solution [as 别名]
# 或者: from solution.Solution import connect [as 别名]
class SmithWidget(Gtk.DrawingArea):
    def __init__(self):
        Gtk.DrawingArea.__init__(self)
        self.connect("draw", self._draw)
        self.connect("configure_event", self._configure_event)
        self.connect("motion_notify_event", self._motion_event)
        self.add_events(Gdk.EventMask.POINTER_MOTION_MASK |
                        Gdk.EventMask.BUTTON_PRESS_MASK |
                        Gdk.EventMask.KEY_PRESS_MASK)
        self.set_can_default(True)
        self.set_can_focus(True)
        self.solution = Solution()
        self.solution.connect("changed", self._solution_changed)
        self.load = None
        self.wload = None
        self.component = None

    def gamma_to_xy(self, gamma):
        x = gamma.real * self._radius + self._width/2
        y = -gamma.imag * self._radius + self._height/2
        return x, y

    def xy_to_gamma(self, x, y):
        gamma = (x - self._width / 2.0) / self._radius
        gamma += 1.0j * (self._height / 2.0 - y) / self._radius
        if abs(gamma) > 0.99:
            gamma = cmath.rect(0.99, cmath.phase(gamma))
        return gamma

    def _draw_chart(self, c):
        """Draw a smith chart on a cairo.Context"""
        style = self.get_style_context()
        # Draw pale admittance grid by scaling and translating
        c.save()
        c.scale(-1, -1)
        color = self.get_style().mid[self.get_state()]
        c.set_source_rgb(color.red, color.green, color.blue)
        draw_chart_lines(c)
        c.restore()

        # Draw impedance grid
        draw_chart_lines(c)

        # Draw chart outline and hard zero reactance line
        c.new_path()
        c.move_to(-1, 0)
        c.line_to(1, 0)
        c.stroke()

        c.set_line_width(0.01)
        c.new_path()
        c.arc(0, 0, 1, 0, 2*math.pi)
        c.stroke()

    def _configure_event(self, w, event):
        self._width = event.width
        self._height = event.height
        self._radius = min(self._width, self._height)/2 - 10

    def cairo_to_gamma(self, cr):
        w = self.get_allocated_width()
        h = self.get_allocated_height()
        r = min(w, h)/2 - 10;
        cr.translate(w/2, h/2)
        cr.scale(r, -r)
        cr.set_line_width(0.005)

    def _draw(self, w, cr):
        self.cairo_to_gamma(cr)
        self._draw_chart(cr)
        self._paint_solution(cr)

    def _motion_event(self, w, event):
        gamma = self.xy_to_gamma(event.x, event.y)
        z = gamma_to_z(gamma)
        if self.load is not None and self.component is not None:
            z = self.component.contraint(self.wload, z)
            gamma = z_to_gamma(z)

        y = 1/z
        text = "Z = %.1f%+.1fj; Y = %.1f%+.1fj\n" % (z.real, z.imag, y.real, y.imag)
        text += "\u0393 = %.1f%+.1fj\n" % (gamma.real, gamma.imag)
        text += "SWR = %.1f\n" % gamma_to_swr(gamma)
        try:
            rl = "%.1f" % (-20*math.log10(abs(gamma)))
        except ValueError:
            rl = "\u221e"
        text += "S<sub>11</sub> = -%s dB" % rl
        return
        layout = pango.Layout(self.get_pango_context())
        layout.set_markup(text)
        w, h = layout.get_pixel_size();
        w += 20
        self._pixmap.draw_drawable(self.style.white_gc,self._chart,
                                  10, 10, 10, 10, w, h)
        self._cairo.set_source_color(self.style.text[self.state])
        self._cairo.move_to(10, 10)
        self._cairo.show_layout(layout)
        self.queue_draw_area(10, 10, w, h)

#.........这里部分代码省略.........
开发者ID:gsmcmullin,项目名称:smith,代码行数:103,代码来源:smithwidget.py

示例4: len

# 需要导入模块: from solution import Solution [as 别名]
# 或者: from solution.Solution import connect [as 别名]
        tn.left = left
        q.append(left)
        idx += 1
        if idx == len(tree):
            break
        right = constructOne(tree[idx])
        idx += 1
        tn.right = right
        q.append(right)
    return root

def printNode(tn, indent):
    sb = ""
    for i in range(indent):
        sb += "\t"
    sb += str(tn.val)
    print(sb)

def printTree(root, indent):
    if not root:
        return
    printTree(root.right, indent + 1)
    printNode(root, indent)
    printTree(root.left, indent + 1)

root = createTree("1, 2, 5, 3, 4, 6, 7")
#  printTree(root, 0)
sol = Solution()
sol.connect(root)
printTree(root, 0)
开发者ID:zhlinh,项目名称:leetcode,代码行数:32,代码来源:test.py

示例5: test_0

# 需要导入模块: from solution import Solution [as 别名]
# 或者: from solution.Solution import connect [as 别名]
def test_0():
    sol = Solution()
    n1 = TreeLinkNode(1)
    sol.connect(n1)
    assert n1.next is None
开发者ID:misaka-10032,项目名称:leetcode,代码行数:7,代码来源:test.py


注:本文中的solution.Solution.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。