Skip to content

Commit 93fdc9f

Browse files
cclaussAnupKumarPanwar
authored andcommitted
Travis CI: Add pytest --doctest-modules maths (#1020)
* Travis CI: Add pytest --doctest-modules maths * Update lucas_series.py * Update lucas_series.py
1 parent b35f5d9 commit 93fdc9f

File tree

5 files changed

+35
-29
lines changed

5 files changed

+35
-29
lines changed

.travis.yml

-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ script:
1818
--ignore=machine_learning/perceptron.py
1919
--ignore=machine_learning/random_forest_classification/random_forest_classification.py
2020
--ignore=machine_learning/random_forest_regression/random_forest_regression.py
21-
--ignore=maths/abs_min.py
22-
--ignore=maths/binary_exponentiation.py
23-
--ignore=maths/lucas_series.py
24-
--ignore=maths/sieve_of_eratosthenes.py
2521
after_success:
2622
- python scripts/build_directory_md.py
2723
- cat DIRECTORY.md

maths/abs_min.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
from abs import abs_val
1+
from .abs import abs_val
2+
23

34
def absMin(x):
45
"""
5-
# >>>absMin([0,5,1,11])
6+
>>> absMin([0,5,1,11])
67
0
7-
# >>absMin([3,-10,-2])
8+
>>> absMin([3,-10,-2])
89
-2
910
"""
1011
j = x[0]
@@ -13,9 +14,11 @@ def absMin(x):
1314
j = i
1415
return j
1516

17+
1618
def main():
1719
a = [-3,-1,2,-11]
1820
print(absMin(a)) # = -1
1921

22+
2023
if __name__ == '__main__':
2124
main()

maths/binary_exponentiation.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ def binary_exponentiation(a, n):
1717
return b * b
1818

1919

20-
try:
21-
BASE = int(input('Enter Base : '))
22-
POWER = int(input("Enter Power : "))
23-
except ValueError:
24-
print("Invalid literal for integer")
25-
26-
RESULT = binary_exponentiation(BASE, POWER)
27-
print("{}^({}) : {}".format(BASE, POWER, RESULT))
20+
if __name__ == "__main__":
21+
try:
22+
BASE = int(input("Enter Base : ").strip())
23+
POWER = int(input("Enter Power : ").strip())
24+
except ValueError:
25+
print("Invalid literal for integer")
26+
27+
RESULT = binary_exponentiation(BASE, POWER)
28+
print("{}^({}) : {}".format(BASE, POWER, RESULT))

maths/lucas_series.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
# Lucas Sequence Using Recursion
22

33
def recur_luc(n):
4-
if n == 1:
5-
return n
6-
if n == 0:
7-
return 2
8-
return (recur_luc(n-1) + recur_luc(n-2))
9-
10-
limit = int(input("How many terms to include in Lucas series:"))
11-
print("Lucas series:")
12-
for i in range(limit):
13-
print(recur_luc(i))
4+
"""
5+
>>> recur_luc(1)
6+
1
7+
>>> recur_luc(0)
8+
2
9+
"""
10+
if n == 1:
11+
return n
12+
if n == 0:
13+
return 2
14+
return recur_luc(n - 1) + recur_luc(n - 2)
15+
16+
17+
if __name__ == "__main__":
18+
limit = int(input("How many terms to include in Lucas series:"))
19+
print("Lucas series:")
20+
for i in range(limit):
21+
print(recur_luc(i))

maths/sieve_of_eratosthenes.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import math
44

5-
N = int(input("Enter n: "))
6-
7-
85
def sieve(n):
96
"""Sieve of Eratosthones."""
107
l = [True] * (n + 1)
@@ -26,4 +23,5 @@ def sieve(n):
2623
return prime
2724

2825

29-
print(sieve(N))
26+
if __name__ == "__main__":
27+
print(sieve(int(input("Enter n: ").strip())))

0 commit comments

Comments
 (0)