How to use _is_number method in autotest

Best Python code snippet using autotest_python

my_math.py

Source:my_math.py Github

copy

Full Screen

...6@author Adam Kostolányi7@date 16.3.20228"""9import math10def _is_number(x):11 """!12 Check if x is number13 @param x number to check14 @return True if x is number15 """16 if type(x) is int or type(x) is float:17 return True18 return False19def _is_int(x):20 """!21 Check if x is integer even if x is float (5 -> True, 5.0 -> True, 5.1 -> False)22 @param x number to integer check23 @return True if x is integer24 """25 return isinstance(x, int) or (isinstance(x, float) and x.is_integer())26def add(a, b):27 """!28 Addition of two numbers29 @param a addend30 @param b addend31 @return sum of a and b32 @exception TypeError if a or b is not a number33 """34 if not _is_number(a) or not _is_number(b):35 raise TypeError36 return a + b37def subtract(a, b):38 """!39 Subtraction of two numbers40 @param a minuend41 @param b subtrahend42 @return difference of a and b43 @exception TypeError if a or b is not a number44 """45 if not _is_number(a) or not _is_number(b):46 raise TypeError47 return a - b48def multiply(a, b):49 """!50 Multiplication of two numbers51 @param a multiplier52 @param b multiplicand53 @return product of a and b54 @exception TypeError if a or b is not a number55 """56 if not _is_number(a) or not _is_number(b):57 raise TypeError58 return a * b59def divide(a, b):60 """!61 Division of two numbers62 Note that function does not take care of zero division.63 @param a dividend64 @param b divisor65 @return quotient of a and b66 @exception TypeError if a or b is not a number67 """68 if not _is_number(a) or not _is_number(b):69 raise TypeError70 result = a / float(b)71 if int(result) == result:72 return int(result)73 return result74def power(x, n):75 """!76 Calculate x^n77 @param x base value78 @param n exponent79 @return x raised to the power n80 @exception TypeError if `x` or `n` isn't number81 @exception ValueError if exponent isn't natural number82 """83 if not _is_number(x) or not _is_number(n):84 raise TypeError('`x` or `n` isn\'t number')85 if not _is_int(n) or n < 0.0:86 raise ValueError('Exponent isn\'t natural number')87 return x ** n88def root(x, n):89 """!90 Calculate nth root of `x`91 @param x positive number92 @param n number n in nth root93 @return x**(1/n)94 @exception TypeError if `x` or `n` isnt't number95 @exception ValueError if `n` isn't integer96 @exception ValueError if `n` is zero 97 @exception ValueError if `x` is negative number98 """99 if not _is_number(x) or not _is_number(n):100 raise TypeError('`x` or `n` isn\'t number')101 if not _is_int(n):102 raise ValueError('`n` isn\'t integer')103 if x < 0:104 raise ValueError('`x` is negative number')105 if n == 0:106 raise ValueError('`n` can\'t be 0')107 return x**(1/n)108def factorial(x):109 """!110 Calculate `x` factorial111 @param x value for factorial calculation112 @return x factorial113 @exception TypeError if `x` isn't number114 @exception ValusError if `x` isn't integer or `x` is negative number115 """116 if not _is_number(x):117 raise TypeError('`x` isn\'t number')118 if not _is_int(x):119 raise ValueError('`x` isn\'t integer')120 return math.factorial(int(x))121def modulo(x, n):122 """!123 Calculate modulo from `x` and `n`124 @param x divident125 @param n divisor126 @return x % n127 @exception TypeError if `x` or `n` isnt't number128 @exception ValueError if `x` or `n` isnt't integer129 """130 if not _is_number(x) or not _is_number(n):131 raise TypeError('`x` or `n` isn\'t number')132 if not _is_int(x) or not _is_int(n):133 raise ValueError('`x` or `n` isn\'t integer')134 return int(x) % int(n)135def sum(li: list):136 """!137 Sum up list138 @param li list with numbers139 @return sum140 """141 sum = 0142 for number in li:143 sum = add(sum, number)144 return sum

Full Screen

Full Screen

filename_sort.py

Source:filename_sort.py Github

copy

Full Screen

...8# Change History:9# 2021-01-20 Hengxin.Li the first version10class FileNameSort(object):11 @staticmethod12 def _is_number(s):13 try:14 float(s)15 return True16 except ValueError:17 pass18 try:19 import unicodedata20 unicodedata.numeric(s)21 return True22 except (TypeError, ValueError):23 pass24 return False25 def _find_continuous_num(self, astr, c):26 num = ''27 # noinspection PyBroadException28 try:29 while not self._is_number(astr[c]) and c < len(astr):30 c += 131 while self._is_number(astr[c]) and c < len(astr):32 num += astr[c]33 c += 134 except:35 pass36 if num != '':37 return int(num)38 def _comp2filename(self, file1, file2):39 smaller_length = min(len(file1), len(file2))40 continuous_num = ''41 for c in range(0, smaller_length):42 if not self._is_number(file1[c]) and not self._is_number(file2[c]):43 if file1[c] < file2[c]:44 return True45 if file1[c] > file2[c]:46 return False47 if file1[c] == file2[c]:48 if c == smaller_length - 1:49 if len(file1) < len(file2):50 return True51 else:52 return False53 else:54 continue55 if self._is_number(file1[c]) and not self._is_number(file2[c]):56 return True57 if not self._is_number(file1[c]) and self._is_number(file2[c]):58 return False59 if self._is_number(file1[c]) and self._is_number(file2[c]):60 if self._find_continuous_num(file1, c) < self._find_continuous_num(file2, c):61 return True62 else:63 return False64 @staticmethod65 def sort_insert(lst):66 for i in range(1, len(lst)):67 x = lst[i]68 j = i69 while j > 0 and lst[j - 1] > x:70 # while j > 0 and comp2filename(x, lst[j-1]):71 lst[j] = lst[j - 1]72 j -= 173 lst[j] = x...

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