Best Python code snippet using lemoncheesecake
tests.py
Source:tests.py
1import data_scilib.functions as f2def small_tests():3 print("\nStarting tests with small dataset.")4 analyzer = f.analyzer('tests_files/small_dataset.csv')5 first_test = analyzer.rows_num()6 print(f"\nCalculating how many rows (without header) the file has. Found: {first_test} rows.")7 second_test = analyzer.columns_num()8 print(f"\nCalculating how many columns the file has. Found: {second_test} columns.")9 third_test = analyzer.find_value_in_row('Username', 'Sam')10 print(f"\nLooking for value of column 'Username' in the row where value 'Sam' is present in any column. Found: {third_test[0]} is the value for 'Username' in the row where value 'Sam' is present.")11 fourth_test = analyzer.is_empty('Last name')12 print(f"\nLooking for the row where the value for column 'Last name' is empty. Found: row #{fourth_test[0]} has no value in column 'Last name'.")13 fifth_test = analyzer.count_if([14 ('Active', lambda x: x == "No"), 15 ('Age', lambda x: x >= 30), 16 ('Location', lambda x: x < 10) # Last condition will return 0 matches since you're trying to compare a string with a number. IMPORTANT: an exception will not be thrown.17 ])18 print(f"\nCalculating how many rows have the value 'No' in the 'Active' column. Found: {fifth_test[0]} rows.") 19 print(f"\nCalculating how many rows have a value greater than or equal to 30 in the 'Age' column. Found: {fifth_test[1]} rows.")20 print(f"\nCalculating how many rows have a value less than 10 in the 'Location' column. Found: {fifth_test[2]} rows. IMPORTANT: returns 0 because all values in 'Location' are strings.")21 sixth_test = analyzer.max_min([22 'Age',23 'First name', # will return ['-inf', 'inf'] since column has no numerical values24 ])25 print(f"\nLooking for the maximum and minimum value for 'Age' across all rows. Found: {sixth_test[0][0]} is the maximum and {sixth_test[0][1]} the minimum.")26 print(f"\nLooking for the maximum and minimum value for 'First name' across all rows. Found: {sixth_test[1][0]} is the maximum and {sixth_test[1][1]} the minimum. IMPORTANT: -inf and inf are returned since all values in 'Last name' are strings.")27def large_tests():28 print("\nStarting tests with large dataset.")29 analyzer = f.analyzer('tests_files/large_dataset.csv')30 first_test = analyzer.rows_num()31 print(f"\nCalculating how many rows (without header) the file has. Found: {first_test} rows.")32 second_test = analyzer.columns_num()33 print(f"\nCalculating how many columns the file has. Found: {second_test} columns.")34 third_test = analyzer.find_value_in_row('total_deaths', 'Mexico')35 print(f"\nLooking for value of column 'total_deaths' in the row where value 'Mexico' is present in any column. Found: {len(third_test)} rows, {third_test[-1]} is the value in column 'total_deaths' for the last found row.")36 fourth_test = analyzer.count_if([37 ('total_cases', lambda x: x >= 500000), 38 ('icu_patients', lambda x: x >= 1000),39 ('continent', lambda x: x == "Asia")40 ])41 print(f"\nCalculating how many rows have a value greater than or equal to 500,000 in the 'total_cases' column. Found: {fourth_test[0]} rows.") 42 print(f"\nCalculating how many rows have a value greater than or equal to 1,000 in the 'icu_patients' column. Found: {fourth_test[1]} rows.")43 print(f"\nCalculating how many rows have a value equal to 'Asia' in the 'continent' column. Found: {fourth_test[2]} rows.")44 fifth_test = analyzer.max_min([45 'total_cases',46 'total_deaths'47 ])48 print(f"\nLooking for the maximum and minimum value for 'total_cases' across all rows. Found: {fifth_test[0][0]} is the maximum and {fifth_test[0][1]} the minimum.")49 print(f"\nLooking for the maximum and minimum value for 'total_deaths' across all rows. Found: {fifth_test[1][0]} is the maximum and {fifth_test[1][1]} the minimum.")50 sixth_test = analyzer.average('new_deaths')51 print(f"\nCalculating average value for 'new_deaths' across all rows. Found: {sixth_test}.")52if __name__ == '__main__':53 small_tests()...
test.py
Source:test.py
1sequence_example = '@D15S4454D1I10V20D5V100#'2motor_state = 'stop'3def check(sequence):4 result = True5 first_test = True6 second_test = True7 third_test = True8 fourth_test = True9 # 1ra. letras correctas10 for i in range(0, len(sequence)):11 if not sequence[i].isdigit():12 if sequence[i] == 'D':13 first_test = True14 elif sequence[i] == 'I':15 first_test = True16 elif sequence[i] == 'V':17 first_test = True18 elif sequence[i] == 'S':19 first_test = True20 else:21 first_test = False22 print('Error #1: "Letra no reconocida"')23 break24 # 2da. final con letra o inicio con número25 end_char = sequence[len(sequence)-1:]26 start_char = sequence[:1]27 if not end_char.isdigit() or start_char.isdigit():28 second_test = False29 print('Error #2: "Secuencia con letra al final o número al principio"')30 # 3ra. comandos juntos o sin número31 for i in range(0, len(sequence)):32 if not sequence[i-1].isdigit() and not sequence[i].isdigit():33 third_test = False34 print('Error #3: "Comandos juntos o sin número"')35 break36 # 4ta. Velocidad invalida37 if third_test:38 for i in range(0, len(sequence)):39 if not sequence[i].isdigit():40 letter = sequence[i]41 new_sequence = sequence[i+1:]42 for j in range(0, len(new_sequence)):43 if not new_sequence[j].isdigit():44 value = int(new_sequence[:j])45 break46 if new_sequence.isdigit():47 value = int(new_sequence)48 if letter == 'V' and (value > 100 or value < 20):49 fourth_test = False50 print('Error #4: "Velocidad fuera de rango"')51 break52 # Resultado final53 if not (first_test and second_test and third_test and fourth_test):54 result = False55 return result56def analysis(sequence):57 for i in range(0, len(sequence)):58 if not sequence[i].isdigit():59 letter = sequence[i]60 new_sequence = sequence[i+1:]61 for j in range(0, len(new_sequence)):62 if not new_sequence[j].isdigit():63 value = new_sequence[:j]64 break65 if new_sequence.isdigit():66 value = int(new_sequence)67 # Metodo del motor68 print(letter, value)69def unpacking(raw_sequence):70 sequence = ''71 if(raw_sequence.count('@') == 1) and (raw_sequence.count('#') == 1):72 sequence = raw_sequence.strip("@#")73 return sequence74sequence = unpacking(sequence_example)75if check(sequence):...
main.py
Source:main.py
1from algorithms import brute_force, kmp, \2 rabin_karp_algorithm, boyer_moore_algorithm, kmpm, tw3from benchmark import benchmark4from alphabet import get_given, get_unknown5fourth_test = [[9, 10], [4, 5]]6fourth_givens = get_given(fourth_test)7fourth_unknowns = get_unknown(fourth_test)8best_options = []9medium_options = []10worst_options = []11best_unknowns = ["A"]12medium_unknowns = ["A"]13worst_unknowns = ["ABC"]14for i in range(1, 15):15 best_options.append("A" + "0" * 2 ** i)16 medium_options.append("0" * 2 ** i + "A")17 if i < 14:18 worst_options.append("AB" * 2 ** i + "ABC")19variants = [[best_options, best_unknowns],20 [medium_options, medium_unknowns],21 [worst_options, worst_unknowns]]22with open('test-memory.txt', 'w'):23 pass24realised_algorithms = [brute_force, kmp,25 rabin_karp_algorithm, boyer_moore_algorithm, kmpm, tw]26for e in realised_algorithms:27 for k in fourth_givens:28 for j in fourth_unknowns:29 for i in range(3):30 benchmark(e, k, j)31with open('test-memory.txt', 'a') as file_obj:32 file_obj.write("-\n")33for e in realised_algorithms:34 for k in variants:35 for j in k[0]:36 for i in range(5):...
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!!