How to use get_expected_result method in Slash

Best Python code snippet using slash

27_testing.py

Source:27_testing.py Github

copy

Full Screen

...22get_array() returns an empty array23In the class TestDataUniqueValues:2425get_array() returns an array of size at least 2 with all unique elements26get_expected_result() returns the expected minimum value index for this array27In the class TestDataExactlyTwoDifferentMinimums:2829get_array() returns an array where the minimum value occurs at exactly 2 indices30get_expected_result() returns the expected index31Take a look at the code template to see the exact implementation of functions that your colleague already implemented.3233Note: The arrays are indexed from .0'''3435def minimum_index(seq):36 if len(seq) == 0:37 raise ValueError("Cannot get the minimum value index from an empty sequence")38 min_idx = 039 for i in range(1, len(seq)):40 if seq[i] < seq[min_idx]:41 min_idx = i42 return min_idx4344class TestDataEmptyArray(object):45 46 @staticmethod47 def get_array():48 return list()4950class TestDataUniqueValues(object):5152 @staticmethod53 def get_array():54 return [7,9,1,2,-7,10,22]5556 @staticmethod57 def get_expected_result():58 return 45960class TestDataExactlyTwoDifferentMinimums(object):6162 @staticmethod63 def get_array():64 return [7,9,1,2,-7,10,22,-7]6566 @staticmethod67 def get_expected_result():68 return 4697071def TestWithEmptyArray():72 try:73 seq = TestDataEmptyArray.get_array()74 result = minimum_index(seq)75 except ValueError as e:76 pass77 else:78 assert False798081def TestWithUniqueValues():82 seq = TestDataUniqueValues.get_array()83 assert len(seq) >= 28485 assert len(list(set(seq))) == len(seq)8687 expected_result = TestDataUniqueValues.get_expected_result()88 result = minimum_index(seq)89 assert result == expected_result909192def TestiWithExactyTwoDifferentMinimums():93 seq = TestDataExactlyTwoDifferentMinimums.get_array()94 assert len(seq) >= 295 tmp = sorted(seq)96 assert tmp[0] == tmp[1] and (len(tmp) == 2 or tmp[1] < tmp[2])9798 expected_result = TestDataExactlyTwoDifferentMinimums.get_expected_result()99 result = minimum_index(seq)100 assert result == expected_result101102TestWithEmptyArray()103TestWithUniqueValues()104TestiWithExactyTwoDifferentMinimums()105106107def TestWithEmptyArray():108 try:109 seq = TestDataEmptyArray.get_array()110 result = minimum_index(seq)111 except ValueError as e:112 pass113 else:114 assert False115116117def TestWithUniqueValues():118 seq = TestDataUniqueValues.get_array()119 assert len(seq) >= 2120121 assert len(list(set(seq))) == len(seq)122123 expected_result = TestDataUniqueValues.get_expected_result()124 result = minimum_index(seq)125 assert result == expected_result126127128def TestiWithExactyTwoDifferentMinimums():129 seq = TestDataExactlyTwoDifferentMinimums.get_array()130 assert len(seq) >= 2131 tmp = sorted(seq)132 assert tmp[0] == tmp[1] and (len(tmp) == 2 or tmp[1] < tmp[2])133134 expected_result = TestDataExactlyTwoDifferentMinimums.get_expected_result()135 result = minimum_index(seq)136 assert result == expected_result137138TestWithEmptyArray()139TestWithUniqueValues()140TestiWithExactyTwoDifferentMinimums() ...

Full Screen

Full Screen

Day 27.py

Source:Day 27.py Github

copy

Full Screen

...15# for i in range(1, len(seq)):16# if a[i] < a[min_idx]:17# min_idx = i18# return min_idx19#Another co-worker has prepared functions that will perform the testing and validate returned results with expectations. Your task is to implement classes that will produce test data and the expected results for the testing functions. More specifically: function get_array() in TestDataEmptyArray class and functions get_array() and get_expected_result() in classes TestDataUniqueValues and TestDataExactlyTwoDifferentMinimums following the below specifications:2021#get_array() method in class TestDataEmptyArray has to return an empty array.22#get_array() method in class TestDataUniqueValues has to return an array of size at least 2 with all unique elements, while method get_expected_result() of this class has to return the expected minimum value index for this array.23#get_array() method in class TestDataExactlyTwoDifferentMinimums has to return an array where there are exactly two different minimum values, while method get_expected_result() of this class has to return the expected minimum value index for this array.24#Take a look at the code2526def minimum_index(seq):2728 if len(seq) == 0:29 raise ValueError("Cannot get the minimum value index from an empty sequence")30 min_idx = 031 for i in range(1, len(seq)):32 if seq[i] < seq[min_idx]:33 min_idx = i34 return min_idx353637class TestDataEmptyArray(object):38 @staticmethod39 def get_array():40 return []4142class TestDataUniqueValues(object):4344 @staticmethod45 def get_array():46 return [4,1,6,2]4748 @staticmethod49 def get_expected_result():50 return 15152class TestDataExactlyTwoDifferentMinimums(object):53 @staticmethod54 def get_array():55 return [6,3,1,1]56 @staticmethod57 def get_expected_result():58 return 259def TestWithEmptyArray():60 try:61 seq = TestDataEmptyArray.get_array()62 result = minimum_index(seq)63 except ValueError as e:64 pass65 else:66 assert False676869def TestWithUniqueValues():70 seq = TestDataUniqueValues.get_array()71 assert len(seq) >= 27273 assert len(list(set(seq))) == len(seq)7475 expected_result = TestDataUniqueValues.get_expected_result()76 result = minimum_index(seq)77 assert result == expected_result787980def TestiWithExactyTwoDifferentMinimums():81 seq = TestDataExactlyTwoDifferentMinimums.get_array()82 assert len(seq) >= 283 tmp = sorted(seq)84 assert tmp[0] == tmp[1] and (len(tmp) == 2 or tmp[1] < tmp[2])8586 expected_result = TestDataExactlyTwoDifferentMinimums.get_expected_result()87 result = minimum_index(seq)88 assert result == expected_result899091TestWithEmptyArray()92TestWithUniqueValues()93TestiWithExactyTwoDifferentMinimums() ...

Full Screen

Full Screen

day27.py

Source:day27.py Github

copy

Full Screen

...3Your company needs a function that meets the following requirements:4For a given array of integers, the function returns the index of the element with the minimum value in the array. If there is more than one element with the minimum value, the returned index should be the smallest one.5If an empty array is passed to the function, it should raise an Exception.6Note: The arrays are indexed from .7Another co-worker has prepared functions that will perform the testing and validate returned results with expectations. Your task is to implement classes that will produce test data and the expected results for the testing functions. More specifically: function get_array() in TestDataEmptyArray class and functions get_array() and get_expected_result() in classes TestDataUniqueValues and TestDataExactlyTwoDifferentMinimums following the below specifications:8get_array() method in class TestDataEmptyArray has to return an empty array.9get_array() method in class TestDataUniqueValues has to return an array of size at least 2 with all unique elements, while method get_expected_result() of this class has to return the expected minimum value index for this array.10get_array() method in class TestDataExactlyTwoDifferentMinimums has to return an array where there are exactly two different minimum values, while method get_expected_result() of this class has to return the expected minimum value index for this array.11Take a look at the code template to see the exact implementation of functions that your colleagues already implemented.12"""13def minimum_index(seq):14 if len(seq) == 0:15 raise ValueError("Cannot get the minimum value index from an empty sequence")16 min_idx = 017 for i in range(1, len(seq)):18 if seq[i] < seq[min_idx]:19 min_idx = i20 return min_idx21class TestDataEmptyArray(object):22 23 @staticmethod24 def get_array():25 # complete this function26 return []27class TestDataUniqueValues(object):28 @staticmethod29 def get_array():30 # complete this function31 return [2,1,3,4]32 @staticmethod33 def get_expected_result():34 # complete this function35 return 136class TestDataExactlyTwoDifferentMinimums(object):37 @staticmethod38 def get_array():39 # complete this function40 return [2,1,3,1,5]41 @staticmethod42 def get_expected_result():43 # complete this function44 return 145def TestWithEmptyArray():46 try:47 seq = TestDataEmptyArray.get_array()48 result = minimum_index(seq)49 except ValueError as e:50 pass51 else:52 assert False53def TestWithUniqueValues():54 seq = TestDataUniqueValues.get_array()55 assert len(seq) >= 256 assert len(list(set(seq))) == len(seq)57 expected_result = TestDataUniqueValues.get_expected_result()58 result = minimum_index(seq)59 assert result == expected_result60def TestiWithExactyTwoDifferentMinimums():61 seq = TestDataExactlyTwoDifferentMinimums.get_array()62 assert len(seq) >= 263 tmp = sorted(seq)64 assert tmp[0] == tmp[1] and (len(tmp) == 2 or tmp[1] < tmp[2])65 expected_result = TestDataExactlyTwoDifferentMinimums.get_expected_result()66 result = minimum_index(seq)67 assert result == expected_result68TestWithEmptyArray()69TestWithUniqueValues()70TestiWithExactyTwoDifferentMinimums()...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful