# How to use is_positive method in assertpy

Best Python code snippet using assertpy_python

test_arit.py

Source:test_arit.py

`1from sympy import Symbol, sin, cos, exp, O, sqrt, Rational, re2from sympy.utilities.pytest import XFAIL3def test_bug1():4 x=Symbol("x")5 assert re(x) != x6 x.series(x,1)7 assert re(x) != x8a = Symbol("a")9b = Symbol("b", positive=True)10c = Symbol("c")11def test_Symbol():12 assert str(a)=="a"13 assert str(b)=="b"14 e=a*b15 assert e==a*b16 assert a*b*b==a*b**217 assert a*b*b+c==c+a*b**218 assert a*b*b-c==-c+a*b**219def test_arit():20 p = Rational(5)21 e=a*b22 assert e == a*b23 e=a*b+b*a24 assert e == 2*a*b25 e=a*b+b*a+a*b+p*b*a26 assert e == 8*a*b27 e=a*b+b*a+a*b+p*b*a+a28 assert e == a+8*a*b29 e=a+a30 assert e == 2*a31 e=a+b+a32 assert e == b+2*a33 e=a+b*b+a+b*b34 assert e == 2*a+2*b**235 e=a+Rational(2)+b*b+a+b*b+p36 assert e == 7+2*a+2*b**237 e=(a+b*b+a+b*b)*p38 assert e == 5*(2*a+2*b**2)39 e=(a*b*c+c*b*a+b*a*c)*p40 assert e == 15*a*b*c41 e=(a*b*c+c*b*a+b*a*c)*p-Rational(15)*a*b*c42 assert e == Rational(0)43 e = Rational(50)*(a-a)44 assert e == Rational(0)45 e=b*a-b-a*b+b46 assert e == Rational(0)47 e=a*b+c**p48 assert e == a*b+c**549 e=a/b50 assert e == a*b**(-1)51 e=a*2*252 assert e == 4*a53 e=2+a*2/254 assert e == 2+a55 e=2-a-256 assert e == -a57 e=2*a*258 assert e == 4*a59 e=2/a/260 assert e == a**(-1)61 e=2**a**262 assert e == 2**(a**2)63 e = -(1+a)64 assert e == -1 -a65 e = Rational(1,2)*(1+a)66 assert e == Rational(1,2) + a/267def testdiv():68 e=a/b69 assert e == a*b**(-1)70 e=a/b+c/271 assert e == a*b**(-1)+Rational(1)/2*c72 e=(1-b)/(b-1)73 assert e == (1+-b)*((-1)+b)**(-1)74def testpow():75 n1 = Rational(1)76 n2 = Rational(2)77 n5 = Rational(5)78 e=a*a79 assert e == a**280 e=a*a*a81 assert e == a**382 e=a*a*a*a**Rational(6)83 assert e == a**984 e=a*a*a*a**Rational(6)-a**Rational(9)85 assert e == Rational(0)86 e=a**(b+c)*a**(-b)87 assert e == a**c88 e=a**(b+c)*a*a**(-b)*a**(-c)/a89 assert e == Rational(1)90 e=a**(b-b)91 assert e == Rational(1)92 e=(a-a)**b93 assert e == Rational(0)94 e=(a+Rational(1)-a)**b95 assert e == Rational(1)96 e=(a+b+c)**n297 assert e == (a+b+c)**298 assert e.expand() == 2*b*c+2*a*c+2*a*b+a**2+c**2+b**299 e=(a+b)**n2100 assert e == (a+b)**2101 assert e.expand() == 2*a*b+a**2+b**2102 e=(a+b)**(n1/n2)103 assert e == (a+b)**(Rational(1)/2)104 assert e.expand() == (a+b)**(Rational(1)/2)105 n=n5**(n1/n2)106 assert n == Rational(5)**(Rational(1)/2)107 e=n*a*b-n*b*a108 assert e == Rational(0)109 e=n*a*b+n*b*a110 assert e == 2*a*b*5**(Rational(1)/2)111 assert e.diff(a) == 2*b*5**(Rational(1)/2)112 assert e.diff(a) == 2*b*5**(Rational(1)/2)113 e=a/b**2114 assert e == a*b**(-2)115 assert sqrt(2*(1+sqrt(2))) == (2*(1+2**(Rational(1,2))))**(Rational(1,2))116 x = Symbol('x')117 y = Symbol('y')118 assert ((x*y)**3).expand() == y**3 * x**3119 assert ((x*y)**-3).expand() == y**-3 * x**-3120 assert (x**5*(3*x)**(3)).expand() == 27 * x**8121 assert (x**5*(-3*x)**(3)).expand() == -27 * x**8122 assert (x**5*(3*x)**(-3)).expand() == Rational(1,27) * x**2123 assert (x**5*(-3*x)**(-3)).expand() == -Rational(1,27) * x**2124 n = Symbol('k', even=False)125 k = Symbol('k', even=True)126 assert (-1)**x == (-1)**x127 assert (-1)**n == (-1)**n128 assert (-2)**k == 2**k129 assert (-1)**k == 1130@XFAIL131def test_pow2():132 # XXX These fail - they are maybe discutable, 133 # let's see SAGE and similar.134 assert ((-x)**2)**Rational(1,3) == ((-x)**Rational(1,3))**2135 assert (-x)**Rational(2,3) == x**Rational(2,3)136 assert (-x)**Rational(5,7) == -x**Rational(5,7)137def test_pow_issue417():138 assert 4**Rational(1, 4) == 2**Rational(1, 2)139def test_pow3():140 assert 2**(Rational(3)/2) == 2 * 2**Rational(1, 2)141 assert 2**(Rational(3)/2) == sqrt(8)142def test_expand():143 p = Rational(5)144 e = (a+b)*c145 assert e == c*(a+b)146 assert (e.expand()-a*c-b*c) == Rational(0)147 e=(a+b)*(a+b)148 assert e == (a+b)**2149 assert e.expand() == 2*a*b+a**2+b**2150 e=(a+b)*(a+b)**Rational(2)151 assert e == (a+b)**3152 assert e.expand() == 3*b*a**2+3*a*b**2+a**3+b**3153 assert e.expand() == 3*b*a**2+3*a*b**2+a**3+b**3154 e=(a+b)*(a+c)*(b+c)155 assert e == (a+c)*(a+b)*(b+c)156 assert e.expand() == 2*a*b*c+b*a**2+c*a**2+b*c**2+a*c**2+c*b**2+a*b**2157 e=(a+Rational(1))**p158 assert e == (1+a)**5159 assert e.expand() == 1+5*a+10*a**2+10*a**3+5*a**4+a**5160 e=(a+b+c)*(a+c+p)161 assert e == (5+a+c)*(a+b+c)162 assert e.expand() == 5*a+5*b+5*c+2*a*c+b*c+a*b+a**2+c**2163 x=Symbol("x")164 s=exp(x*x)-1165 e=s.series(x,5)/x**2166 assert e.expand() == 1+x**2/2+O(x**3)167 # Check that this isn't too slow168 x = Symbol('x')169 W = 1170 for i in range(1, 21):171 W = W * (x-i)172 W = W.expand()173 assert W.has(-1672280820*x**15)174def test_power_expand():175 """Test for Pow.expand()"""176 a = Symbol('a')177 b = Symbol('b')178 p = (a+b)**2179 assert p.expand() == a**2 + b**2 + 2*a*b180 p = (1+2*(1+a))**2181 assert p.expand() == 9 + 4*(a**2) + 12*a182def test_ncmul():183 A = Symbol("A", commutative=False)184 B = Symbol("B", commutative=False)185 C = Symbol("C", commutative=False)186 assert A*B != B*A187 assert A*B*C != C*B*A188 assert A*b*B*3*C == 3*b*A*B*C189 assert A*b*B*3*C != 3*b*B*A*C190 assert A*b*B*3*C == 3*A*B*C*b191 assert A+B == B+A192 assert (A+B)*C != C*(A+B)193 assert C*(A+B)*C != C*C*(A+B)194 assert (C*(A+B)).expand() == C*A+C*B195 assert (C*(A+B)).expand() != A*C+B*C196 assert A*A == A**2197 assert (A+B)*(A+B) == (A+B)**2198 assert ((A+B)**2).expand() == A**2 + A*B + B*A +B**2199 assert A**-1 * A == 1200 assert A/A == 1201 assert A/(A**2) == 1/A202 assert A/(1+A) == A/(1+A)203def test_ncpow():204 x = Symbol('x', commutative=False)205 y = Symbol('y', commutative=False)206 assert (x**2)*(y**2) != (y**2)*(x**2)207 assert (x**-2)*y != y*(x**2)208def test_powerbug():209 x=Symbol("x")210 assert x**1 != (-x)**1211 assert x**2 == (-x)**2212 assert x**3 != (-x)**3213 assert x**4 == (-x)**4214 assert x**5 != (-x)**5215 assert x**6 == (-x)**6216 assert x**128 == (-x)**128217 assert x**129 != (-x)**129218 assert (2*x)**2 == (-2*x)**2219def test_Add_Mul_is_integer():220 x = Symbol('x')221 k = Symbol('k', integer=True)222 n = Symbol('n', integer=True)223 assert (2*k).is_integer == True224 assert (-k).is_integer == True225 assert (k/3).is_integer == False226 assert (x*k*n).is_integer == None227 assert (k+n).is_integer == True228 assert (k+x).is_integer == None229 assert (k+n*x).is_integer == None230 assert (k+n/3).is_integer == False231def test_Add_Mul_is_bounded():232 x = Symbol('x', real=True, bounded=False)233 assert sin(x).is_bounded == True234 assert (x*sin(x)).is_bounded == False235 assert (1024*sin(x)).is_bounded == True236 assert (sin(x)*exp(x)).is_bounded == False237 assert (sin(x)*cos(x)).is_bounded == True238 assert (x*sin(x)*exp(x)).is_bounded == False239 assert (sin(x)-67).is_bounded == True240 assert (sin(x)+exp(x)).is_bounded == False241def test_Mul_is_even_odd():242 x = Symbol('x', integer=True)243 k = Symbol('k', odd=True)244 n = Symbol('n', odd=True)245 m = Symbol('m', even=True)246 assert (2*x).is_even == True247 assert (2*x).is_odd == False248 assert (3*x).is_even == None249 assert (3*x).is_odd == None250 assert (k/3).is_even == None251 assert (k/3).is_odd == None252 assert (2*n).is_even == True253 assert (2*n).is_odd == False254 assert (2*m).is_even == True255 assert (2*m).is_odd == False256 assert (-n).is_even == False257 assert (-n).is_odd == True258 assert (k*n).is_even == False259 assert (k*n).is_odd == True260 assert (k*m).is_even == True261 assert (k*m).is_odd == False262 assert (k*n*m).is_even == True263 assert (k*n*m).is_odd == False264 assert (k*m*x).is_even == True265 assert (k*m*x).is_odd == False266def test_Add_is_even_odd():267 x = Symbol('x', integer=True)268 k = Symbol('k', odd=True)269 n = Symbol('n', even=True)270 assert (2+k).is_even == False271 assert (2+k).is_odd == True272 assert (7-k).is_even == True273 assert (7-k).is_odd == False274 assert (11-n).is_even == False275 assert (11-n).is_odd == True276 assert (-8+n).is_even == True277 assert (-8+n).is_odd == False278 assert (n+k).is_even == False279 assert (n+k).is_odd == True280 assert (n-k).is_even == False281 assert (n-k).is_odd == True282 assert (n+2*k).is_even == True283 assert (n+2*k).is_odd == False284 assert (k+n+x).is_odd == None285 assert (k+n-x).is_even == None286 assert (2*k+n*x).is_odd == None287 assert (2*k+n*x).is_even == None288def test_Mul_is_negative_positive():289 x = Symbol('x', real=True)290 y = Symbol('y', real=False)291 k = Symbol('k', negative=True)292 n = Symbol('n', positive=True)293 u = Symbol('u', nonnegative=True)294 v = Symbol('v', nonpositive=True)295 assert k.is_negative == True296 assert (-k).is_negative == False297 assert (2*k).is_negative == True298 assert n.is_negative == False299 assert (-n).is_negative == True300 assert (2*n).is_negative == False301 assert (n*k).is_negative == True302 assert (2*n*k).is_negative == True303 assert (-n*k).is_negative == False304 assert (n*k*y).is_negative == None305 assert u.is_negative == False306 assert (-u).is_negative == None307 assert (2*u).is_negative == False308 assert v.is_negative == None309 assert (-v).is_negative == False310 assert (2*v).is_negative == None311 assert (u*v).is_negative == None312 assert (k*u).is_negative == None313 assert (k*v).is_negative == False314 assert (n*u).is_negative == False315 assert (n*v).is_negative == None316 assert (v*k*u).is_negative == False317 assert (v*n*u).is_negative == None318 assert (-v*k*u).is_negative == None319 assert (-v*n*u).is_negative == False320 assert (17*v*k*u).is_negative == False321 assert (17*v*n*u).is_negative == None322 assert (k*v*n*u).is_negative == False323 assert (x*k).is_negative == None324 assert (u*v*n*x*k).is_negative == None325 assert k.is_positive == False326 assert (-k).is_positive == True327 assert (2*k).is_positive == False328 assert n.is_positive == True329 assert (-n).is_positive == False330 assert (2*n).is_positive == True331 assert (n*k).is_positive == False332 assert (2*n*k).is_positive == False333 assert (-n*k).is_positive == True334 assert (-n*k*y).is_positive == None335 assert u.is_positive == None336 assert (-u).is_positive == False337 assert (2*u).is_positive == None338 assert v.is_positive == False339 assert (-v).is_positive == None340 assert (2*v).is_positive == False341 assert (u*v).is_positive == False342 assert (k*u).is_positive == False343 assert (k*v).is_positive == None344 assert (n*u).is_positive == None345 assert (n*v).is_positive == False346 assert (v*k*u).is_positive == None347 assert (v*n*u).is_positive == False348 assert (-v*k*u).is_positive == False349 assert (-v*n*u).is_positive == None350 assert (17*v*k*u).is_positive == None351 assert (17*v*n*u).is_positive == False352 assert (k*v*n*u).is_positive == None353 assert (x*k).is_positive == None354 assert (u*v*n*x*k).is_positive == None355def test_Mul_is_nonpositive_nonnegative():356 x = Symbol('x', real=True)357 k = Symbol('k', negative=True)358 n = Symbol('n', positive=True)359 u = Symbol('u', nonnegative=True)360 v = Symbol('v', nonpositive=True)361 assert k.is_nonpositive == True362 assert (-k).is_nonpositive == False363 assert (2*k).is_nonpositive == True364 assert n.is_nonpositive == False365 assert (-n).is_nonpositive == True366 assert (2*n).is_nonpositive == False367 assert (n*k).is_nonpositive == True368 assert (2*n*k).is_nonpositive == True369 assert (-n*k).is_nonpositive == False370 assert u.is_nonpositive == None371 assert (-u).is_nonpositive == True372 assert (2*u).is_nonpositive == None373 assert v.is_nonpositive == True374 assert (-v).is_nonpositive == None375 assert (2*v).is_nonpositive == True376 assert (u*v).is_nonpositive == True377 assert (k*u).is_nonpositive == True378 assert (k*v).is_nonpositive == None379 assert (n*u).is_nonpositive == None380 assert (n*v).is_nonpositive == True381 assert (v*k*u).is_nonpositive == None382 assert (v*n*u).is_nonpositive == True383 assert (-v*k*u).is_nonpositive == True384 assert (-v*n*u).is_nonpositive == None385 assert (17*v*k*u).is_nonpositive == None386 assert (17*v*n*u).is_nonpositive == True387 assert (k*v*n*u).is_nonpositive == None388 assert (x*k).is_nonpositive == None389 assert (u*v*n*x*k).is_nonpositive == None390 assert k.is_nonnegative == False391 assert (-k).is_nonnegative == True392 assert (2*k).is_nonnegative == False393 assert n.is_nonnegative == True394 assert (-n).is_nonnegative == False395 assert (2*n).is_nonnegative == True396 assert (n*k).is_nonnegative == False397 assert (2*n*k).is_nonnegative == False398 assert (-n*k).is_nonnegative == True399 assert u.is_nonnegative == True400 assert (-u).is_nonnegative == None401 assert (2*u).is_nonnegative == True402 assert v.is_nonnegative == None403 assert (-v).is_nonnegative == True404 assert (2*v).is_nonnegative == None405 assert (u*v).is_nonnegative == None406 assert (k*u).is_nonnegative == None407 assert (k*v).is_nonnegative == True408 assert (n*u).is_nonnegative == True409 assert (n*v).is_nonnegative == None410 assert (v*k*u).is_nonnegative == True411 assert (v*n*u).is_nonnegative == None412 assert (-v*k*u).is_nonnegative == None413 assert (-v*n*u).is_nonnegative == True414 assert (17*v*k*u).is_nonnegative == True415 assert (17*v*n*u).is_nonnegative == None416 assert (k*v*n*u).is_nonnegative == True417 assert (x*k).is_nonnegative == None418 assert (u*v*n*x*k).is_nonnegative == None419def test_Add_is_even_odd():420 x = Symbol('x', integer=True)421 k = Symbol('k', odd=True)422 n = Symbol('n', odd=True)423 m = Symbol('m', even=True)424 assert (k+7).is_even == True425 assert (k+7).is_odd == False426 assert (-k+7).is_even == True427 assert (-k+7).is_odd == False428 assert (k-12).is_even == False429 assert (k-12).is_odd == True430 assert (-k-12).is_even == False431 assert (-k-12).is_odd == True432 assert (k+n).is_even == True433 assert (k+n).is_odd == False434 assert (k+m).is_even == False435 assert (k+m).is_odd == True436 assert (k+n+m).is_even == True437 assert (k+n+m).is_odd == False438 assert (k+n+x+m).is_even == None439 assert (k+n+x+m).is_odd == None440def test_Add_is_negative_positive():441 x = Symbol('x', real=True)442 k = Symbol('k', negative=True)443 n = Symbol('n', positive=True)444 u = Symbol('u', nonnegative=True)445 v = Symbol('v', nonpositive=True)446 assert (k-2).is_negative == True447 assert (k+17).is_negative == None448 assert (-k-5).is_negative == None449 assert (-k+123).is_negative == False450 assert (k-n).is_negative == True451 assert (k+n).is_negative == None452 assert (-k-n).is_negative == None453 assert (-k+n).is_negative == False454 assert (k-n-2).is_negative == True455 assert (k+n+17).is_negative == None456 assert (-k-n-5).is_negative == None457 assert (-k+n+123).is_negative == False458 assert (-2*k+123*n+17).is_negative == False459 assert (k+u).is_negative == None460 assert (k+v).is_negative == True461 assert (n+u).is_negative == False462 assert (n+v).is_negative == None463 assert (u-v).is_negative == False464 assert (u+v).is_negative == None465 assert (-u-v).is_negative == None466 assert (-u+v).is_negative == None467 assert (u-v+n+2).is_negative == False468 assert (u+v+n+2).is_negative == None469 assert (-u-v+n+2).is_negative == None470 assert (-u+v+n+2).is_negative == None471 assert (k+x).is_negative == None472 assert (k+x-n).is_negative == None473 assert (k-2).is_positive == False474 assert (k+17).is_positive == None475 assert (-k-5).is_positive == None476 assert (-k+123).is_positive == True477 assert (k-n).is_positive == False478 assert (k+n).is_positive == None479 assert (-k-n).is_positive == None480 assert (-k+n).is_positive == True481 assert (k-n-2).is_positive == False482 assert (k+n+17).is_positive == None483 assert (-k-n-5).is_positive == None484 assert (-k+n+123).is_positive == True485 assert (-2*k+123*n+17).is_positive == True486 assert (k+u).is_positive == None487 assert (k+v).is_positive == False488 assert (n+u).is_positive == True489 assert (n+v).is_positive == None490 assert (u-v).is_positive == None491 assert (u+v).is_positive == None492 assert (-u-v).is_positive == None493 assert (-u+v).is_positive == False494 assert (u-v-n-2).is_positive == None495 assert (u+v-n-2).is_positive == None496 assert (-u-v-n-2).is_positive == None497 assert (-u+v-n-2).is_positive == False498 assert (n+x).is_positive == None499 assert (n+x-k).is_positive == None500def test_Add_is_nonpositive_nonnegative():501 x = Symbol('x', real=True)502 k = Symbol('k', negative=True)503 n = Symbol('n', positive=True)504 u = Symbol('u', nonnegative=True)505 v = Symbol('v', nonpositive=True)506 assert (u-2).is_nonpositive == None507 assert (u+17).is_nonpositive == False508 assert (-u-5).is_nonpositive == True509 assert (-u+123).is_nonpositive == None510 assert (u-v).is_nonpositive == None511 assert (u+v).is_nonpositive == None512 assert (-u-v).is_nonpositive == None513 assert (-u+v).is_nonpositive == True514 assert (u-v-2).is_nonpositive == None515 assert (u+v+17).is_nonpositive == None516 assert (-u-v-5).is_nonpositive == None517 assert (-u+v-123).is_nonpositive == True518 assert (-2*u+123*v-17).is_nonpositive == True519 assert (k+u).is_nonpositive == None520 assert (k+v).is_nonpositive == True521 assert (n+u).is_nonpositive == False522 assert (n+v).is_nonpositive == None523 assert (k-n).is_nonpositive == True524 assert (k+n).is_nonpositive == None525 assert (-k-n).is_nonpositive == None526 assert (-k+n).is_nonpositive == False527 assert (k-n+u+2).is_nonpositive == None528 assert (k+n+u+2).is_nonpositive == None529 assert (-k-n+u+2).is_nonpositive == None530 assert (-k+n+u+2).is_nonpositive == False531 assert (u+x).is_nonpositive == None532 assert (v-x-n).is_nonpositive == None533 assert (u-2).is_nonnegative == None534 assert (u+17).is_nonnegative == True535 assert (-u-5).is_nonnegative == False536 assert (-u+123).is_nonnegative == None537 assert (u-v).is_nonnegative == True538 assert (u+v).is_nonnegative == None539 assert (-u-v).is_nonnegative == None540 assert (-u+v).is_nonnegative == None541 assert (u-v+2).is_nonnegative == True542 assert (u+v+17).is_nonnegative == None543 assert (-u-v-5).is_nonnegative == None544 assert (-u+v-123).is_nonnegative == False545 assert (2*u-123*v+17).is_nonnegative == True546 assert (k+u).is_nonnegative == None547 assert (k+v).is_nonnegative == False548 assert (n+u).is_nonnegative == True549 assert (n+v).is_nonnegative == None550 assert (k-n).is_nonnegative == False551 assert (k+n).is_nonnegative == None552 assert (-k-n).is_nonnegative == None553 assert (-k+n).is_nonnegative == True554 assert (k-n-u-2).is_nonnegative == False555 assert (k+n-u-2).is_nonnegative == None556 assert (-k-n-u-2).is_nonnegative == None557 assert (-k+n-u-2).is_nonnegative == None558 assert (u-x).is_nonnegative == None559 assert (v+x+n).is_nonnegative == None560def test_Pow_is_integer():561 x = Symbol('x')562 k = Symbol('k', integer=True)563 n = Symbol('n', nni=True)564 m = Symbol('m', pi=True)565 assert (k**2).is_integer == True566 assert (k**(-2)).is_integer == False567 assert (2**k).is_integer == None568 assert (2**(-k)).is_integer == None569 assert (2**n).is_integer == True570 assert (2**(-n)).is_integer == None571 assert (2**m).is_integer == True572 assert (2**(-m)).is_integer == False573 assert (x**2).is_integer == None574 assert (2**x).is_integer == None575 assert (k**n).is_integer == True576 assert (k**(-n)).is_integer == None577 assert (k**x).is_integer == None578 assert (x**k).is_integer == None579 assert (k**(n*m)).is_integer == True580 assert (k**(-n*m)).is_integer == None581@XFAIL582def test_Pow_is_bounded():583 x = Symbol('x', real=True)584 assert (x**2).is_bounded == None585 assert (sin(x)**2).is_bounded == True586 assert (sin(x)**x).is_bounded == None587 assert (sin(x)**exp(x)).is_bounded == None588 # XXX This first one fails589 assert (1/sin(x)).is_bounded == False590 assert (1/exp(x)).is_bounded == False591def test_Pow_is_even_odd():592 x = Symbol('x')593 k = Symbol('k', even=True)594 n = Symbol('n', odd=True)595 m = Symbol('m', nni=True)596 assert (k**2).is_even == True597 assert (n**2).is_even == False598 assert (2**k).is_even == None599 assert (k**m).is_even == True600 assert (n**m).is_even == False601 assert (k**x).is_even == None602 assert (n**x).is_even == None603 assert (k**2).is_odd == False604 assert (n**2).is_odd == True605 assert (3**k).is_odd == None606 assert (k**m).is_odd == False607 assert (n**m).is_odd == True608 assert (k**x).is_odd == None609 assert (n**x).is_odd == None610def test_Pow_is_negative_positive():611 x = Symbol('x', real=True)612 k = Symbol('k', pi=True)613 n = Symbol('n', even=True)614 m = Symbol('m', odd=True)615 assert (2**x).is_positive == True616 assert ((-2)**x).is_positive == None617 assert ((-2)**n).is_positive == True618 assert ((-2)**m).is_positive == False619 assert (k**2).is_positive == True620 assert (k**(-2)).is_positive == True621 assert (k**x).is_positive == True622 assert ((-k)**x).is_positive == None623 assert ((-k)**n).is_positive == True624 assert ((-k)**m).is_positive == False625 assert (2**x).is_negative == False626 assert ((-2)**x).is_negative == None627 assert ((-2)**n).is_negative == False628 assert ((-2)**m).is_negative == True629 assert (k**2).is_negative == False630 assert (k**(-2)).is_negative == False631 assert (k**x).is_negative == False632 assert ((-k)**x).is_negative == None633 assert ((-k)**n).is_negative == False634 assert ((-k)**m).is_negative == True635def test_Pow_is_nonpositive_nonnegative():636 x = Symbol('x', real=True)637 k = Symbol('k', nni=True)638 n = Symbol('n', even=True)639 m = Symbol('m', odd=True)640 assert (2**x).is_nonnegative == True641 assert ((-2)**x).is_nonnegative == None642 assert ((-2)**n).is_nonnegative == True643 assert ((-2)**m).is_nonnegative == False644 assert (k**2).is_nonnegative == True645 assert (k**(-2)).is_nonnegative == True646 assert (k**x).is_nonnegative == True647 assert ((-k)**x).is_nonnegative == None648 assert ((-k)**n).is_nonnegative == True649 assert ((-k)**m).is_nonnegative == None650 assert (2**x).is_nonpositive == False651 assert ((-2)**x).is_nonpositive == None652 assert ((-2)**n).is_nonpositive == False653 assert ((-2)**m).is_nonpositive == True654 assert (k**2).is_nonpositive == None655 assert (k**(-2)).is_nonpositive == None656 assert (k**x).is_nonpositive == None657 assert ((-k)**x).is_nonpositive == None658 assert ((-k)**n).is_nonpositive == None...`

