How to use test_percentile method in locust

Best Python code snippet using locust

ADSw6FindPercentile.py

Source:ADSw6FindPercentile.py Github

copy

Full Screen

...73 k -= count_discarded74 else: # k is in right part75 a_len = i76 b_len = j77def test_percentile(test_arr1, test_arr2, test_p, answer):78 random.seed(int(time.time()))79 percentile_result = find_percentile(test_arr1, test_arr2, test_p)80 error_str = 'Test failed!\nInput: {0}, {1}, {2}\nOutput: {3}\nCorrect output: {4}'81 assert percentile_result == answer, error_str.format(test_arr1, test_arr2, test_p, percentile_result, answer)82def run_unit_test():83 test_percentile([15, 15, 15], [12, 12, 12, 12], 50, 12)84 test_percentile([101, 118, 138, 175], [7, 11, 21, 45, 65], 91, 175)85 test_percentile([1], [], 50, 1)86 test_percentile([], [1], 50, 1)87 test_percentile([1], [0], 50, 0)88 test_percentile([1], [2, 3], 50, 2)89 test_percentile([2, 3], [1], 50, 2)90 test_percentile([], [1, 2, 3], 50, 2)91 test_percentile([1, 2, 7, 8, 10], [6, 12], 50, 7)92 test_percentile([15, 20, 35, 40, 50], [], 30, 20)93 test_percentile([15, 20], [25, 40, 50], 40, 20)94 test_percentile([55], [25, 40, 50], 20, 25)95 test_percentile([15], [25, 40, 50], 5, 15)96 test_percentile([15, 20], [25, 40, 50], 70, 40)97 test_percentile([15, 20, 55], [12, 25, 40, 50], 100, 55)98 test_percentile([15, 20, 55], [12, 25, 40, 50], 1, 12)99 print("Unit tests passed!")100def get_random_test(test_size1, test_size2, max_int1):101 a = []102 b = []103 if test_size1 == 0 and test_size2 == 0: # don't need to test 0,0104 return [1], [1], 1105 else:106 for i in range(test_size1):107 a.append(random.randint(0, max_int1))108 for i in range(test_size2):109 b.append(random.randint(0, max_int1))110 return sorted(a), sorted(b), random.randint(1, 100)111def partition(arr, l, r):112 x = arr[r]113 i = l114 for j in range(l, r):115 if arr[j] <= x:116 arr[i], arr[j] = arr[j], arr[i]117 i += 1118 arr[i], arr[r] = arr[r], arr[i]119 return i120def kthSmallest(arr, l, r, k):121 if k > 0 and k <= r - l + 1:122 index = partition(arr, l, r)123 if index - l == k - 1:124 return arr[index]125 if index - l > k - 1:126 return kthSmallest(arr, l, index - 1, k)127 return kthSmallest(arr, index + 1, r,128 k - index + l - 1)129 print("Index out of bound")130def run_stress_test(max_test_size=20, max_attempts=10, max_right_border=10):131 # random.seed(100)132 random.seed(int(time.time()))133 for test_size1 in range(0, max_test_size):134 for test_size2 in range(max_test_size, -1, -1):135 print('test_size = ', test_size1, test_size2)136 for right_border in range(0, max_right_border):137 for attempt in range(max_attempts):138 a, b, p = get_random_test(test_size1, test_size2, 200)139 k_float = p / 100 * (len(a) + len(b)) # ordinal rank140 if k_float.is_integer():141 k = int(k_float)142 else:143 k = math.floor(k_float) + 1144 test_percentile(a, b, p, kthSmallest(a+b, 0, len(a+b)-1, k))145 print('Stress test passed!')146# Array a len: 1000000 Array b len: 1000000 Max int in both arrays: 42147# find_percentile runs in 0.000995 seconds148def run_max_test():149 # random.seed(100)150 random.seed(int(time.time()))151 a, b, p = get_random_test(1000, 1000, 100000000)152 k_float = p / 100 * (len(a) + len(b)) # ordinal rank153 if k_float.is_integer():154 k = int(k_float)155 else:156 k = math.floor(k_float) + 1157 test_percentile(a, b, p, kthSmallest(a + b, 0, len(a + b) - 1, k))158 print('Max test passed!')159 # measure time160 a, b, p = get_random_test(1000000, 1000000, 100000000)161 print('Array a len:', len(a), 'Array b len:', len(b), 'Max int in both arrays:', p)162 start = time.time()163 answer = find_percentile(a, b, p)164 end = time.time()165 difference = end - start166 print("find_percentile runs % f seconds" % difference)167def main():168 run_unit_test()169 run_stress_test()170 run_max_test()171# some test code...

Full Screen

Full Screen

map_test_student_growth.py

Source:map_test_student_growth.py Github

copy

Full Screen

