Skip to content

Commit 9c1d282

Browse files
Hai Hoang Danggoswami-rahul
Hai Hoang Dang
authored andcommitted
Add coverall to algorithms (#261)
* Add coverall to Algorithms * Add .coverage to gitignore * Fix prime_test in tests.math * Add coveral badge to README * Change the prime_test to prime_check
1 parent 463e9fb commit 9c1d282

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

.coveragerc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[report]
2+
omit =
3+
*/python?.?/*
4+
*/site-packages/nose/*
5+
*__init__*

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ __pycache__/
22
*.py[cod]
33
.idea/
44
.cache/
5-
.pytest_cache/
5+
.pytest_cache/
6+
.coverage

.travis.yml

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ matrix:
1212
install:
1313
- pip install -r requirements.txt
1414
- pip install flake8 # pytest # add another testing frameworks later
15+
- pip install python-coveralls
16+
- pip install coverage
17+
- pip install nose
1518
before_script:
1619
# stop the build if there are Python syntax errors or undefined names
1720
- flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
@@ -22,6 +25,11 @@ script:
2225
- python3 -m unittest discover tests
2326
# Check pytest running
2427
- python3 -m pytest tests
28+
# Run nose with coverage support
29+
- nosetests --with-coverage
2530
notifications:
2631
on_success: change
2732
on_failure: change # `always` will be the setting once code changes slow down
33+
34+
after_success:
35+
- coveralls

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ English | [简体中文](https://github.com/yunshuipiao/algorithms/blob/master/R
22

33
[![Open Source Helpers](https://www.codetriage.com/keon/algorithms/badges/users.svg)](https://www.codetriage.com/keon/algorithms)
44
[![Build Status](https://travis-ci.org/keon/algorithms.svg?branch=master)](https://travis-ci.org/keon/algorithms)
5+
[![Coverage Status](https://coveralls.io/repos/github/keon/algorithms/badge.svg?branch=master)](https://coveralls.io/github/keon/algorithms?branch=master)
56

67
Pythonic Data Structures and Algorithms
78
=========================================
@@ -153,7 +154,7 @@ For running all tests write down:
153154
- [next_bigger](maths/next_bigger.py)
154155
- [next_perfect_square](maths/next_perfect_square.py)
155156
- [nth_digit](maths/nth_digit.py)
156-
- [prime_test](maths/prime_test.py)
157+
- [prime_check](maths/prime_check.py)
157158
- [primes_sieve_of_eratosthenes](maths/primes_sieve_of_eratosthenes.py)
158159
- [pythagoras](maths/pythagoras.py)
159160
- [rabin_miller](maths/rabin_miller.py)

maths/prime_test.py renamed to maths/prime_check.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
prime_test(n) returns a True if n is a prime number else it returns False
33
"""
44

5-
def prime_test(n):
5+
def prime_check(n):
66
if n <= 1:
77
return False
88
if n == 2 or n == 3:
@@ -17,7 +17,7 @@ def prime_test(n):
1717
return True
1818

1919

20-
def prime_test2(n):
20+
def prime_check2(n):
2121
# prime numbers are greater than 1
2222
if n > 1:
2323
# check for factors
@@ -26,11 +26,11 @@ def prime_test2(n):
2626
# print(num, "is not a prime number")
2727
# print(i, "times", num//i, "is", num)
2828
return False
29-
29+
3030
# print(num, "is a prime number")
3131
return True
3232

3333
# if input number is less than
3434
# or equal to 1, it is not prime
3535
else:
36-
return False
36+
return False

tests/test_maths.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from maths.generate_strobogrammtic import gen_strobogrammatic, strobogrammatic_in_range
55
from maths.is_strobogrammatic import is_strobogrammatic, is_strobogrammatic2
66
from maths.next_perfect_square import find_next_square, find_next_square2
7-
from maths.prime_test import prime_test
7+
from maths.prime_check import prime_check, prime_check2
88
from maths.primes_sieve_of_eratosthenes import primes
99
from maths.pythagoras import pythagoras
1010
from maths.rabin_miller import is_prime
@@ -96,7 +96,7 @@ def test_is_strobogrammatic2(self):
9696
class TestNextPerfectSquare(unittest.TestCase):
9797
"""[summary]
9898
Test for the file next_perfect_square.py
99-
99+
100100
Arguments:
101101
unittest {[type]} -- [description]
102102
"""
@@ -137,7 +137,7 @@ def test_prime_test(self):
137137
"""
138138
counter = 0
139139
for i in range(2, 101):
140-
if prime_test(i):
140+
if prime_check(i):
141141
counter += 1
142142
self.assertEqual(25, counter)
143143

@@ -148,14 +148,14 @@ def test_prime_test2(self):
148148
"""
149149
counter = 0
150150
for i in range(2, 101):
151-
if prime_test(i):
151+
if prime_check2(i):
152152
counter += 1
153153
self.assertEqual(25, counter)
154154

155155

156156
class TestPythagoras(unittest.TestCase):
157157
"""[summary]
158-
Test for the file pythagoras.py
158+
Test for the file pythagoras.py
159159
160160
Arguments:
161161
unittest {[type]} -- [description]
@@ -188,7 +188,7 @@ class TestRSA(unittest.TestCase):
188188
"""
189189

190190
def test_encrypt_decrypt(self):
191-
191+
192192
self.assertEqual(7, decrypt(encrypt(7, 23, 143), 47, 143))
193193

194194
# def test_key_generator(self): # this test takes a while!

0 commit comments

Comments
 (0)