Exemplo n.º 1
0
    def test_odd_or_even(self):
        for num in np.arange(0, 12, 2):
            test = sm(num)
            assert test.odd_or_even() == 'Even'

        for num in np.arange(1, 11, 2):
            test = sm(num)
            assert test.odd_or_even() == 'Odd'
Exemplo n.º 2
0
    def test_factorial(self):
        test = sm(-4)
        with raises(ValueError) as exception:
            test.factorial()

        for num in range(5):
            test = sm(num)
            assert test.factorial() == math.factorial(num)
Exemplo n.º 3
0
    def test_square_root(self):
        test = sm(-4)
        with raises(ValueError) as exception:
            test.square_root()

        for num in np.arange(5):
            test = sm(num)
            assert test.square_root() == np.sqrt(num)
Exemplo n.º 4
0
    def test_power(self):
        test = sm(3)
        with raises(ValueError) as exception:
            test.power(False)

        for num in range(5):
            test = sm(num)
            for x in np.arange(4):
                assert test.power(x) == math.pow(num, x)
Exemplo n.º 5
0
 def test_odd_or_even(self):
     """ Check that 0 returns as Even and other positive cases """
     zero = sm(0)
     assert zero.odd_or_even() == 'Even'
     one = sm(1)
     assert one.odd_or_even() == 'Odd'
     two = sm(2)
     assert two.odd_or_even() == 'Even'
     minusone = sm(-1)
     assert minusone.odd_or_even() == 'Odd'
Exemplo n.º 6
0
 def test_square_root(self):
     """ Positive tests for 0, int result, float result and complex result """
     zero = sm(0)
     assert zero.square_root() == 0.0
     four = sm(4)
     assert four.square_root() == 2
     twelve = sm(12)
     assert twelve.square_root() == 3.4641016151377544
     minusfour = sm(-4)
     assert minusfour.square_root() == (1.2246467991473532e-16+2j)
     assert type(minusfour.square_root()) == complex
Exemplo n.º 7
0
 def test_constructor_1(self):
     with raises(TypeError):
         sm(3.2)
     with raises(TypeError):
         sm(-123.2)
     with raises(TypeError):
         sm(3 / 2.5)
Exemplo n.º 8
0
 def test_factorial_0(self):
     zero = sm(0)
     assert zero._factorial(0) == 1
Exemplo n.º 9
0
 def test_square(self):
     twelve = sm(12)
     assert sm.square(twelve) == 12**2
Exemplo n.º 10
0
 def test_constructor_type(self):
     """ Check that the constructor creates an 'sm'-type object """
     twelve = sm(12)
     assert type(twelve) == sm
Exemplo n.º 11
0
 def test_power_2(self):
     test_num_neg = sm(0 - test_num.number)
     assert test_num_neg.power(2) == test_num.power(rand_index)
Exemplo n.º 12
0
 def test_factorial(self):
     a = sm(5)
     assert a.factorial() == 120
Exemplo n.º 13
0
 def test_power_inputs(self):
     """ Check result for float input to power """
     twelve = sm(12)
     assert twelve.power(3.0) == 12**3.0
Exemplo n.º 14
0
 def test_power_default(self):
     """ Check that the power defaults to 3 """
     twelve = sm(12)
     assert twelve.power() == 12**3
Exemplo n.º 15
0
from pytest import raises
import random
import math
from simplemaths.simplemaths import SimpleMaths as sm

rand_int = random.randint(1, 12)
test_num = sm(rand_int)

class TestSimpleMaths():
    
    def test_constructor_pos(self):
        # positive constructor test for int type 
        assert type(test_num.number) == int
            
    def test_constructor_float(self):
        # negative constructor test for float input
        rand_float = random.uniform(1, 12)
        with raises(TypeError):
            a = sm(rand_float)

    def test_constructor_string(self):
        # positive constructor test for int type 
        rand_string = str(test_num)
        with raises (TypeError):
            b = sm(rand_string)
    
    def test_square(self):
        assert test_num.square() == test_num.number ** 2
    
    def test_factorial(self):
        test_fac = math.factorial(test_num.number)
Exemplo n.º 16
0
 def test_constructor_float(self):
     # negative constructor test for float input
     rand_float = random.uniform(1, 12)
     with raises(TypeError):
         a = sm(rand_float)
Exemplo n.º 17
0
 def test_constructor_string(self):
     # positive constructor test for int type 
     rand_string = str(test_num)
     with raises (TypeError):
         b = sm(rand_string)
Exemplo n.º 18
0
 def test_square(self):
     for num in range(5):
         test = sm(num)
         assert test.square() == np.square(num)
Exemplo n.º 19
0
 def test_constructor_input_boolean(self):
     with raises(ValueError) as exception:
         test = sm(False)
Exemplo n.º 20
0
 def test_constructor_input_complex(self):
     with raises(ValueError) as exception:
         test = sm(2j)
Exemplo n.º 21
0
 def test_constructor_input_string(self):
     with raises(ValueError) as exception:
         test = sm('a')
Exemplo n.º 22
0
 def test_factorial_proper(self):
     twelve = sm(12)
     assert sm.factorial(twelve) == 479001600
     zero = sm(0)
     assert sm.factorial(zero) == 1
Exemplo n.º 23
0
 def test_power(self):
     """ Check result for int inputs to power """
     twelve = sm(12)
     assert twelve.power(0) == 1
     minustwo = sm(-2)
     assert minustwo.power(2) == 4
Exemplo n.º 24
0
 def test_non_int_power(self):
     a = sm(2)
     assert a.power(2.5) == pytest.approx(5.656, 0.001)
Exemplo n.º 25
0
 def test_constructor_input(self):
     """ Check that some non-integer inputs will fail """
     with raises(TypeError) as exception:
         sm(1.0)
     with raises(TypeError) as exception:
         sm("string")
Exemplo n.º 26
0
 def test_constructor_input_float(self):
     with raises(ValueError) as exception:
         test = sm(0.1)
Exemplo n.º 27
0
 def test_power_inputs(self):
     """ Check that a non-int/float input will fail """
     twelve = sm(12)
     with raises(TypeError) as exception:
         twelve.power('three')
Exemplo n.º 28
0
 def test_constructor_input_empty(self):
     """ Check that an empty input will fail """
     with raises(TypeError) as exception:
         sm()
Exemplo n.º 29
0
 def test_constructor_number(self):
     """ Check that the .number attribute returns the inputted integer """
     twelve = sm(12)
     assert twelve.number == 12
Exemplo n.º 30
0
 def test_factorial_neg(self):
     test_num_neg = sm(0 - test_num.number)
     with raises(Exception):
        c =  test_num_neg.factorial()