├── README.md ├── pysimplified.py └── pysimplified_test.py /README.md: -------------------------------------------------------------------------------- 1 | # pysimplified 2 | python simplified functions library 3 | 4 | coming soon... 5 | -------------------------------------------------------------------------------- /pysimplified.py: -------------------------------------------------------------------------------- 1 | ## welcome to line 1 of the official python simplified library! :) 2 | 3 | def quadratic(a, b, c): 4 | ''' 5 | quadratic equation solver function. 6 | equasion: ax² + bx + c = 0. 7 | formula: x=(-b±√(b2-4ac))/2a. 8 | output: tuple of floating point numbers (x1, x2). 9 | ''' 10 | if ( 11 | # accept only integer and float inputs 12 | (type(a), type(b), type(c)) == (int, int, int) or 13 | (type(a), type(b), type(c)) == (float, float, float) 14 | ): 15 | # filter mathematical fallacies 16 | if a != 0: 17 | # solve quadratic formula 18 | x1 = (-b +((b**2) -4*a*c)**(0.5))/(2*a) 19 | x2 = (-b -((b**2) -4*a*c)**(0.5))/(2*a) 20 | else: 21 | # notify about falacy 22 | raise ValueError("input a can't be 0") 23 | return x1, x2 24 | else: 25 | # if input is not an integer or float 26 | raise TypeError("inputs a,b,c must be integers ot floats") 27 | -------------------------------------------------------------------------------- /pysimplified_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import pysimplified as pysf 3 | 4 | class TestPythonSimplifiedLibrary: 5 | def test_library_exists(self): 6 | assert pysf is not None 7 | 8 | def test_quadratic_exists(self): 9 | assert pysf.quadratic is not None 10 | 11 | def test_quadratic_output_tuple(self): 12 | a,b,c = 1,5,6 13 | output = pysf.quadratic(a,b,c) 14 | assert type(output) == tuple 15 | 16 | def test_quadratic_output_tuple_of_floats(self): 17 | a,b,c = 1,5,6 18 | output = pysf.quadratic(a,b,c) 19 | assert type(output[0]) == float 20 | assert type(output[1]) == float 21 | 22 | def test_quadratic_output_tuple_of_two_floats(self): 23 | a,b,c = 1,5,6 24 | output = pysf.quadratic(a,b,c) 25 | assert len(output) == 2 26 | 27 | def test_quadratic_ideal(self): 28 | a,b,c = 1,5,6 29 | output = pysf.quadratic(a,b,c) 30 | assert output == (-2., -3.) 31 | 32 | def test_quadratic_boundary1(self): 33 | ''' 34 | test max boundary inputs 35 | ''' 36 | a = 10000000000000000000 37 | b = 99999999999999999999 38 | c = -7383205930254632388 39 | 40 | output = pysf.quadratic(a,b,c) 41 | 42 | assert type(output) == tuple 43 | assert type(output[0]) == float 44 | assert type(output[1]) == float 45 | print("\n") 46 | print("extremley large:", output) 47 | 48 | def test_quadratic_boundary2(self): 49 | ''' 50 | test min boundary inputs 51 | ''' 52 | a = 0.000000000000000001 53 | b = 0.000000000000000099 54 | c = -0.00000000000000002 55 | 56 | output = pysf.quadratic(a,b,c) 57 | 58 | assert type(output) == tuple 59 | assert type(output[0]) == float 60 | assert type(output[1]) == float 61 | print("extremley small:", output) 62 | 63 | def test_quadratic_bad_math(self): 64 | a,b,c = 0,5,6 65 | with pytest.raises(ValueError): 66 | pysf.quadratic(a,b,c) 67 | --------------------------------------------------------------------------------