How to use constrained_complex method in hypothesis

Best Python code snippet using hypothesis

core.py

Source:core.py Github

copy

Full Screen

...1666 # magnitude and therefore no relationship between the real and1667 # imaginary parts.1668 return builds(complex, floats(**allow_kw), floats(**allow_kw))1669 @composite1670 def constrained_complex(draw):1671 # Draw the imaginary part, and determine the maximum real part given1672 # this and the max_magnitude1673 if max_magnitude is None:1674 zi = draw(floats(**allow_kw))1675 rmax = None1676 else:1677 zi = draw(floats(-max_magnitude, max_magnitude, **allow_kw))1678 rmax = cathetus(max_magnitude, zi)1679 # Draw the real part from the allowed range given the imaginary part1680 if min_magnitude == 0 or math.fabs(zi) >= min_magnitude:1681 zr = draw(floats(None if rmax is None else -rmax, rmax, **allow_kw))1682 else:1683 zr = draw(floats(cathetus(min_magnitude, zi), rmax, **allow_kw))1684 # Order of conditions carefully tuned so that for a given pair of1685 # magnitude arguments, we always either draw or do not draw the bool1686 # (crucial for good shrinking behaviour) but only invert when needed.1687 if min_magnitude > 0 and draw(booleans()) and math.fabs(zi) <= min_magnitude:1688 zr = -zr1689 return complex(zr, zi)1690 return constrained_complex()1691@deprecated_posargs1692def shared(1693 base: SearchStrategy[Ex],1694 *,1695 key: Optional[Hashable] = None,1696) -> SearchStrategy[Ex]:1697 """Returns a strategy that draws a single shared value per run, drawn from1698 base. Any two shared instances with the same key will share the same value,1699 otherwise the identity of this strategy will be used. That is:1700 >>> s = integers() # or any other strategy1701 >>> x = shared(s)1702 >>> y = shared(s)1703 In the above x and y may draw different (or potentially the same) values.1704 In the following they will always draw the same:...

Full Screen

Full Screen

strategies.py

Source:strategies.py Github

copy

Full Screen

...1594 # magnitude and therefore no relationship between the real and1595 # imaginary parts.1596 return builds(complex, floats(**allow_kw), floats(**allow_kw))1597 @composite1598 def constrained_complex(draw):1599 # Draw the imaginary part, and determine the maximum real part given1600 # this and the max_magnitude1601 if max_magnitude is None:1602 zi = draw(floats(**allow_kw))1603 rmax = float('inf')1604 else:1605 zi = draw(floats(-max_magnitude, max_magnitude, **allow_kw))1606 rmax = cathetus(max_magnitude, zi)1607 # Draw the real part from the allowed range given the imaginary part1608 if min_magnitude is None or math.fabs(zi) >= min_magnitude:1609 zr = draw(floats(-rmax, rmax, **allow_kw))1610 else:1611 zr = draw(floats(cathetus(min_magnitude, zi), rmax, **allow_kw))1612 # Order of conditions carefully tuned so that for a given pair of1613 # magnitude arguments, we always either draw or do not draw the bool1614 # (crucial for good shrinking behaviour) but only invert when needed.1615 if min_magnitude is not None and draw(booleans()) and \1616 math.fabs(zi) <= min_magnitude:1617 zr = -zr1618 return complex(zr, zi)1619 return constrained_complex()1620def shared(base, key=None):1621 # type: (SearchStrategy[Ex], Any) -> SearchStrategy[Ex]1622 """Returns a strategy that draws a single shared value per run, drawn from1623 base. Any two shared instances with the same key will share the same value,1624 otherwise the identity of this strategy will be used. That is:1625 >>> s = integers() # or any other strategy1626 >>> x = shared(s)1627 >>> y = shared(s)1628 In the above x and y may draw different (or potentially the same) values.1629 In the following they will always draw the same:1630 >>> x = shared(s, key="hi")1631 >>> y = shared(s, key="hi")1632 Examples from this strategy shrink as per their base strategy.1633 """...

Full Screen

Full Screen

test_graphsolver.py

Source:test_graphsolver.py Github

copy

Full Screen

