def test_function_100times_eq_100q(): q1 = Qualean(random.choice(states)) new_q = Qualean(0) for _ in range(100): new_q += q1.q assert math.isclose(new_q, q1 * 100, rel_tol=1e-4)
def test_qualean_lt(): q1, q2 = Qualean(1), Qualean(0) if q1.number > 0: q1 = q1.__invertsign__() assert q1 < q2
def test_qualean_value(): q1 = Qualean(1) q2 = Qualean(0) q3 = Qualean(-1) assert q1.number >= -1 and q1.number <= 1 assert q2.number == 0 assert q3.number >= -1 and q1.number <= 1
def test_qualean_gt(): q1, q2 = Qualean(1), Qualean(0) if q1.number < 0: q1 = q1.__invertsign__() assert q1 > q2
def test_qualean_le(): q1, q2, q3 = Qualean(1), Qualean(0), Qualean(0) if q1.number > 0: q1 = q1.__invertsign__() assert q1 <= q2 assert q2 <= q3
def test_qualean_ge(): q1, q2, q3 = Qualean(1), Qualean(0), Qualean(0) if q1.number < 0: q1 = q1.__invertsign__() assert q1 >= q2 assert q2 >= q3
def test_qualean_sqrt(): decimal.getcontext().prec = 10 sign = lambda x : copysign(1.0, x) q = Qualean(-1) if q.number < 0: q = q.__invertsign__() assert q.__sqrt__() == Decimal(q.number).sqrt()
def test_addition(): num = random.choice([-1, 0, 1]) q = Qualean(num) sum_of_q = Qualean(0) for i in range(100): sum_of_q = q + sum_of_q # print(sum_of_q) # return sum_of_q # return sum_of_q == q*100 # print(sum_of_q,q*100) # return sum_of_q == q *100 assert sum_of_q == q * 100, "summing of q 100 times is equal to q multiplied by 100"
def test_qualean_and(): q1 = Qualean(1) q2 = Qualean(0) q3 = Qualean(-1) i = 113 if q1 and q3: assert q1.__and__(q3) assert not q1.__and__(q2) assert not q3.__and__(q2) assert not q2.__and__(i)
def test_qualean_or(): q1 = Qualean(1) q2 = Qualean(0) q3 = Qualean(-1) i = 113 if q1 or q3: assert q1.__or__(q3) assert q1.__or__(q2) assert q3.__or__(q2) if q1: assert q1.__or__(i)
def test_million_q_sum(): result = 0 for _ in range(0,1000000): x = random.choice([0, -1, 1]) result += Qualean(x).number assert math.isclose(result, 0, abs_tol = 1000), ("not nearing to 0", result)
def test_repetitive_addition_multiplication(): q = Qualean(random.choice([0, -1, 1])) res = 0 for _ in range(0, 100): res += q.number assert round(res,10) == round(100 * q.number,10)
def test_function_decimal_sqrt_check(): q1 = Qualean(1) Decimal_Test=False print(Decimal_Test) if q1.q >= 0: with decimal.localcontext() as ctx: ctx.prec = 10 ctx.rounding = decimal.ROUND_HALF_EVEN if q1.__sqrt__() == Decimal(str(q1)).sqrt(context=ctx): Decimal_Test=True pass else: pass else: Decimal_Test= True print(Decimal_Test) assert Decimal_Test == True, "Check your the function"
def test_invertsign(): q1 = Qualean(random.choice([-1, 0, 1])) if q1.get_number() < 0: assert (q1.__invertsign__() > 0) == True, "invertsign not working" elif q1.get_number() > 0: assert (q1.__invertsign__() < 0) == True, "invertsign not working" else: assert (q1.__invertsign__() == 0) == True, "invertsign not working"
def test_function_sum_million_q_eq_zero(): q1 = 0 TEST_million = True for x in range(100001): q = random.choice(states) q = Qualean(q) q1 = q1 + q.q print(q1) else: if math.isclose(q1, 0): TEST_million=False assert TEST_million== True, 'Check'
def test_or_functionality(): q1 = Qualean(random.choice([-1, 0, 1])) q2 = Qualean(random.choice([-1, 0, 1])) if q1.get_number() != 0 or q2.get_number() != 0: assert q1 | q2 == True, "or True case is not working as expected" else: assert q1 | q2 == False, "or False case is not working as expected"
def test_lt(): q1 = Qualean(random.choice([-1, 0, 1])) q2 = Qualean(random.choice([-1, 0, 1])) if q1.get_number() < q2.get_number(): assert (q1 < q2) == True, "__lt__ True case not working" else: assert (q1 < q2) == False, "__lt__ False case not working"
def test_ge(): q1 = Qualean(random.choice([-1, 0, 1])) q2 = Qualean(random.choice([-1, 0, 1])) if q1.get_number() >= q2.get_number(): # print(q1.get_number()) # print(q2.get_number()) # print(True) assert (q1 >= q2) == True, "__ge__ True case not working" else: # print(q1.get_number()) # print(q2.get_number()) # print(False) assert (q1 >= q2) == False, "__ge__ False case not working"
def test_function_equality_true(): q1 = Qualean(random.choice(states)) assert q1 == q1
def test_function_bool(): q1 = Qualean(1) assert bool(q1) q1 = Qualean(0) assert not bool(q1)
def test_function_add(): q1 = Qualean(random.choice(states)) q2 = Qualean(random.choice(states)) assert math.isclose(q1.__add__(q2), q1.q+q2.q, rel_tol=1e-8 )
def test_function_str(): assert "object at" not in Qualean(random.choice(states)).__str__()
def test_function_invalid_integer_input(): with pytest.raises(ValueError) as execinfo: _ = Qualean(2) assert "ValueError" in str(execinfo)
def test_function_valid_input(): q1 = Qualean(random.choice(states)) assert isinstance(q1, Qualean)
def test_function_equality_false(): q1 = Qualean(1) q2 = Qualean(0) assert not q1 == q2
def test_function_less_than_equal_to(): q1 = Qualean(random.choice(states)) assert q1 <= q1 + 1
def test_function_lesser_than(): q1 = Qualean(random.choice(states)) assert q1 < q1 + 1
def test_function_greater_than_equal_to(): q1 = Qualean(random.choice(states)) assert q1 + 1 >= q1
def test_function_greater(): q1 = Qualean(random.choice(states)) assert q1 + 1 > q1
def test_function_float_conversion(): q1 = Qualean(random.choice(states)) assert isinstance(q1.__float__(), float)