How to use test_operators method in Molotov

Best Python code snippet using molotov_python

test_suites.py

Source:test_suites.py Github

copy

Full Screen

1import unittest2import test_aterm3import test_convenience4import test_expression5import test_full6import test_idx7import test_operators8import test_sc_rules9import test_term10import test_term_map11import test_test12import test_wick13def run_suite():14 suite = unittest.TestSuite()15 suite.addTest(test_test.TestTest("test_framework"))16 suite.addTest(test_aterm.ATermTest("test_mul"))17 suite.addTest(test_aterm.ATermTest("test_merge_external"))18 suite.addTest(test_aterm.ATermTest("test_term_map"))19 suite.addTest(test_aterm.ATermTest("test_tensor_sort"))20 suite.addTest(test_aterm.ATermTest("test_connected"))21 suite.addTest(test_aterm.ATermTest("test_reducible"))22 suite.addTest(test_aterm.ATermTest("test_eq"))23 suite.addTest(test_aterm.ATermTest("test_string"))24 suite.addTest(test_convenience.ConvenienceTest("testE1"))25 suite.addTest(test_convenience.ConvenienceTest("testE2"))26 suite.addTest(test_convenience.ConvenienceTest("testEip1"))27 suite.addTest(test_convenience.ConvenienceTest("testEip2"))28 suite.addTest(test_convenience.ConvenienceTest("testEdip1"))29 suite.addTest(test_convenience.ConvenienceTest("testEea1"))30 suite.addTest(test_convenience.ConvenienceTest("testEea2"))31 suite.addTest(test_convenience.ConvenienceTest("testEdea1"))32 suite.addTest(test_convenience.ConvenienceTest("testP1"))33 suite.addTest(test_convenience.ConvenienceTest("testP2"))34 suite.addTest(test_convenience.ConvenienceTest("testP1E1"))35 suite.addTest(test_convenience.ConvenienceTest("testP1Eip1"))36 suite.addTest(test_convenience.ConvenienceTest("testP1Eea1"))37 suite.addTest(test_convenience.ConvenienceTest("testP2E1"))38 suite.addTest(test_convenience.ConvenienceTest("testP1op"))39 suite.addTest(test_convenience.ConvenienceTest("testP2op"))40 suite.addTest(test_convenience.ConvenienceTest("testEP11op"))41 suite.addTest(test_expression.ExpressionTest("test_resolve0"))42 suite.addTest(test_expression.ExpressionTest("test_resolve1"))43 suite.addTest(test_expression.ExpressionTest("test_resolve2"))44 suite.addTest(test_expression.ExpressionTest("test_resolve3"))45 suite.addTest(test_expression.ExpressionTest("test_resolve_chain"))46 suite.addTest(test_expression.ExpressionTest("test_str"))47 suite.addTest(test_full.FullTest("test_ccsd_T1"))48 suite.addTest(test_full.FullTest("test_p2"))49 suite.addTest(test_idx.IdxTest("test_idx"))50 suite.addTest(test_idx.IdxTest("test_idx_str"))51 suite.addTest(test_idx.IdxTest("test_idx_occ"))52 suite.addTest(test_idx.IdxTest("test_idx_eq"))53 suite.addTest(test_operators.OperatorTest("test_foperator"))54 suite.addTest(test_operators.OperatorTest("test_boperator"))55 suite.addTest(test_operators.OperatorTest("test_projector"))56 suite.addTest(test_operators.OperatorTest("test_tensor"))57 suite.addTest(test_operators.OperatorTest("test_sigma"))58 suite.addTest(test_operators.OperatorTest("test_delta"))59 suite.addTest(test_operators.OperatorTest("test_dagger"))60 suite.addTest(test_operators.OperatorTest("test_string"))61 suite.addTest(test_operators.OperatorTest("test_inc"))62 suite.addTest(test_sc_rules.SCRulesTest("test_0d0"))63 suite.addTest(test_sc_rules.SCRulesTest("test_0d1"))64 suite.addTest(test_sc_rules.SCRulesTest("test_0d2"))65 suite.addTest(test_sc_rules.SCRulesTest("test_1d0a"))66 suite.addTest(test_sc_rules.SCRulesTest("test_1d1a"))67 suite.addTest(test_sc_rules.SCRulesTest("test_1d2a"))68 suite.addTest(test_sc_rules.SCRulesTest("test_1d0b"))69 suite.addTest(test_sc_rules.SCRulesTest("test_1d1b"))70 suite.addTest(test_sc_rules.SCRulesTest("test_1d2b"))71 suite.addTest(test_sc_rules.SCRulesTest("test_2d1a"))72 suite.addTest(test_sc_rules.SCRulesTest("test_2d2a"))73 suite.addTest(test_sc_rules.SCRulesTest("test_2d1b"))74 suite.addTest(test_sc_rules.SCRulesTest("test_2d2b"))75 suite.addTest(test_sc_rules.SCRulesTest("test_2d1c"))76 suite.addTest(test_sc_rules.SCRulesTest("test_2d2c"))77 suite.addTest(test_term_map.TermMapTest("test_null"))78 suite.addTest(test_term_map.TermMapTest("test_label"))79 suite.addTest(test_term.TermTest("test_scalar_mul"))80 suite.addTest(test_term.TermTest("test_mul"))81 suite.addTest(test_term.TermTest("test_mul2"))82 suite.addTest(test_term.TermTest("test_ilist"))83 suite.addTest(test_wick.WickTest("test_valid_contraction"))84 suite.addTest(test_wick.WickTest("test_pair_list"))85 suite.addTest(test_wick.WickTest("test_get_sign"))86 suite.addTest(test_wick.WickTest("test_split_operators"))87 suite.addTest(test_wick.WickTest("test_projector"))88 return suite89if __name__ == '__main__':90 runner = unittest.TextTestRunner()...

Full Screen

Full Screen

00411_accurate_number_comparison.py

Source:00411_accurate_number_comparison.py Github

copy

Full Screen

...42 if signed:43 return -2**(bits-1) <= value and value <= 2**(bits-1) - 144 else:45 return 0 <= value and value <= 2**bits - 146def test_operators(v1, v2, v1_passed, v2_passed):47 query_str = "{v1} = {v2}, {v1} != {v2}, {v1} < {v2}, {v1} <= {v2}, {v1} > {v2}, {v1} >= {v2},\t".format(v1=v1_passed, v2=v2_passed)48 query_str += "{v1} = {v2}, {v1} != {v2}, {v1} < {v2}, {v1} <= {v2}, {v1} > {v2}, {v1} >= {v2} ".format(v1=v2_passed, v2=v1_passed)49 answers = [v1 == v2, v1 != v2, v1 < v2, v1 <= v2, v1 > v2, v1 >= v2]50 answers += [v2 == v1, v2 != v1, v2 < v1, v2 <= v1, v2 > v1, v2 >= v1]51 answers_str = "\t".join([str(int(x)) for x in answers])52 return (query_str, answers_str)53VALUES = [x for x in get_values() if is_valid_integer(x)]54def test_pair(v1, v2):55 query = "SELECT {}, {}, ".format(v1, v2)56 answers = "{}\t{}\t".format(v1, v2)57 q, a = test_operators(v1, v2, str(v1), str(v2))58 query += q59 answers += a60 if TEST_WITH_CASTING:61 for t1 in TYPES.iterkeys():62 if inside_range(v1, t1):63 for t2 in TYPES.iterkeys():64 if inside_range(v2, t2):65 q, a = test_operators(v1, v2, 'to{}({})'.format(t1, v1), 'to{}({})'.format(t2, v2))66 query += ', ' + q67 answers += "\t" + a68 check_answers(query, answers)69 return query, answers70VALUES_INT = [0, -1, 1, 2**64-1, 2**63, -2**63, 2**63-1, 2**51, 2**52, 2**53-1, 2**53, 2**53+1, 2**53+2, -2**53+1, -2**53, -2**53-1, -2**53-2, 2*52, -2**52]71VALUES_FLOAT = [float(x) for x in VALUES_INT + [-0.5, 0.5, -1.5, 1.5, 2**53, 2**51 - 0.5, 2**51 + 0.5, 2**60, -2**60, -2**63 - 10000, 2**63 + 10000]]72def test_float_pair(i, f):73 f_str = ("%.9f" % f)74 query = "SELECT '{}', '{}', ".format(i, f_str)75 answers = "{}\t{}\t".format(i, f_str)76 q, a = test_operators(i, f, i, f_str)77 query += q78 answers += a79 if TEST_WITH_CASTING:80 for t1 in TYPES.iterkeys():81 if inside_range(i, t1):82 q, a = test_operators(i, f, 'to{}({})'.format(t1, i), f_str)83 query += ', ' + q84 answers += "\t" + a85 check_answers(query, answers)86 return query, answers87def main():88 if GENERATE_TEST_FILES:89 base_name = '00411_accurate_number_comparison'90 sql_file = open(base_name + '.sql', 'wt')91 ref_file = open(base_name + '.reference', 'wt')92 for (v1, v2) in itertools.combinations(VALUES, 2):93 q, a = test_pair(v1, v2)94 if GENERATE_TEST_FILES:95 sql_file.write(q + ";\n")96 ref_file.write(a + "\n")...

