How to use assert_in_range method in Testify

Best Python code snippet using Testify_python

dnn_benchmark_test.py

Source:dnn_benchmark_test.py Github

copy

Full Screen

...76 input_fn = test_data.iris_input_logistic_fn77 steps = 40078 metrics = classifier.fit(input_fn=input_fn, steps=steps).evaluate(79 input_fn=input_fn, steps=1)80 estimator_test_utils.assert_in_range(steps, steps + 5, 'global_step',81 metrics)82 estimator_test_utils.assert_in_range(0.9, 1.0, 'accuracy', metrics)83 estimator_test_utils.assert_in_range(0.0, 0.3, 'loss', metrics)84 self._report_metrics(metrics)85 def benchmarkLogisticMatrixDataLabels1D(self):86 def _input_fn():87 iris = test_data.prepare_iris_data_for_logistic_regression()88 return {89 'feature': constant_op.constant(90 iris.data, dtype=dtypes.float32)91 }, constant_op.constant(92 iris.target, shape=(100,), dtype=dtypes.int32)93 classifier = dnn.DNNClassifier(94 feature_columns=(feature_column.real_valued_column(95 'feature', dimension=4),),96 hidden_units=(3, 3),97 config=run_config.RunConfig(tf_random_seed=1))98 steps = 100099 metrics = classifier.fit(input_fn=_input_fn, steps=steps).evaluate(100 input_fn=_input_fn, steps=1)101 estimator_test_utils.assert_in_range(steps, steps + 5, 'global_step',102 metrics)103 estimator_test_utils.assert_in_range(0.9, 1.0, 'accuracy', metrics)104 self._report_metrics(metrics)105 def benchmarkLogisticNpMatrixData(self):106 classifier = dnn.DNNClassifier(107 feature_columns=(feature_column.real_valued_column(108 '', dimension=4),),109 hidden_units=(3, 3),110 config=run_config.RunConfig(tf_random_seed=1))111 iris = test_data.prepare_iris_data_for_logistic_regression()112 train_x = iris.data113 train_y = iris.target114 steps = 100115 metrics = classifier.fit(x=train_x, y=train_y, steps=steps).evaluate(116 x=train_x, y=train_y, steps=1)117 estimator_test_utils.assert_in_range(steps, steps + 5, 'global_step',118 metrics)119 estimator_test_utils.assert_in_range(0.8, 1.0, 'accuracy', metrics)120 self._report_metrics(metrics)121 def benchmarkLogisticTensorData(self):122 def _input_fn(num_epochs=None):123 features = {124 'age':125 input_lib.limit_epochs(126 constant_op.constant(((.8,), (0.2,), (.1,))),127 num_epochs=num_epochs),128 'language':129 sparse_tensor.SparseTensor(130 values=input_lib.limit_epochs(131 ('en', 'fr', 'zh'), num_epochs=num_epochs),132 indices=((0, 0), (0, 1), (2, 0)),133 dense_shape=(3, 2))134 }135 return features, constant_op.constant(136 ((1,), (0,), (0,)), dtype=dtypes.int32)137 lang_column = feature_column.sparse_column_with_hash_bucket(138 'language', hash_bucket_size=20)139 classifier = dnn.DNNClassifier(140 feature_columns=(feature_column.embedding_column(141 lang_column, dimension=1),142 feature_column.real_valued_column('age')),143 hidden_units=(3, 3),144 config=run_config.RunConfig(tf_random_seed=1))145 steps = 100146 metrics = classifier.fit(input_fn=_input_fn, steps=steps).evaluate(147 input_fn=_input_fn, steps=1)148 estimator_test_utils.assert_in_range(steps, steps + 5, 'global_step',149 metrics)150 estimator_test_utils.assert_in_range(0.9, 1.0, 'accuracy', metrics)151 estimator_test_utils.assert_in_range(0.0, 0.3, 'loss', metrics)152 self._report_metrics(metrics)153 self._report_predictions(154 classifier=classifier,155 input_fn=functools.partial(_input_fn, num_epochs=1),156 iters=metrics['global_step'],157 n_examples=3,158 n_classes=2,159 expected_classes=(1, 0, 0))160 def benchmarkLogisticFloatLabel(self):161 def _input_fn(num_epochs=None):162 features = {163 'age':164 input_lib.limit_epochs(165 constant_op.constant(((50,), (20,), (10,))),166 num_epochs=num_epochs),167 'language':168 sparse_tensor.SparseTensor(169 values=input_lib.limit_epochs(170 ('en', 'fr', 'zh'), num_epochs=num_epochs),171 indices=((0, 0), (0, 1), (2, 0)),172 dense_shape=(3, 2))173 }174 return features, constant_op.constant(175 ((0.8,), (0.,), (0.2,)), dtype=dtypes.float32)176 lang_column = feature_column.sparse_column_with_hash_bucket(177 'language', hash_bucket_size=20)178 n_classes = 2179 classifier = dnn.DNNClassifier(180 n_classes=n_classes,181 feature_columns=(feature_column.embedding_column(182 lang_column, dimension=1),183 feature_column.real_valued_column('age')),184 hidden_units=(3, 3),185 config=run_config.RunConfig(tf_random_seed=1))186 steps = 1000187 metrics = classifier.fit(input_fn=_input_fn, steps=steps).evaluate(188 input_fn=_input_fn, steps=1)189 estimator_test_utils.assert_in_range(steps, steps + 5, 'global_step',190 metrics)191 # Prediction probabilities mirror the labels column, which proves that the192 # classifier learns from float input.193 self._report_metrics(metrics)194 self._report_predictions(195 classifier=classifier,196 input_fn=functools.partial(_input_fn, num_epochs=1),197 iters=metrics['global_step'],198 n_examples=3,199 n_classes=n_classes,200 expected_probabilities=((0.2, 0.8), (1., 0.), (0.8, 0.2)),201 expected_classes=(1, 0, 0))202 def benchmarkMultiClassMatrixData(self):203 """Tests multi-class classification using matrix data as input."""204 classifier = dnn.DNNClassifier(205 n_classes=3,206 feature_columns=(feature_column.real_valued_column(207 'feature', dimension=4),),208 hidden_units=(3, 3),209 config=run_config.RunConfig(tf_random_seed=1))210 input_fn = test_data.iris_input_multiclass_fn211 steps = 500212 metrics = classifier.fit(input_fn=input_fn, steps=steps).evaluate(213 input_fn=input_fn, steps=1)214 estimator_test_utils.assert_in_range(steps, steps + 5, 'global_step',215 metrics)216 estimator_test_utils.assert_in_range(0.9, 1.0, 'accuracy', metrics)217 estimator_test_utils.assert_in_range(0.0, 0.4, 'loss', metrics)218 self._report_metrics(metrics)219if __name__ == '__main__':...

Full Screen

Full Screen

numrangeregex.py

Source:numrangeregex.py Github

copy

Full Screen

...108 print("usage: numrageregex.py min max")109 sys.exit(1)110 min_, max_ = sys.argv[1:]111 print(generate_numeric_range_regex(int(min_), int(max_)))112# def assert_in_range(regex, min_, max_, lower, upper):113# import re114# pattern = re.compile(regex)115# for i in xrange(lower, upper):116# match = pattern.match(str(i))117# if min_ <= i <= max_:118# if match is None:119# print "ERROR", min_, max_, i120# return121# else:122# if match is not None:123# print "ERROR", min_, max_, i124# return125# def test_random_numbers():126# import random127# while True:128# min_1 = random.randint(0, 999999)129# max_1 = random.randint(min_1, 999999)130# regex_1 = generate_numeric_range_regex(min_1, max_1)131# min_2 = random.randint(0, 999)132# max_2 = random.randint(10000, 999999)133# regex_2 = generate_numeric_range_regex(min_2, max_2)134# try:135# assert_in_range(regex_1, min_1, max_1, 0, 1999999)136# assert_in_range(regex_2, min_2, max_2, 0, 1999999)137# except Exception, e:138# print e139# if __name__ == "__main__":140# regex = generate_numeric_range_regex(927, 496952)141# print regex142# assert_in_range(regex, 927, 496952, 0, 999999)143# regex = generate_numeric_range_regex(0, 111111)144# print regex145# assert_in_range(regex, 0, 111111, 0, 999999)...

Full Screen

Full Screen

test_rl.py

Source:test_rl.py Github

copy

Full Screen

1import numpy as np2import pytest3from rl2048.env import Env20484from rl2048.exp_buffer import ExperineReplayBuffer5def assert_in_range(a, l, h):6 assert np.max(a) <= h7 assert np.min(a) >= l8@pytest.mark.parametrize('reward_mode', ['dense', 'valid'])9def test_random_moves(reward_mode):10 env = Env2048()11 env.step_limit = 10012 exp_buffer = ExperineReplayBuffer()13 exp_buffer.size = 1014 for i in range(100):15 state = env.reset()16 while not env.done:17 action = np.random.randint(0, 4)18 next_state, reward, done = env.execute(action)19 exp_buffer.add(state, action, reward, env.done, next_state)20 assert_in_range(state, -1, 1)21 assert_in_range(next_state, -1, 1)22 assert_in_range(action, 0, 3)23 assert_in_range(reward, -1, 1)24 state, action, reward, finished, next_state = exp_buffer.sample(100)25 assert_in_range(state, -1, 1)26 assert_in_range(action, 0, 3)27 assert_in_range(reward, -1, 1)28 assert_in_range(finished, 0, 1)...

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