infinity.py

Source:infinity.py

`...4@functools.total_ordering5class Infinity:6 def __init__(self, positive=True):7 self.__positive = positive8 def is_positive(self):9 return self.__positive10 @staticmethod11 def nan_check(to_check):12 if isinstance(to_check, float):13 return math.isnan(to_check)14 return False15 def __repr__(self):16 return "+infinity" if self.is_positive() else "-infinity"17 def __str__(self):18 return self.__repr__()19 def __hash__(self):20 return hash(self.is_positive())21 # +self22 def __pos__(self):23 return Infinity(self.is_positive())24 # -self25 def __neg__(self):26 return Infinity(not self.is_positive())27 # abs(self)28 def __abs__(self):29 return Infinity()30 # self < other31 def __lt__(self, other):32 if Infinity.nan_check(other):33 return False34 elif isinstance(other, Infinity):35 return not self.is_positive() and other.is_positive()36 return not self.is_positive()37 # self == other38 def __eq__(self, other):39 if isinstance(other, Infinity):40 return self.is_positive() == other.is_positive()41 return False42 # self + other43 def __add__(self, other):44 if Infinity.nan_check(other):45 return math.nan46 elif isinstance(other, Infinity):47 if self.is_positive() == other.is_positive():48 return Infinity(self.is_positive())49 else:50 return math.nan51 return Infinity(self.is_positive())52 # other + self == self + other53 def __radd__(self, other):54 return self + other55 # self - other == self + (-other)56 def __sub__(self, other):57 if isinstance(other, Infinity):58 other = -other59 return self + other60 # other - self == (-self) + other61 def __rsub__(self, other):62 return -self + other63 # self * other64 def __mul__(self, other):65 if Infinity.nan_check(other) or other == 0:66 return math.nan67 elif isinstance(other, Infinity):68 return Infinity(self.is_positive() == other.is_positive())69 return Infinity(self.is_positive() == (other > 0))70 71 # other * self == self * other72 def __rmul__(self, other):73 return self * other74 # self / other75 def __truediv__(self, other):76 if other == 0:77 raise ZeroDivisionError()78 if isinstance(other, Infinity):79 return math.nan80 return self * other81 # other / self82 def __rtruediv__(self, other):83 if Infinity.nan_check(other):84 return math.nan85 return 0.0 if self.is_positive() == (other > 0) else -0.086 # self // other87 def __floordiv__(self, other):88 return self / other89 # other // self90 def __rfloordiv__(self, other):91 if Infinity.nan_check(other):92 return math.nan93 return 094 # self % other95 def __mod__(self, other):96 if other == 0:97 raise ZeroDivisionError()98 return math.nan99 # other % self100 def __rmod__(self, other):101 if Infinity.nan_check(other):102 return math.nan103 if other == 0 or (self.is_positive() == (other > 0)):104 return other105 else:106 return Infinity(self.is_positive())107 # divmod(self, other)108 def __divmod__(self, other):109 return (self // other, self % other)110 # divmod(other, self)111 def __rdivmod__(self, other):...`

