def verify_tails(t: unittest.TestCase, run: kfp_server_api.ApiRun, tasks: dict[str, KfpTask], **kwargs): t.assertEqual(run.status, 'Succeeded') t.assertCountEqual(['print-msg', 'condition-1', 'flip-coin'], tasks.keys()) t.assertIsNone(tasks['condition-1'].children) # MLMD canceled state means NotTriggered state for KFP. t.assertEqual(Execution.State.CANCELED, tasks['condition-1'].state)
def test_folder_info(s): tc = TestCase() info = s.folder_info('SyncthingManagerTestFolder1') tc.assertCountEqual(['id', 'index', 'devices', 'label'], list(info.keys())) assert len(info['devices']) == 1 info = s.folder_info('stmantest1') tc.assertCountEqual(['id', 'index', 'devices', 'label'], list(info.keys()))
def verify_tasks(t: unittest.TestCase, tasks: Dict[str, KfpTask]): task_names = [*tasks.keys()] t.assertCountEqual(task_names, ['read-from-gcs', 'write-to-gcs'], 'task names') write_task = tasks['write-to-gcs'] read_task = tasks['read-from-gcs'] pprint('======= preprocess task =======') pprint(write_task.get_dict()) pprint('======= train task =======') pprint(read_task.get_dict()) pprint('==============') t.assertEqual( { 'name': 'write-to-gcs', 'inputs': { 'artifacts': [], 'parameters': { 'msg': 'Hello world!', } }, 'outputs': { 'artifacts': [{ 'metadata': { 'display_name': 'artifact' }, 'name': 'artifact', 'type': 'system.Artifact' }], 'parameters': {} }, 'type': 'system.ContainerExecution', 'state': Execution.State.COMPLETE, }, write_task.get_dict()) t.assertEqual( { 'name': 'read-from-gcs', 'inputs': { 'artifacts': [{ 'metadata': { 'display_name': 'artifact' }, 'name': 'artifact', 'type': 'system.Artifact', }], 'parameters': {} }, 'outputs': { 'artifacts': [], 'parameters': {} }, 'type': 'system.ContainerExecution', 'state': Execution.State.COMPLETE, }, read_task.get_dict())
def verify(t: unittest.TestCase, run: kfp_server_api.ApiRun, tasks: dict[str, KfpTask], **kwargs): t.assertEqual(run.status, 'Succeeded') # assert DAG structure t.assertCountEqual(['generate-op', 'print-op', 'for-loop-1'], tasks.keys()) # assert all iteration outputs t.assertCountEqual(['110', '220', '330', '440'], [ x.children['print-op-2'].outputs.parameters['Output'] for x in tasks['for-loop-1'].children.values() ])
def assrt(expecteds, inputs): tst = TestCase() slots = Recurslot() res = [] for s in inputs: ans = slots.cmd(s) print('', s, slots.slots, ans, sep='\n') if ans != None: res.append(ans) tst.assertCountEqual(expecteds, res)
def assertStrsEqual(a: List[str], b: List[str]) -> None: t = TestCase() t.assertEqual(len(a), len(b)) a_, b_ = [] * len(a), [] * len(b) for e in a: a_.append(sorted(e)) for e in b: b_.append(sorted(e)) t.assertCountEqual(a_, b_)
def compare_schema_texts_order_independently( test_case: TestCase, expected_schema_text: str, received_schema_text: str, ) -> None: """Compare expected and received schema texts, ignoring order of definitions.""" expected_schema_blocks = expected_schema_text.split("\n\n") received_schema_blocks = expected_schema_text.split("\n\n") # This is the preferred order-independent comparison method in Python: # https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertCountEqual test_case.assertCountEqual(expected_schema_blocks, received_schema_blocks)
def test_verifychange(driver, username, email, sex_no, msn, q_number, b_number, j_number, p_number, birth_year, birth_month, birth_day): driver.switch_to_frame("menu-frame") driver.find_element_by_link_text("会员列表").click() driver.switch_to_default_content() driver.switch_to_frame("main-frame") driver.find_element_by_name("keyword").send_keys(username) driver.find_element_by_xpath("//input[@type='submit']").click() sleep(1) driver.find_element_by_xpath("//a[@title='编辑']").click() actual_name = driver.find_element_by_name("username").get_attribute( "value") TestCase.assertEqual(TestCase(), actual_name, username) actual_mail = driver.find_element_by_name("email").get_attribute("value") TestCase.assertEqual(TestCase(), actual_mail, email) print("前后台邮件对比一致") actual_msn = driver.find_element_by_name("extend_field1").get_attribute( "value") TestCase.assertEqual(TestCase(), actual_msn, msn) print("前后台MSN对比一致") a_qnumber = driver.find_element_by_name("extend_field2").get_attribute( "value") TestCase.assertEqual(TestCase(), a_qnumber, q_number) print("前后台QQ对比一致") a_bnumber = driver.find_element_by_name("extend_field3").get_attribute( "value") TestCase.assertEqual(TestCase(), a_bnumber, b_number) print("前后台办公电话对比一致") a_jnumber = driver.find_element_by_name("extend_field4").get_attribute( "value") TestCase.assertEqual(TestCase(), a_jnumber, j_number) print("前后台家庭电话对比一致") a_pnumber = driver.find_element_by_name("extend_field5").get_attribute( "value") TestCase.assertEqual(TestCase(), a_pnumber, p_number) print("前后台手机对比一致") actual_sex = driver.find_element_by_xpath( "//input[@checked]").get_attribute("value") TestCase.assertEqual(TestCase(), actual_sex, str(sex_no)) print("前后台性别对比一致") actual_years = driver.find_element_by_name("birthdayYear") actual_year = Select(actual_years) for select in actual_year.all_selected_options: a_year = select.text TestCase.assertCountEqual(TestCase(), a_year, birth_year) actual_months = driver.find_element_by_name("birthdayMonth") actual_month = Select(actual_months) for select in actual_month.all_selected_options: a_month = select.text TestCase.assertCountEqual(TestCase(), a_month, birth_month) actual_days = driver.find_element_by_name("birthdayDay") actual_day = Select(actual_days) for select in actual_day.all_selected_options: a_day = select.text TestCase.assertCountEqual(TestCase(), a_day, birth_day) print("出生日期对比一致") driver.switch_to_default_content() driver.switch_to_frame("header-frame") driver.find_element_by_link_text("起始页").click() driver.switch_to_default_content()
def verify(t: unittest.TestCase, run: kfp_server_api.ApiRun, tasks: dict[str, KfpTask], **kwargs): t.assertEqual(run.status, 'Succeeded') # assert DAG structure t.assertCountEqual(['print-op', 'for-loop-1'], tasks.keys()) # assert all iteration parameters t.assertCountEqual( [{ 'a': '1', 'b': '2' }, { 'a': '10', 'b': '20' }], [ x.inputs. parameters['pipelinechannel--static_loop_arguments-loop-item'] for x in tasks['for-loop-1'].children.values() ], ) # assert all iteration outputs t.assertCountEqual(['12', '1020'], [ x.children['print-op-2'].outputs.parameters['Output'] for x in tasks['for-loop-1'].children.values() ])
def test_stock_find_stock(): """ Tests Stock.find_stock() """ stock1 = Stock(name="Name1X", ticker="TKRC") stock1.save() stock2 = Stock(name="Name2Y", ticker="TKFF") stock2.save() TestCase.assertCountEqual(None, [stock1, stock2], Stock.find_stock("")) TestCase.assertCountEqual(None, [stock1, stock2], Stock.find_stock("Name")) TestCase.assertCountEqual(None, [stock1], Stock.find_stock("Name1")) TestCase.assertCountEqual(None, [stock2], Stock.find_stock("e2")) single_stock_find = Stock.find_stock("", 1)[0] assert single_stock_find == stock1 or single_stock_find == stock2
def verify(t: unittest.TestCase, run: kfp_server_api.ApiRun, tasks: dict[str, KfpTask], **kwargs): t.assertEqual(run.status, 'Succeeded') # assert DAG structure t.assertCountEqual(tasks.keys(), ['args-generator-op', 'for-loop-1']) t.assertCountEqual( ['for-loop-1-#0', 'for-loop-1-#1', 'for-loop-1-#2'], tasks['for-loop-1'].children.keys(), ) # assert all iteration parameters t.assertCountEqual( ['1.1', '1.2', '1.3'], [ x.inputs. parameters['pipelinechannel--args-generator-op-Output-loop-item'] for x in tasks['for-loop-1'].children.values() ], ) # assert 1 iteration task t.assertEqual( { 'name': 'for-loop-1-#0', 'type': 'system.DAGExecution', 'state': Execution.State.RUNNING, # TODO(Bobgy): this should be COMPLETE 'inputs': { 'parameters': { 'pipelinechannel--args-generator-op-Output-loop-item': '1.1' } }, 'outputs': {}, }, tasks['for-loop-1'].children['for-loop-1-#0'].get_dict(), ) t.assertEqual( { 'name': 'print-op', 'type': 'system.ContainerExecution', 'state': Execution.State.COMPLETE, 'inputs': { 'parameters': { 's': '1.1', } }, 'outputs': {}, }, tasks['for-loop-1'].children['for-loop-1-#0'].children['print-op']. get_dict(), )
def verify(t: unittest.TestCase, run: kfp_server_api.ApiRun, tasks: dict[str, KfpTask], **kwargs): t.assertEqual(run.status, 'Succeeded') t.assertCountEqual(['importer', 'train'], tasks.keys(), 'task names') importer = tasks['importer'] train = tasks['train'] t.assertEqual( 'gs://ml-pipeline-playground/shakespeare1.txt', importer.outputs.artifacts[0].uri, 'output artifact uri of importer should be "gs://ml-pipeline-playground/shakespeare1.txt"' ) t.assertEqual( 'gs://ml-pipeline-playground/shakespeare1.txt', train.inputs.artifacts[0].uri, 'input artifact uri of train should be "gs://ml-pipeline-playground/shakespeare1.txt"' ) importer_dict = importer.get_dict() train_dict = train.get_dict() for artifact in importer_dict.get('outputs').get('artifacts'): # pop metadata here because the artifact which got re-imported may have metadata with uncertain data if artifact.get('metadata') is not None: artifact.pop('metadata') for artifact in train_dict.get('inputs').get('artifacts'): # pop metadata here because the artifact which got re-imported may have metadata with uncertain data if artifact.get('metadata') is not None: artifact.pop('metadata') t.assertEqual( { 'name': 'importer', 'inputs': {}, 'outputs': { 'artifacts': [{ 'name': 'artifact', 'type': 'system.Artifact', # 'type': 'system.Dataset', }], }, 'type': 'system.ImporterExecution', 'state': Execution.State.COMPLETE, }, importer_dict) t.assertEqual( { 'name': 'train', 'inputs': { 'artifacts': [{ 'name': 'dataset', # TODO(chesu): compiled pipeline spec incorrectly sets importer artifact type to system.Artifact, but in the pipeline, it should be system.Dataset. 'type': 'system.Artifact', # 'type': 'system.Dataset' }], }, 'outputs': { 'artifacts': [{ 'metadata': { 'display_name': 'model' }, 'name': 'model', 'type': 'system.Model' }], 'parameters': { 'scalar': '123' } }, 'type': 'system.ContainerExecution', 'state': Execution.State.COMPLETE, }, train_dict)
def verify_tasks(t: unittest.TestCase, tasks: dict[str, KfpTask]): task_names = [*tasks.keys()] t.assertCountEqual(task_names, ['train-op', 'preprocess'], 'task names') preprocess = tasks['preprocess'] train = tasks['train-op'] pprint('======= preprocess task =======') pprint(preprocess.get_dict()) pprint('======= train task =======') pprint(train.get_dict()) pprint('==============') t.assertEqual( { 'name': 'preprocess', 'inputs': { 'artifacts': [], 'parameters': { 'some_int': 1234, 'uri': 'uri-to-import' } }, 'outputs': { 'artifacts': [{ 'metadata': { 'display_name': 'output_dataset_one', }, 'name': 'output_dataset_one', 'type': 'system.Dataset' }], 'parameters': { 'output_parameter_one': 1234 } }, 'type': 'system.ContainerExecution', 'state': Execution.State.COMPLETE, }, preprocess.get_dict()) t.assertEqual( { 'name': 'train-op', 'inputs': { 'artifacts': [{ 'metadata': { 'display_name': 'output_dataset_one', }, 'name': 'dataset', 'type': 'system.Dataset', }], 'parameters': { 'num_steps': 1234 } }, 'outputs': { 'artifacts': [{ 'metadata': { 'display_name': 'model', }, 'name': 'model', 'type': 'system.Model', }], 'parameters': {} }, 'type': 'system.ContainerExecution', 'state': Execution.State.COMPLETE, }, train.get_dict())
def verify_tasks(t: unittest.TestCase, tasks: dict[str, KfpTask], task_state, uri: str, some_int: int): task_names = [*tasks.keys()] t.assertCountEqual(task_names, ['train-op', 'preprocess'], 'task names') preprocess = tasks['preprocess'] train = tasks['train-op'] t.assertEqual( { 'name': 'preprocess', 'inputs': { 'artifacts': [], 'parameters': { 'some_int': some_int, 'uri': uri } }, 'outputs': { 'artifacts': [{ 'metadata': { 'display_name': 'output_dataset_one', }, 'name': 'output_dataset_one', 'type': 'system.Dataset' }], 'parameters': { 'output_parameter_one': some_int } }, 'type': 'system.ContainerExecution', 'state': task_state, }, preprocess.get_dict()) t.assertEqual( { 'name': 'train-op', 'inputs': { 'artifacts': [{ 'metadata': { 'display_name': 'output_dataset_one', }, 'name': 'dataset', 'type': 'system.Dataset', }], 'parameters': { 'num_steps': some_int } }, 'outputs': { 'artifacts': [{ 'metadata': { 'display_name': 'model', }, 'name': 'model', 'type': 'system.Model', }], 'parameters': {} }, 'type': 'system.ContainerExecution', 'state': task_state, }, train.get_dict())
def verify(t: unittest.TestCase, run: kfp_server_api.ApiRun, tasks: dict[str, KfpTask], **kwargs): t.assertEqual(run.status, 'Succeeded') task_names = [*tasks.keys()] t.assertCountEqual(task_names, [ 'wine-classification', 'iris-sgdclassifier', 'digit-classification', 'html-visualization', 'markdown-visualization' ], 'task names') wine_classification = tasks['wine-classification'] iris_sgdclassifier = tasks['iris-sgdclassifier'] digit_classification = tasks['digit-classification'] html_visualization = tasks['html-visualization'] markdown_visualization = tasks['markdown-visualization'] t.assertEqual( { 'name': 'wine-classification', 'inputs': {}, 'outputs': { 'artifacts': [{ 'metadata': { 'display_name': 'metrics', 'confidenceMetrics': { 'list': [{ 'confidenceThreshold': 2.0, 'falsePositiveRate': 0.0, 'recall': 0.0 }, { 'confidenceThreshold': 1.0, 'falsePositiveRate': 0.0, 'recall': 0.33962264150943394 }, { 'confidenceThreshold': 0.9, 'falsePositiveRate': 0.0, 'recall': 0.6037735849056604 }, { 'confidenceThreshold': 0.8, 'falsePositiveRate': 0.0, 'recall': 0.8490566037735849 }, { 'confidenceThreshold': 0.6, 'falsePositiveRate': 0.0, 'recall': 0.8867924528301887 }, { 'confidenceThreshold': 0.5, 'falsePositiveRate': 0.0125, 'recall': 0.9245283018867925 }, { 'confidenceThreshold': 0.4, 'falsePositiveRate': 0.075, 'recall': 0.9622641509433962 }, { 'confidenceThreshold': 0.3, 'falsePositiveRate': 0.0875, 'recall': 1.0 }, { 'confidenceThreshold': 0.2, 'falsePositiveRate': 0.2375, 'recall': 1.0 }, { 'confidenceThreshold': 0.1, 'falsePositiveRate': 0.475, 'recall': 1.0 }, { 'confidenceThreshold': 0.0, 'falsePositiveRate': 1.0, 'recall': 1.0 }] } }, 'name': 'metrics', 'type': 'system.ClassificationMetrics' }], }, 'type': 'system.ContainerExecution', 'state': Execution.State.COMPLETE, }, wine_classification.get_dict()) t.assertEqual( { 'inputs': { 'parameters': { 'test_samples_fraction': 0.3 } }, 'name': 'iris-sgdclassifier', 'outputs': { 'artifacts': [{ 'metadata': { 'display_name': 'metrics', 'confusionMatrix': { 'struct': { 'annotationSpecs': [{ 'displayName': 'Setosa' }, { 'displayName': 'Versicolour' }, { 'displayName': 'Virginica' }], 'rows': [ { # these numbers can be random during execution 'row': [mock.ANY, mock.ANY, mock.ANY] }, { 'row': [mock.ANY, mock.ANY, mock.ANY] }, { 'row': [mock.ANY, mock.ANY, mock.ANY] } ] } } }, 'name': 'metrics', 'type': 'system.ClassificationMetrics' }], }, 'type': 'system.ContainerExecution', 'state': Execution.State.COMPLETE, }, iris_sgdclassifier.get_dict()) rows = iris_sgdclassifier.get_dict()['outputs']['artifacts'][0][ 'metadata']['confusionMatrix']['struct']['rows'] for i, row in enumerate(rows): for j, item in enumerate(row['row']): t.assertIsInstance( item, float, f'value of confusion matrix row {i}, col {j} is not a number') t.assertEqual( { 'name': 'digit-classification', 'inputs': {}, 'outputs': { 'artifacts': [{ 'metadata': { 'display_name': 'metrics', 'accuracy': 92.0, }, 'name': 'metrics', 'type': 'system.Metrics' }], }, 'type': 'system.ContainerExecution', 'state': Execution.State.COMPLETE, }, digit_classification.get_dict()) t.assertEqual( { 'name': 'html-visualization', 'inputs': {}, 'outputs': { 'artifacts': [{ 'metadata': { 'display_name': 'html_artifact' }, 'name': 'html_artifact', 'type': 'system.HTML' }], }, 'state': Execution.State.COMPLETE, 'type': 'system.ContainerExecution' }, html_visualization.get_dict()) t.assertEqual( { 'name': 'markdown-visualization', 'inputs': {}, 'outputs': { 'artifacts': [{ 'metadata': { 'display_name': 'markdown_artifact' }, 'name': 'markdown_artifact', 'type': 'system.Markdown' }], }, 'state': Execution.State.COMPLETE, 'type': 'system.ContainerExecution' }, markdown_visualization.get_dict())
# print(dp[-1]) ''' almost but len != k return list(map(lambda i: list(i) if len(i), list(dp[-1]))) ''' res = [] for t in dp[-1]: if len(t) == k and max(t) < 10: res.append(list(t)) return res if __name__ == '__main__': t = TestCase() s = Solution() t.assertCountEqual([[1, 4], [2, 3]], s.combinationSum3(2, 5)) t.assertCountEqual([[1, 2, 4]], s.combinationSum3(3, 7)) t.assertCountEqual([[1, 2, 6], [1, 3, 5], [2, 3, 4]], s.combinationSum3(3, 9)) t.assertCountEqual([], s.combinationSum3(4, 1)) t.assertCountEqual([], s.combinationSum3(3, 2)) t.assertCountEqual([[1, 2, 3, 4, 5, 6, 7, 8, 9]], s.combinationSum3(9, 45)) t.assertCountEqual( [[1, 5, 9], [1, 6, 8], [2, 4, 9], [2, 5, 8], [2, 6, 7], [3, 4, 8], [3, 5, 7], [4, 5, 6]], #[1,3,11],[1,4,10],[1,2,12],[2,3,10] has number grater than 9 s.combinationSum3(3, 15)) ''' 3 15
uf = Dsu(alphabet) for (u, v), w in zip(equations, values): uf.union(u, v, w) ans = [] for u, v in queries: if u in alphabet and v in alphabet: pu, vu = uf.find(u) pv, vv = uf.find(v) if pu == pv: ans.append(vu / vv) else: ans.append(-1) else: ans.append(-1) return ans if __name__ == '__main__': t = TestCase() s = Solution() t.assertCountEqual([6.00000,0.50000,-1.00000,1.00000,-1.00000], s.calcEquation( equations = [["a", "b"], ["b", "c"], ['c', 'd'], ['e', 'd']], values = [2.0, 3.0, 5, 2], queries = [["a","c"], ["b","a"], ["a","e"], ["a","a"], ["x","x"]] )) t.assertCountEqual([6.00000,0.50000,-1.00000,1.00000,-1.00000], s.calcEquation( equations = [["a","b"],["b","c"]], values = [2.0, 3.0], queries = [["a","c"], ["b","a"], ["a","e"], ["a","a"], ["x","x"]] )) print('OK!')
while r > h: # forward, backward n, h = cutforth(snum, h, r, n) if n == None: break res.append(n) n, r = cutback(snum, h, r, n) if n == None: break res.append(n) return res if __name__ == "__main__": t = TestCase() t.assertCountEqual([3, 8, 14, 35, 159], parsNums('31415926538')) t.assertCountEqual([3, 5, 14, 62, 159], parsNums('314159265')) t.assertCountEqual([2, 7, 16], parsNums('201617')) t.assertCountEqual([1, 9, 23, 87, 456], parsNums('123456789')) t.assertCountEqual([1, 4, 22, 44, 333], parsNums('1223334444')) t.assertCountEqual([2, 8, 71, 281, 828], parsNums('2718281828')) t.assertCountEqual([1, 12, 22, 23], parsNums('12233221')) t.assertCountEqual([5, 50], parsNums('5005')) t.assertCountEqual([2, 5], parsNums('250')) t.assertCountEqual([9], parsNums('9')) print('OK!')
def verify_heads(t: unittest.TestCase, run: kfp_server_api.ApiRun, tasks: dict[str, KfpTask], **kwargs): t.assertEqual(run.status, 'Succeeded') t.assertCountEqual(['print-msg', 'condition-1', 'flip-coin'], tasks.keys()) t.assertCountEqual(['print-msg-2', 'print-msg-3', 'flip-coin-2'], tasks['condition-1'].children.keys())
from unittest import TestCase from typing import List class Solution: ''' 17.09% ''' def subsets(self, nums: List[int]) -> List[List[int]]: if len(nums) == 0: return [] elif len(nums) == 1: return [[], nums] res = [] trackings = self.subsets(nums[1:]) for trk in trackings: trk = trk[:] trk.insert(0, nums[0]) res.append(trk) res.extend(trackings) return res if __name__ == '__main__': t = TestCase() s = Solution() t.assertCountEqual([[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]], s.subsets([1, 2, 3])) t.assertCountEqual([[], [0]], s.subsets([0])) t.assertCountEqual([[], [1], [3], [1, 3]], s.subsets([1, 3])) print('OK!')
buf.append(arr[hi + 1]) hi += 1 elif 0 < low: buf.insert(0, arr[low - 1]) low -= 1 else: break return buf if __name__ == '__main__': t = TestCase() s = SolutionUnsorted() t.assertCountEqual([1], s.findClosestElements([1, 3], 1, 2)) t.assertCountEqual([-2, -1, 1, 2, 3, 4, 5], s.findClosestElements([-2, -1, 1, 2, 3, 4, 5], 7, 3)) t.assertCountEqual([10], s.findClosestElements([1, 1, 1, 10, 10, 10], 1, 9)) t.assertCountEqual([10, 10, 10], s.findClosestElements([1, 1, 1, 10, 10, 10], 3, 9)) t.assertCountEqual([1, 10, 10, 10], s.findClosestElements([1, 1, 1, 10, 10, 10], 4, 9)) t.assertCountEqual([1, 1, 10, 10, 10], s.findClosestElements([1, 1, 1, 10, 10, 10], 5, 9)) t.assertCountEqual([1], s.findClosestElements([1], 1, 1)) t.assertCountEqual([1, 2], s.findClosestElements([1, 2, 3], 2, 1)) t.assertCountEqual([1, 2, 3, 4], s.findClosestElements([1, 2, 3, 4, 5], 4, 3))
for p in bank: v = bank[p] res.append("{} {}".format(p.strip(), v)) return res def outputLines(ss): f = open('gift1.out', 'w') for s in ss: f.write(s + '\n') f.close() if __name__ == 'gift1': from unittest import TestCase print(__name__) t = TestCase() g = GiftGame() t.assertCountEqual( ["dave 302", "laura 66", "owen -359", "vick 141", "amr -150"], g.gift(open("gift1_1.in").readlines())) else: g = GiftGame() fin = open('gift1.in', 'r') ans = g.gift(fin.readlines()) fin.close() outputLines(ans) print('OK!')
days[d13 % 7] += 1 mth = m % 12 d13 += leaps[mth] if isleap(m // 12 + startyear) else months[mth] m += 1 # 13th falls on Saturday, Sunday, Monday, Tuesday, ..., Friday. days.insert(0, days.pop(-1)) return list(map(lambda x: str(x), days)) if __name__ != "__main__": # PyUnit t = TestCase() r = Friday() ans = r.days(2021, 5, 1) print(ans) t.assertCountEqual(['1', '2', '2', '2', '1', '1', '3'], ans) fin = open('friday.in', 'r') ans = r.days(1900, 1, fin.readlines()[0]) print(ans) t.assertCountEqual(['36', '33', '34', '33', '35', '35', '34'], ans) print('OK!') else: # main r = Friday() fin = open('friday.in', 'r') ans = r.days(1900, 1, fin.readlines()[0]) fin.close() fo = open('friday.out', 'w') fo.write(' '.join(ans) + '\n') fo.close()
for i in range(len(nums)): if val == nums[i]: continue i0 += 1 nums[i0] = nums[i] return min(i0 + 1, len(nums)) if __name__ == '__main__': t = TestCase() s = Solution() l = [1, 1, 2] c = s.removeElement(l, 2) t.assertEqual(2, c) t.assertCountEqual([1, 1], l[0:c]) l = [1, 1, 2, 3] c = s.removeElement(l, 1) t.assertEqual(2, c) t.assertCountEqual([2, 3], l[0:c]) l = [] c = s.removeElement(l, 1) t.assertEqual(0, c) t.assertCountEqual([], l[0:c]) l = [1] c = s.removeElement(l, 1) t.assertEqual(0, c) t.assertCountEqual([], l[0:c])
class Solution: def findRedundantConnection(self, edges: List[List[int]]) -> List[int]: dsu = DSU(len(edges) + 1) for e in edges: if not dsu.union(*e): return e print('No cycle...') if __name__ == '__main__': t = TestCase() s = Solution() t.assertCountEqual([1, 3], s.findRedundantConnection([[1, 2], [2, 3], [1, 3]])) t.assertCountEqual([2, 5], s.findRedundantConnection([[3, 4], [1, 2], [2, 4], [3, 5], [2, 5]])) t.assertCountEqual([3, 10], s.findRedundantConnection([[7, 8], [2, 6], [2, 8], [1, 4], [9, 10], [1, 7], [3, 9], [6, 9], [3, 5], [3, 10]])) t.assertCountEqual([5, 25], s.findRedundantConnection([[6, 13], [15, 22], [10, 13], [12, 24], [3, 23], [19, 20], [3, 12], [2, 16], [19, 23], [2, 11], [18, 23], [1, 25], [2, 17], [4, 5], [14, 19], [2, 3], [1, 7], [4, 6],
def countBits(self, num: int) -> List[int]: _1s = [None] * (num + 1) _1s[0] = 0 def count1(n) : if n == 0: return 0 elif _1s[n] is not None: return _1s[n] ci = 0 if n % 2 == 1: ci += 1 n //= 2 _1s[n] = count1(n) return ci + _1s[n] for i in range(1, num + 1): if _1s[i] is None: _1s[i] = count1(i) return _1s if __name__ == '__main__': t = TestCase() s = Solution() t.assertCountEqual([0, 1, 1, 2, 1, 2], s.countBits(5)) t.assertCountEqual([0, 1, 1], s.countBits(2)) t.assertCountEqual([0, 1, 1, 2, 1, 2, 2, 3, 1], s.countBits(8)) print('OK!')
if c < n: dp[r][c] = mat[r][c] + dp[r][c-1] else: dp[r][c] = dp[r][c-1] for c in range(n+K): for r in range(1, m+K): if r < m: dp[r][c] += dp[r-1][c] else: dp[r][c] = dp[r-1][c] for r in range(m): for c in range(n): mat[r][c] = dp[r+K][c+K] if 0 <= r - K - 1: mat[r][c] -= dp[r-K-1][c+K] if 0 <= c - K - 1: mat[r][c] -= dp[r+K][c-K-1] if 0 <= r - K - 1 and 0 <= c - K - 1: mat[r][c] += dp[r-K-1][c-K-1] return mat if __name__ == '__main__': t = TestCase() s = Solution() t.assertCountEqual([[12,21,16],[27,45,33],[24,39,28]], s.matrixBlockSum([[1,2,3],[4,5,6],[7,8,9]], 1)) t.assertCountEqual([[45,45,45],[45,45,45],[45,45,45]], s.matrixBlockSum([[1,2,3],[4,5,6],[7,8,9]], 2)) print("OK!")
def test_device_info(s): tc = TestCase() info = s.device_info('SyncthingManagerTestDevice1') tc.assertCountEqual(['id', 'index', 'folders', 'name'], list(info.keys())) assert info['index'] != None assert info['folders'] == []
l += 1 else: i += l break if nxt != None and least < nxt: least = nxt else: least = None print(res) return ' '.join(res) if __name__ == "__main__": t = TestCase() t.assertCountEqual('3 5 6 29 51', leastNums('1314159265')) t.assertCountEqual('1 4 43 322', leastNums('11223344')) t.assertCountEqual('25 75 279', leastNums('225897257')) t.assertCountEqual('25 75 279', leastNums('225897257')) t.assertCountEqual('1234 2534 8765 67892', leastNums('412342987656784352')) t.assertCountEqual('398 1234 3567 17654', leastNums('33984567176534321')) t.assertCountEqual('1 5 54 312 318 532', leastNums('111235813213455')) t.assertCountEqual('19 71 287', leastNums('219782017')) t.assertCountEqual('2016', leastNums('420165102')) t.assertCountEqual('66 505 813 5765 54221', leastNums('26625122455675318505')) t.assertCountEqual('643', leastNums('364311')) t.assertCountEqual('0 1 2 22 33 44 55', leastNums('105544332221')) t.assertCountEqual('0 1 2 22 33 44 55', leastNums('10550440330022021'))
def assertIntsEqual(a: List[int], b: List[int]) -> None: t = TestCase() t.assertEqual(len(a), len(b)) a, b = sorted(a), sorted(b) for x in range(len(a)): t.assertCountEqual(a[x], b[x])