1"""2Unit tests for module.3"""4import networkx as nx5import pandas as pd6import logging7import pytest8import allocate.solvers.graphsolver9import allocate.network.algorithms10import allocate.network.visualize11import tests.utilities12from allocate.solvers.constrained import BucketSolverConstrained13from allocate.solvers.constrained import BucketSolverSimple14from allocate.solvers import BucketSolver15@pytest.mark.parametrize('starting_frame,expected_graph,solver', [16 # simple_no_addition : the amounts should be redistributed17 (18 pd.DataFrame([19 dict(label='T', current_value=3000.0, optimal_ratio=1.00, amount_to_add=0.0000, children=('H', 'I', 'J')),20 dict(label='H', current_value=3000.0, optimal_ratio=0.50, amount_to_add=0.0000, children=()),21 dict(label='I', current_value=0000.0, optimal_ratio=0.35, amount_to_add=0.0000, children=()),22 dict(label='J', current_value=0000.0, optimal_ratio=0.15, amount_to_add=0.0000, children=()),23 ]),24 tests.utilities.make_graph(nodes=[25 ('T', dict(results_value=3000.0 + 3000.0 * 0.00, amount_to_add=+3000.0 * 0.00)),26 ('H', dict(results_value=3000.0 - 3000.0 * 0.50, amount_to_add=-3000.0 * 0.50)),27 ('I', dict(results_value=0.0000 + 3000.0 * 0.35, amount_to_add=+3000.0 * 0.35)),28 ('J', dict(results_value=0.0000 + 3000.0 * 0.15, amount_to_add=+3000.0 * 0.15)),29 ], edges=[30 ('T', 'H'), ('T', 'I'), ('T', 'J')31 ]),32 BucketSolverSimple33 ),34 # simple_value_added : the amounts should be redistributed and value should be added35 (36 pd.DataFrame([37 dict(label='F', current_value=8000.0 + 0.000, optimal_ratio=1.00, amount_to_add=1000.0,38 children=('U', 'V', 'W')),39 dict(label='U', current_value=4000.0 + 0.000, optimal_ratio=0.50, amount_to_add=0.0000, children=()),40 dict(label='V', current_value=2800.0 + 256.0, optimal_ratio=0.35, amount_to_add=0.0000, children=()),41 dict(label='W', current_value=1200.0 - 256.0, optimal_ratio=0.15, amount_to_add=0.0000, children=()),42 ]),43 tests.utilities.make_graph(nodes=[44 ('F', dict(results_value=8000.0 + 0.000 + 1000.0 * 1.00 + 0.000, amount_to_add=+1000.0 * 0.00 + 0.000)),45 ('U', dict(results_value=4000.0 + 0.000 + 1000.0 * 0.50 + 0.000, amount_to_add=+1000.0 * 0.50 + 0.000)),46 ('V', dict(results_value=2800.0 + 256.0 + 1000.0 * 0.35 - 256.0, amount_to_add=+1000.0 * 0.35 - 256.0)),47 ('W', dict(results_value=1200.0 - 256.0 + 1000.0 * 0.15 + 256.0, amount_to_add=+1000.0 * 0.15 + 256.0)),48 ], edges=[49 ('F', 'U'), ('F', 'V'), ('F', 'W')50 ]),51 BucketSolverSimple52 ),53 # constrained_simple : values are only added to the final result and are in perfect ratios54 (55 pd.DataFrame([56 dict(label='A', current_value=4000.0, optimal_ratio=1.00, amount_to_add=1000.0, children=('0', '1', '2')),57 dict(label='0', current_value=2000.0, optimal_ratio=0.50, amount_to_add=0.0000, children=()),58 dict(label='1', current_value=1000.0, optimal_ratio=0.25, amount_to_add=0.0000, children=()),59 dict(label='2', current_value=1000.0, optimal_ratio=0.25, amount_to_add=0.0000, children=()),60 ]),61 tests.utilities.make_graph(nodes=[62 ('A', dict(results_value=4000.0 + 1000.0 * 1.00, amount_to_add=1000.0 * 0.00)),63 ('0', dict(results_value=2000.0 + 1000.0 * 0.50, amount_to_add=1000.0 * 0.50)),64 ('1', dict(results_value=1000.0 + 1000.0 * 0.25, amount_to_add=1000.0 * 0.25)),65 ('2', dict(results_value=1000.0 + 1000.0 * 0.25, amount_to_add=1000.0 * 0.25)),66 ], edges=[67 ('A', '0'), ('A', '1'), ('A', '2')68 ]),69 BucketSolverConstrained70 ),71 # constrained_complex : values are only added to the final result and are in perfect ratios72 (73 pd.DataFrame([74 dict(label='B', current_value=8000.0, optimal_ratio=1.00, amount_to_add=4000.0, children=('3', '4', '5')),75 dict(label='3', current_value=4000.0, optimal_ratio=0.50, amount_to_add=0.0000, children=()),76 dict(label='4', current_value=2000.0, optimal_ratio=0.25, amount_to_add=0.0000, children=()),77 dict(label='5', current_value=2000.0, optimal_ratio=0.25, amount_to_add=0.0000, children=('C', 'D')),78 dict(label='C', current_value=1000.0, optimal_ratio=0.50, amount_to_add=0.0000, children=()),79 dict(label='D', current_value=1000.0, optimal_ratio=0.50, amount_to_add=0.0000, children=('6', '7')),80 dict(label='6', current_value=2.50e2, optimal_ratio=0.25, amount_to_add=0.0000, children=()),81 dict(label='7', current_value=7.50e2, optimal_ratio=0.75, amount_to_add=0.0000, children=()),82 ]),83 tests.utilities.make_graph(nodes=[84 ('B', dict(results_value=8000.0 + 4000.0 * 1.00 * 1.00 * 1.00, amount_to_add=4000.0 * 0.00 * 1.00 * 1.00)),85 ('3', dict(results_value=4000.0 + 4000.0 * 0.50 * 1.00 * 1.00, amount_to_add=4000.0 * 0.50 * 1.00 * 1.00)),86 ('4', dict(results_value=2000.0 + 4000.0 * 0.25 * 1.00 * 1.00, amount_to_add=4000.0 * 0.25 * 1.00 * 1.00)),87 ('5', dict(results_value=2000.0 + 4000.0 * 0.25 * 1.00 * 1.00, amount_to_add=4000.0 * 0.00 * 1.00 * 1.00)),88 ('C', dict(results_value=1000.0 + 4000.0 * 0.25 * 0.50 * 1.00, amount_to_add=4000.0 * 0.25 * 0.50 * 1.00)),89 ('D', dict(results_value=1000.0 + 4000.0 * 0.25 * 0.50 * 1.00, amount_to_add=4000.0 * 0.00 * 0.50 * 1.00)),90 ('6', dict(results_value=2.50e2 + 4000.0 * 0.25 * 0.50 * 0.25, amount_to_add=4000.0 * 0.25 * 0.50 * 0.25)),91 ('7', dict(results_value=7.50e2 + 4000.0 * 0.25 * 0.50 * 0.75, amount_to_add=4000.0 * 0.25 * 0.50 * 0.75)),92 ], edges=[93 ('B', '3'), ('B', '4'), ('B', '5'), ('5', 'C'), ('5', 'D'), ('D', '6'), ('D', '7')94 ]),95 BucketSolverConstrained96 ),97], ids=[98 'simple_no_addition',99 'simple_value_added',100 'constrained_simple',101 'constrained_complex',102])103def test_solve(starting_frame: pd.DataFrame, expected_graph: nx.DiGraph, solver: BucketSolver):104 logging.debug('starting_frame:\n%s', starting_frame)105 starting_graph: nx.DiGraph = allocate.network.algorithms.create(starting_frame)106 tests.utilities.show_graph('starting_graph', starting_graph, **allocate.network.visualize.formats_inp)107 tests.utilities.show_graph('expected_graph', expected_graph, **allocate.network.visualize.formats_out)108 observed_graph: nx.DiGraph = allocate.solvers.graphsolver.solve(starting_graph, solver=solver, inplace=False)109 tests.utilities.show_graph('observed_graph', observed_graph, **allocate.network.visualize.formats_out)110 node_match = nx.algorithms.isomorphism.numerical_node_match(111 ['results_value', 'amount_to_add'], [-1000, -1000])...

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