How to use step_test method in autotest

Best Python code snippet using autotest_python

LengthTesting.py

Source:LengthTesting.py Github

copy

Full Screen

1import random2import numpy as np3import matplotlib.pyplot as plt4import timeit5678from string import ascii_lowercase9101112def plotter(r_k_time, b_f_time, kmp_time, time, filename):13 '''14 plots using information based on time15 '''16 plt.title(f'Complexity Analysis when m = 500')17 plt.plot(time, b_f_time, label="Brute Force")18 plt.plot(time, r_k_time,19 'tab:orange', label="Rabin Karp")20 plt.plot(time, kmp_time21 , 'tab:green', label="KMP")22 plt.xlabel("n")23 plt.ylabel('time in seconds')24 plt.legend()2526 plt.plot()27 plt.savefig(f"{filename}.png")28 print("plotted")293031def get_random_string(length, letters):32 '''33 Generates random string of length length using letters34 '''35 result_str = ''.join(random.choice(letters) for i in range(length))36 return result_str373839def insert(source_str, insert_str, pos):40 '''41 Fits a string into another string and results in a new string42 '''43 return source_str[:pos]+insert_str+source_str[pos:]4445start_test,end_test,step_test = 5000,1000001,500046times = list(range(start_test,end_test,step_test))4748b_f_temp = list(range(start_test,end_test,step_test))49r_k_temp = list(range(start_test,end_test,step_test))50kmp_temp = list(range(start_test,end_test,step_test))5152for i,n in enumerate(range(start_test,end_test,step_test)):53 pattern = get_random_string(500,ascii_lowercase)54 string_to_search = get_random_string(n-len(pattern), ascii_lowercase)55 string_to_search = insert(56 string_to_search, pattern, random.randint(0, len(string_to_search)-1))57 a = timeit.timeit(stmt="NaiveAlgorithm(pattern,text)",58 setup=f"from BruteForce import NaiveAlgorithm;text='{string_to_search}';pattern='{pattern}';", number=3)59 60 b = timeit.timeit(stmt=f"RabinKarp(pattern,text,524287)",61 setup=f"from RabinKarp import RabinKarp;text='{string_to_search}';pattern='{pattern}';", number=3)62 63 c = timeit.timeit(stmt="KMP_search(pattern,text)",64 setup=f"from Knuth import KMP_search;text='{string_to_search}';pattern='{pattern}';", number=3)65 b_f_temp[i] = a/366 r_k_temp[i] = b/367 kmp_temp[i] = c/368 import time69 if n % 100 == 0:70 print(n)71print("done") ...

Full Screen

Full Screen

test_cnn.py

Source:test_cnn.py Github

copy

Full Screen

1# file: test.py2#3# Restores a learned CNN model and tests it.4#5# Store your test images in a sub-folder for each6# class in <dataset_root>/validation/7# e.g.8# <dataset_root>/validation/bikes9# <dataset_root>/validation/cars10# 11# ---12# Prof. Dr. Juergen Brauer, www.juergenbrauer.org13from dataset_reader import dataset14dataset_root = "V:/01_job/12_datasets/imagenet/cars_vs_bikes_prepared/"15testing = dataset(dataset_root + "validation", ".jpeg")16import tensorflow as tf17import numpy as np18# Parameters19batch_size = 120ckpt = tf.train.get_checkpoint_state("saved_model_exp03")21saver = tf.train.import_meta_graph(ckpt.model_checkpoint_path + '.meta')22pred = tf.get_collection("pred")[0]23x = tf.get_collection("x")[0]24keep_prob = tf.get_collection("keep_prob")[0]25sess = tf.Session()26saver.restore(sess, ckpt.model_checkpoint_path)27# test28step_test = 029correct=030while step_test * batch_size < len(testing):31 # testing_ys and testing_xs are tuples32 testing_ys, testing_xs = testing.nextBatch(batch_size)33 # get first image and first ground truth vector34 # from the tuples35 first_img = testing_xs[0]36 first_groundtruth_vec = testing_ys[0]37 # at first iteration:38 # show shape of image and ground truth vector39 if step_test == 0:40 print("Shape of testing_xs is :", first_img.shape)41 print("Shape of testing_ys is :", first_groundtruth_vec.shape)42 # given the input image,43 # let the CNN predict the category!44 predict = sess.run(pred, feed_dict={x: testing_xs, keep_prob: 1.})45 # get ground truth label and46 # predicted label from output vector47 groundtruth_label = np.argmax(first_groundtruth_vec)48 predicted_label = np.argmax(predict, 1)[0]49 print("\nImage test: ", step_test)50 print("Ground truth label :", testing.label2category[groundtruth_label])51 print("Label predicted by CNN:", testing.label2category[predicted_label])52 if predicted_label == groundtruth_label:53 correct+=154 step_test += 155print("\n---")56print("Classified", correct, "images correct of", step_test,"in total.")...

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 autotest 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