Best Python code snippet using hypothesis
test_document.py
Source:test_document.py
...20def test_grouping():21 doc = Document()22 doc[r'\count0'].value=10023 assert doc[r'\count0'].value==10024 doc.begin_group()25 doc[r'\count0'].value=10026 doc[r'\count1'].value=027 doc[r'\count0'].value=20028 doc[r'\count0'].value=20029 doc[r'\count1'].value=030 doc.end_group()31 doc[r'\count0'].value=10032 doc[r'\count1'].value=033def test_group_matching():34 doc = Document()35 g1 = doc.begin_group()36 assert g1 is not None37 g2 = doc.begin_group()38 assert g2 is not None39 doc.end_group(group=g2)40 doc.end_group(group=g1)41 g1 = doc.begin_group()42 g2 = doc.begin_group()43 doc.end_group()44 doc.end_group(group=g1)45 g1 = doc.begin_group()46 g2 = doc.begin_group()47 doc.end_group(group=g2)48 doc.end_group()49 g1 = doc.begin_group()50 g2 = doc.begin_group()51 doc.end_group()52 doc.end_group()53 g1 = doc.begin_group()54 g2 = doc.begin_group()55 with pytest.raises(ValueError):56 doc.end_group(group=g1)57def test_group_ephemeral():58 doc = Document()59 g1 = doc.begin_group()60 g2 = doc.begin_group()61 with pytest.raises(ValueError):62 doc.end_group(group=g1)63 doc = Document()64 g1 = doc.begin_group()65 g2 = doc.begin_group(ephemeral=True)66 doc.end_group(group=g1)67this_file_load_time = datetime.datetime.now()68def test_time():69 doc = Document()70 when = yex.control.parameter.file_load_time71 assert doc[r'\time'].value == when.hour*60+when.minute72 assert doc[r'\day'].value == when.day73 assert doc[r'\month'].value == when.month74 assert doc[r'\year'].value == when.year75 # In case the clock has ticked forward during running the test76 assert this_file_load_time-when < datetime.timedelta(seconds=3), \77 f"{when} {this_file_load_time}"78def test_set_global():79 doc = Document()80 assert doc[r'\count0'].value==081 doc[r'\count0'].value = 182 assert doc[r'\count0'].value==183 doc.begin_group()84 doc[r'\count0'].value = 285 assert doc[r'\count0'].value==286 doc.end_group()87 assert doc[r'\count0'].value==188 doc.begin_group()89 doc.next_assignment_is_global = True90 doc[r'\count0'].value = 291 assert doc[r'\count0'].value==292 doc.end_group()93 assert doc[r'\count0'].value==294def test_document_len():95 doc = Document()96 assert len(doc)==197 doc.begin_group()98 assert len(doc)==299 doc.end_group()100 assert len(doc)==1101def test_document_save(yex_test_fs):102 message = "Lorum ipsum dolor sit amet."103 y = yex.Document()104 y += (105 r"\def\TeX{T\kern-.1667em\lower.5ex\hbox{E}\kern-.125emX}"106 r"\shipout\hbox{"107 f"{message}"108 r"}"109 )110 y.save('lorum.svg')111 result = ''.join(check_svg('lorum.svg'))112 assert result == message.replace(' ','')113def _test_font_control(114 string,115 s = None,116 ):117 if s is None:118 doc = Document()119 return doc['_font']120def test_control_symbols():121 s = yex.document.Document()122 # Let's look up three controls which are all horizontal unexpandables:123 for name in [124 # an example of a control token:125 r'\discretionary',126 # two examples of control symbols:127 r'\-',128 r'\ ',129 ]:130 handler = s[name]131 assert handler.horizontal, f"{name} is a valid horizontal control"132def test_document_end_all_groups(fs):133 doc = yex.Document()134 for i in range(10):135 assert len(doc.groups)==i136 doc.begin_group()137 doc.end_all_groups()138 assert len(doc.groups)==0139def test_document_save_ends_all_groups(yex_test_fs):140 FILENAME = "x.svg"141 doc = yex.Document()142 run_code(143 r"\hbox{X}",144 doc = doc,145 )146 doc.save(FILENAME)147 assert os.access(FILENAME, os.F_OK), "it didn't save"...
reverseNodesInKGroup.py
Source:reverseNodesInKGroup.py
1from typing import Optional2import sys3sys.path.append("..")4from linkedlist import MyLinkedList, Node as ListNode5from rotateList import printList6class Solution:7 def reverseLinkedList(self, head: Optional[ListNode]) -> Optional[ListNode]:8 if head == None:9 return None10 new_head = head11 curr_node = head.next12 head.next = None13 next_node = None14 while curr_node != None:15 next_node = curr_node.next16 curr_node.next = new_head17 new_head = curr_node18 curr_node = next_node19 return new_head20 def reverseKGroup(self, head: Optional[ListNode], k: int) -> Optional[ListNode]:21 if k == 1:22 return head23 dummy = ListNode(None, head)24 before_begin_group = dummy25 begin_group = head26 end_group = dummy27 after_end_group = head28 done = False29 while True:30 for _ in range(k):31 if end_group == None or after_end_group == None:32 done = True33 break34 end_group = end_group.next35 after_end_group = after_end_group.next36 if done:37 break38 print('-', before_begin_group, begin_group, end_group, after_end_group)39 before_begin_group.next = None40 end_group.next = None41 self.reverseLinkedList(begin_group)42 before_begin_group.next = end_group43 begin_group.next = after_end_group44 ###45 before_begin_group = begin_group46 begin_group = after_end_group47 ###48 end_group = before_begin_group49 print('+', before_begin_group, begin_group, end_group, after_end_group)50 printList(dummy)51 return dummy.next52s = Solution()53l = MyLinkedList()54l.addAtTail(1)55l.addAtTail(2)56l.addAtTail(3)57l.addAtTail(4)58l.addAtTail(5)59l.addAtTail(6)60l.addAtTail(7)61l.addAtTail(8)62print('hooooo')63print(l)...
positions-of-large-groups.py
Source:positions-of-large-groups.py
1class Solution:2 def largeGroupPositions(self, s: str) -> List[List[int]]:3 4 begin_group = 05 n = len(s)6 res = []7 for i in range(1, n):8 if s[i-1] == s[i]:9 pass10 else:11 lenght = i - begin_group12 if lenght >= 3:13 res.append([begin_group, i-1])14 begin_group = i15 if s[begin_group] == s[n - 1] and n - begin_group >= 3:16 res.append([begin_group, n - 1])17 return res18# Time: O(N)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!