Пример #1
0
 def test_power_positive(self):  # positive test on power method
     test_data = yaml.load(open('fixtures.yml'))
     pos_int = test_data.get('positive')[0]
     test_obj = sm(pos_int)
     test_power = random.randint(2, 5)
     test_obj_power = test_obj.power(test_power)
     assert (test_obj_power == math.pow(pos_int, test_power))
Пример #2
0
 def test_odd_positive(self):  # positive test on odd/even method
     test_data = yaml.load(open('fixtures.yml'))
     pos_odd_int = test_data.get('positive_odd')[0]
     test_obj = sm(pos_odd_int)
     obj_odd_even = test_obj.odd_or_even()
     odd_even_str = ""
     if (pos_odd_int % 2) == 0:
         odd_even_str = 'Even'
     if (pos_odd_int % 2) == 1:
         odd_even_str = "Odd"
     assert (obj_odd_even == odd_even_str)
Пример #3
0
def test_constructor_float():
    with raises(TypeError):  # if TypeError is raised, the test passes
        test_obj = sm(random.random(1, 10))  # random float between 1 and 10
Пример #4
0
def test_constructor_string():
    with raises(TypeError):  # if TypeError is raised, the test passes
        test_obj = sm("teststring")
Пример #5
0
def test_constructor_boolean():
    with raises(TypeError):  # if TypeError is raised, the test passes
        test_obj = sm(True)
Пример #6
0
import pytest
from pytest import raises
import random
import math
from simplemaths import SimpleMaths as sm

integer = random.randint(
    1, 10)  # create test object with random int between 1 & 10
test_obj = sm(integer)


def test_constructor_positive():  # positive test on sm class constructor
    assert test_obj.number == integer


def test_constructor_boolean():
    with raises(TypeError):  # if TypeError is raised, the test passes
        test_obj = sm(True)


def test_constructor_string():
    with raises(TypeError):  # if TypeError is raised, the test passes
        test_obj = sm("teststring")


def test_constructor_float():
    with raises(TypeError):  # if TypeError is raised, the test passes
        test_obj = sm(random.random(1, 10))  # random float between 1 and 10


def test_square_positive():  # positive test on square method
Пример #7
0
 def test_factorial_positive(self):  # positive test on factorial method
     test_data = yaml.load(open('fixtures.yml'))
     pos_int = test_data.get('positive')[0]
     test_obj = sm(pos_int)
     test_obj_fact = test_obj.factorial()
     assert (test_obj_fact == math.factorial(pos_int))
Пример #8
0
 def test_square_positive(self):  # positive test on square method
     test_data = yaml.load(open('fixtures.yml'))
     pos_int = test_data.get('positive')[0]
     test_obj = sm(pos_int)
     test_obj_square = test_obj.square()
     assert (test_obj_square == math.pow(pos_int, 2))
Пример #9
0
 def test_constructor_float(self):
     test_data = yaml.load(open('fixtures.yml'))
     fl = test_data.get('float')[0]
     with raises(TypeError):  # if TypeError is raised, the test passes
         test_obj = sm(fl)  # random float between 1 and 10
Пример #10
0
 def test_constructor_string(self):
     test_data = yaml.load(open('fixtures.yml'))
     string = test_data.get('string')[0]
     with raises(TypeError):  # if TypeError is raised, the test passes
         test_obj = sm(string)
Пример #11
0
 def test_constructor_boolean(self):
     test_data = yaml.load(open('fixtures.yml'))
     boolean = test_data.get('boolean')[0]
     with raises(TypeError):  # if TypeError is raised, the test passes
         test_obj = sm(boolean)
Пример #12
0
 def test_constructor_positive(
         self):  # positive test on sm class constructor
     test_data = yaml.load(open('fixtures.yml'))
     pos_int = test_data.get('positive')[0]
     test_obj = sm(pos_int)
     assert test_obj.number == pos_int