test_variant_signal.py

Source:test_variant_signal.py

`1from rest_framework.test import APITestCase2from tests.factories import QuestionFactory, VariantFactory3from jobadvisor.polls.models import Variant4class VariantSignalTestCase(APITestCase):5 @classmethod6 def setUpTestData(cls) -> None:7 """8 SetUp test data.9 :return: None10 """11 cls.question = QuestionFactory()12 def test_calculate_weight_some_negative_variant(self) -> None:13 VariantFactory(question=self.question, is_positive=False)14 VariantFactory(question=self.question, is_positive=False)15 negative_variant = Variant.objects.filter(16 question_id=self.question.id,17 is_positive=False18 )19 self.assertEqual(negative_variant.first().weight, 0.5)20 self.assertEqual(negative_variant.last().weight, 0.5)21 def test_calculate_weight_negative_variant(self) -> None:22 VariantFactory(question=self.question, is_positive=False)23 negative_variant = Variant.objects.get(24 question_id=self.question.id,25 is_positive=False26 )27 self.assertEqual(negative_variant.weight, 0)28 def test_calculate_weight_positive_variant(self) -> None:29 VariantFactory(question=self.question, is_positive=True)30 positive_variant = Variant.objects.get(31 question_id=self.question.id,32 is_positive=True33 )34 self.assertEqual(positive_variant.weight, 1)35 def test_recalculate_weight_del_some_negative_variant(self) -> None:36 VariantFactory(question=self.question, is_positive=False)37 VariantFactory(question=self.question, is_positive=False)38 VariantFactory(question=self.question, is_positive=False)39 VariantFactory(question=self.question, is_positive=False)40 negative_variant = Variant.objects.filter(41 question_id=self.question.id,42 is_positive=False43 )44 self.assertEqual(negative_variant.first().weight, 0.25)45 self.assertEqual(negative_variant.last().weight, 0.25)46 negative_variant.first().delete()47 negative_variant.last().delete()48 self.assertEqual(negative_variant.first().weight, 0.5)49 self.assertEqual(negative_variant.last().weight, 0.5)50 def test_recalculate_weight_del_negative_variant(self) -> None:51 VariantFactory(question=self.question, is_positive=False)52 VariantFactory(question=self.question, is_positive=False)53 negative_variant = Variant.objects.filter(54 question_id=self.question.id,55 is_positive=False56 )57 self.assertEqual(negative_variant.first().weight, 0.5)58 self.assertEqual(negative_variant.last().weight, 0.5)59 negative_variant.first().delete()60 self.assertEqual(negative_variant.first().weight, 0)61 def test_recalculate_weight_del_positive_variant(self) -> None:62 VariantFactory(question=self.question, is_positive=True)63 VariantFactory(question=self.question, is_positive=True)64 positive_variant = Variant.objects.filter(65 question_id=self.question.id,66 is_positive=True67 )68 self.assertEqual(positive_variant.first().weight, 1)69 self.assertEqual(positive_variant.last().weight, 1)70 positive_variant.first().delete()...`

## 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.