Full Screen

Full Screen

zmat_functions.py

Source:zmat_functions.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2import numpy as np3import sympy4from chemcoord import export5from chemcoord.internal_coordinates.zmat_class_main import Zmat6@export7class DummyManipulation(object):8 """Contextmanager that controls the behaviour of9 :meth:`~chemcoord.Zmat.safe_loc` and10 :meth:`~chemcoord.Zmat.safe_iloc`.11 In the following examples it is assumed, that using the assignment with12 :meth:`~chemcoord.Zmat.safe_loc` would lead to an invalid reference.13 Then there are two possible usecases::14 with DummyManipulation(zmat, True):15 zmat.safe_loc[...] = ...16 # This inserts required dummy atoms and removes them,17 # if they are not needed anymore.18 # Removes only dummy atoms, that were automatically inserted.19 with DummyManipulation(zmat, False):20 zmat.safe_loc[...] = ...21 # This raises an exception22 # :class:`~chemcoord.exceptions.InvalidReference`.23 # which can be handled appropiately.24 # The zmat instance is unmodified, if an exception was raised.25 """26 def __init__(self, dummy_manipulation_allowed, cls=None):27 if cls is None:28 cls = Zmat29 self.cls = cls30 self.dummy_manipulation_allowed = dummy_manipulation_allowed31 self.old_value = self.cls.dummy_manipulation_allowed32 def __enter__(self):33 self.cls.dummy_manipulation_allowed = self.dummy_manipulation_allowed34 def __exit__(self, exc_type, exc_value, traceback):35 self.cls.dummy_manipulation_allowed = self.old_value36@export37class TestOperators(object):38 """Switch the validity testing of zmatrices resulting from operators.39 The following examples is done with ``+``40 it is assumed, that adding ``zmat_1`` and ``zmat_2``41 leads to a zmatrix with an invalid reference::42 with TestOperators(True):43 zmat_1 + zmat_244 # Raises InvalidReference Exception45 """46 def __init__(self, test_operators, cls=None):47 if cls is None:48 cls = Zmat49 self.cls = cls50 self.test_operators = test_operators51 self.old_value = self.cls.test_operators52 def __enter__(self):53 self.cls.test_operators = self.test_operators54 def __exit__(self, exc_type, exc_value, traceback):55 self.cls.test_operators = self.old_value56@export57class PureInternalMovement(object):58 """Remove the translational and rotational degrees of freedom.59 When doing assignments to the z-matrix::60 with PureInternalMovement(True):61 zmat_1.loc[1, 'bond'] = value62 the translational and rotational degrees of freedom are automatically projected oout.63 For infinitesimal movements this would be done with the Eckhard conditions,64 but in this case we allow large non-infinitesimal movements.65 For the details read [6]_.66 """67 def __init__(self, pure_internal_mov, cls=None):68 if cls is None:69 cls = Zmat70 self.cls = cls71 self.pure_internal_mov = pure_internal_mov72 self.old_value = self.cls.pure_internal_mov73 def __enter__(self):74 self.cls.pure_internal_mov = self.pure_internal_mov75 def __exit__(self, exc_type, exc_value, traceback):76 self.cls.pure_internal_mov = self.old_value77def apply_grad_cartesian_tensor(grad_X, zmat_dist):78 """Apply the gradient for transformation to cartesian space onto zmat_dist.79 Args:80 grad_X (:class:`numpy.ndarray`): A ``(3, n, n, 3)`` array.81 The mathematical details of the index layout is explained in82 :meth:`~chemcoord.Cartesian.get_grad_zmat()`.83 zmat_dist (:class:`~chemcoord.Zmat`):84 Distortions in Zmatrix space.85 Returns:86 :class:`~chemcoord.Cartesian`: Distortions in cartesian space.87 """88 columns = ['bond', 'angle', 'dihedral']89 C_dist = zmat_dist.loc[:, columns].values.T90 try:91 C_dist = C_dist.astype('f8')92 C_dist[[1, 2], :] = np.radians(C_dist[[1, 2], :])93 except (TypeError, AttributeError):94 C_dist[[1, 2], :] = sympy.rad(C_dist[[1, 2], :])95 cart_dist = np.tensordot(grad_X, C_dist, axes=([3, 2], [0, 1])).T96 from chemcoord.cartesian_coordinates.cartesian_class_main import Cartesian97 return Cartesian(atoms=zmat_dist['atom'],...

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