예제 #1
0
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)
예제 #2
0
def test_qualean_lt():
    q1, q2 = Qualean(1), Qualean(0)

    if q1.number > 0:
        q1 = q1.__invertsign__()

    assert q1 < q2
예제 #3
0
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
예제 #4
0
def test_qualean_gt():
    q1, q2 = Qualean(1), Qualean(0)
    
    if q1.number < 0:
        q1 = q1.__invertsign__()

    assert q1 > q2
예제 #5
0
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
예제 #6
0
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
예제 #7
0
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()
예제 #8
0
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"
예제 #9
0
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)
예제 #10
0
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)
예제 #11
0
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)
예제 #12
0
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)
예제 #13
0
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"
예제 #15
0
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"
예제 #19
0
def test_function_equality_true():
    q1 = Qualean(random.choice(states))
    assert q1 == q1
예제 #20
0
def test_function_bool():
    q1 = Qualean(1)
    assert bool(q1)
    q1 = Qualean(0)
    assert not bool(q1)
예제 #21
0
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 )
예제 #22
0
def test_function_str():
    assert "object at" not in Qualean(random.choice(states)).__str__()
예제 #23
0
def test_function_invalid_integer_input():
    with pytest.raises(ValueError) as execinfo:
        _ = Qualean(2)
    assert "ValueError" in str(execinfo)
예제 #24
0
def test_function_valid_input():
    q1 = Qualean(random.choice(states))
    assert isinstance(q1, Qualean)
예제 #25
0
def test_function_equality_false():
    q1 = Qualean(1)
    q2 = Qualean(0)
    assert not q1 == q2
예제 #26
0
def test_function_less_than_equal_to():
    q1 = Qualean(random.choice(states))
    assert q1 <= q1 + 1
예제 #27
0
def test_function_lesser_than():
    q1 = Qualean(random.choice(states))
    assert q1 < q1 + 1
예제 #28
0
def test_function_greater_than_equal_to():
    q1 = Qualean(random.choice(states))
    assert q1 + 1 >= q1
예제 #29
0
def test_function_greater():
    q1 = Qualean(random.choice(states))
    assert q1 + 1 > q1
예제 #30
0
def test_function_float_conversion():
    q1 = Qualean(random.choice(states))
    assert isinstance(q1.__float__(), float)