1# Copyright (c) 2020, ifitwala and contributors2# For license information, please see license.txt3from __future__ import unicode_literals4import frappe5from frappe import _6def execute(filters=None):7 if not filters:8 filters = {}9 columns = get_columns(filters)10 data = get_data(filters)11 chart = get_chart_data(data)12 return columns, data, None, chart13def get_columns(filters=None):14 columns = [15 {16 "label": _("Test Date"),17 "fieldname": "test_date",18 "fieldtype": "Date",19 "width": 10020 },21 {22 "label": _("Program"),23 "fieldname": "program",24 "fieldtype": "Link",25 "options": "Program",26 "width": 10027 },28 {29 "label": _("Student"),30 "fieldname": "student",31 "fieldtype": "Link",32 "options": "Student",33 "width": 15034 },35 {36 "label": _("Student Name"),37 "fieldname": "student_name",38 "fieldtype": "Data",39 "width": 15040 },41 {42 "label": _("Discipline"),43 "fieldname": "discipline",44 "fieldtype": "Data",45 "width": 15046 },47 {48 "label": _("RIT Score"),49 "fieldname": "test_rit_score",50 "fieldtype": "Data",51 "width": 8052 },53 {54 "label": _("Percentile"),55 "fieldname": "test_percentile",56 "fieldtype": "Data",57 "width": 8058 }59 ]60 return columns61def get_data(filters = None):62 data = []63 conditions = get_filter_conditions(filters)64 map_results = frappe.db.sql("""65 SELECT student, student_name, program, test_percentile, test_rit_score, academic_term, test_date, discipline66 FROM `tabMAP Test`67 WHERE68 docstatus = 0 %s69 ORDER BY70 test_date, discipline, test_rit_score""" % (conditions), as_dict=1)71 for test in map_results:72 data.append({73 'student': test.student,74 'discipline': test.discipline,75 'student_name': test.student_name,76 'program': test.program,77 'test_rit_score': test.test_rit_score,78 'test_percentile': test.test_percentile,79 'test_date': test.test_date,80 'academic_term': test.academic_term81 })82 return data83def get_chart_data(data):84 if not data:85 return None86 labels = []87 math = []88 reading = []89 language = []90 for entry in data:91 if entry.get("academic_term") not in labels:92 labels.append(entry.get("academic_term"))93 if entry.get("discipline") == "Mathematics":94 math.append(entry.get("test_percentile"))95 if entry.get("discipline") == "Reading":96 reading.append(entry.get("test_percentile"))97 if entry.get("discipline") == "Language":98 language.append(entry.get("test_percentile"))99 return {100 "data": {101 "labels": labels,102 "datasets": [103 {104 "name": _("Math Percentile"),105 "values": math106 },107 {108 "name": _("Reading Percentile"),109 "values": reading110 },111 {112 "name": _("Language Percentile"),113 "values": language114 }115 ]116 },117 "type": "line"118 }119def get_filter_conditions(filters):120 conditions = ""121 if filters.get("discipline"):122 conditions += " and discipline = '%s' " % (filters.get("discipline"))123 if filters.get("student"):124 conditions += " and student = '%s' " % (filters.get("student"))...

Full Screen

Full Screen

test_fluorescence.py

Source:test_fluorescence.py Github

copy

Full Screen

1import unittest2import numpy as np3import pandas as pd4from altFACS.fluorescence import *5# Define fixings6#Set the random seed to get a reproducible set of pseudorandom data7np.random.seed(1)8# Generate test DataFrame9test_df = pd.DataFrame()10test_df.loc[:,'FSC-A'] = np.random.normal(0, 1, 1000)11test_df.loc[:,'405nm'] = np.random.normal(0, 1, 1000)12test_df.loc[:,'488nm'] = np.random.normal(0, 1, 1000)13class TestFlourescence(unittest.TestCase):14 15 def test_autothresholdChannel(self):16 17 # Use test_df to generate expected threshold with no kwargs18 threshold_405nm = autothresholdChannel(test_df, '405nm')19 self.assertEqual(threshold_405nm, test_df['405nm'].quantile(0.999), "Threshold should be set at 99.9th percentile .")20 21 # Use test_df to generate expected threshold with percentile kwarg22 test_percentile = 0.523 threshold_405nm = autothresholdChannel(test_df, '405nm', percentile=test_percentile)24 self.assertEqual(threshold_405nm, test_df['405nm'].quantile(test_percentile), "Threshold should be set at 99.9th percentile .")25 26 # Use test_df to generate expected threshold with n_stdevs kwarg27 threshold_405nm = autothresholdChannel(test_df, '405nm', n_stdevs=1)28 self.assertEqual(threshold_405nm, test_df['405nm'].mean() + test_df['405nm'].std(), "Threshold should be set at mean+1*std .")29if __name__ == "__main__":...

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