Best Python code snippet using hypothesis
exponentials.py
Source: exponentials.py
1""" TO DO:2make difficulty more interesting3add parameter for num terms to produce and let difficulty effect the actual integral (coefficients ext)45find a way to print bases nicely6find an even prettier print7"""89from sympy import *10import numpy as np11from fractions import Fraction as frac12from sympy.integrals.manualintegrate import integral_steps1314x = symbols('x')15integer_choice = range(-10, 10)161718def get_fractional_coeff(int_range):19 coefficient_denominator = np.random.choice(int_range)20 coefficient_numerator = np.random.choice(int_range)21 coefficient = frac(coefficient_numerator, coefficient_denominator)22 return coefficient232425def generate_polynomial(order, integer_range, architecture=None):26 terms = order + 127 integral = 028 if architecture == None:29 architecture = tuple(1 for _ in range(terms))3031 for power, terms in enumerate(architecture):32 for j in range(terms):33 coefficient = get_fractional_coeff(integer_range)34 integral += coefficient * x**power35 return integral363738def generate_exponential(difficulty, integer_range):39 integral = 04041 match difficulty:42 case 'Easy': # simple exponential43 coefficient = get_fractional_coeff(integer_range)44 integral += coefficient * exp(x)45 case 'Medium':46 coefficient = get_fractional_coeff(integer_range)47 polynomial_ord1 = generate_polynomial(1, integer_range)48 integral += coefficient * exp(polynomial_ord1)49 case 'Hard':50 chance = 'heads' if np.random.random() >= 0.5 else 'tails'51 coefficient = get_fractional_coeff(integer_range)52 if chance == 'heads':53 polynomial_power = generate_polynomial(2, integer_range)54 polynomial_coefficient = generate_polynomial(1, integer_range)55 else:56 polynomial_power = generate_polynomial(3, integer_range)57 polynomial_coefficient = generate_polynomial(2, integer_range)58 integral += coefficient * polynomial_coefficient * exp(polynomial_power)5960 return integral616263def generate_ln(difficulty, integer_range):64 terms = No_of_terms[difficulty]65 integral = 06667 for i in range(terms):68 power = get_fractional_coeff(integer_range)69 coefficient = get_fractional_coeff(integer_range)70 ln_coefficient = get_fractional_coeff(integer_range)7172 integral += coefficient * log(ln_coefficient * x**power)73 return integral747576def generate_log(difficulty, integer_range, base):77 terms = No_of_terms[difficulty]78 integral = 07980 for i in range(terms):81 power = get_fractional_coeff(integer_range)82 coefficient = get_fractional_coeff(integer_range)83 ln_coefficient = get_fractional_coeff(integer_range)8485 integral += coefficient * log(ln_coefficient * x**power, base)86 return integral878889test = generate_polynomial(2, integer_choice)9091solution = generate_exponential('easy', integer_range=integer_choice)92# FOR PERTY PRINTING93init_printing()
...
domain.py
Source: domain.py
1from typing import Tuple2import DZ1.defaults3class Domain:4 def __init__(self, integer_range: Tuple[int, int] = DZ1.defaults.DEFAULT_DOMAIN_RANGE):5 if integer_range is None or not isinstance(integer_range, tuple) or not len(integer_range) == 2\6 or not (isinstance(integer_range[0], int) and isinstance(integer_range[1], int))\7 or not (integer_range[0] - integer_range[1] < 0):8 integer_range = DZ1.defaults.DEFAULT_DOMAIN_RANGE9 self.__members = tuple(range(*integer_range))10 @staticmethod11 def from_domains(domains: Tuple["Domain", "Domain"]) -> "Domain":12 if domains is None or not isinstance(domains, tuple) or not len(domains) == 2\13 or not (isinstance(domains[0], Domain) and isinstance(domains[1], Domain)):14 raise ValueError(DZ1.defaults.DOMAIN_INPUT_IS_POOPOO)15 members = list()16 for domain_predecessor in domains[0]:17 if isinstance(domain_predecessor, int):18 domain_predecessor = (domain_predecessor, )19 for domain_successor in domains[1]:20 if isinstance(domain_successor, int):21 domain_successor = (domain_successor, )22 members.append(domain_predecessor + domain_successor)23 to_return = Domain((0, 1))24 to_return.__members = tuple(members)25 return to_return26 @staticmethod27 def from_domains_merge(domains: Tuple["Domain", "Domain"]) -> "Domain":28 if domains is None or not isinstance(domains, tuple) or not len(domains) == 2 \29 or not (isinstance(domains[0], Domain) and isinstance(domains[1], Domain)):30 raise ValueError(DZ1.defaults.DOMAIN_INPUT_IS_POOPOO)31 to_return = Domain((0, 1))32 to_return.__members = tuple(sorted(set(domains[0].__members + domains[1].__members)))33 return to_return34 def cardinality(self) -> int:35 return len(self)36 def index(self, element, start=None, end=None) -> int:37 if start is None or not isinstance(start, int):38 start = 039 if end is None or not isinstance(end, int):40 end = len(self.__members)41 return self.__members.index(element, start, end)42 def __getitem__(self, key) -> Tuple or int:43 return self.__members[key]44 def __len__(self) -> int:45 return len(self.__members)46 def __str__(self) -> str:...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.
How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.
Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.
Mobile application development is on the rise like never before, and it proportionally invites the need to perform thorough testing with the right mobile testing strategies. The strategies majorly involve the usage of various mobile automation testing tools. Mobile testing tools help businesses automate their application testing and cut down the extra cost, time, and chances of human error.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!