mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 23:11:09 +00:00
Travis CI: Add a flake8 test for unused imports (#1038)
This commit is contained in:
parent
46bcee0978
commit
3c8e9314b6
|
@ -6,7 +6,7 @@ before_install: pip install --upgrade pip setuptools
|
||||||
install: pip install -r requirements.txt
|
install: pip install -r requirements.txt
|
||||||
before_script:
|
before_script:
|
||||||
- black --check . || true
|
- black --check . || true
|
||||||
- flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
- flake8 . --count --select=E9,F401,F63,F7,F82 --show-source --statistics
|
||||||
script:
|
script:
|
||||||
- mypy --ignore-missing-imports .
|
- mypy --ignore-missing-imports .
|
||||||
- pytest . --doctest-modules
|
- pytest . --doctest-modules
|
||||||
|
|
|
@ -16,10 +16,19 @@ while Q is non-empty:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import collections
|
G = {'A': ['B', 'C'],
|
||||||
|
'B': ['A', 'D', 'E'],
|
||||||
|
'C': ['A', 'F'],
|
||||||
|
'D': ['B'],
|
||||||
|
'E': ['B', 'F'],
|
||||||
|
'F': ['C', 'E']}
|
||||||
|
|
||||||
|
|
||||||
def bfs(graph, start):
|
def bfs(graph, start):
|
||||||
|
"""
|
||||||
|
>>> ''.join(sorted(bfs(G, 'A')))
|
||||||
|
'ABCDEF'
|
||||||
|
"""
|
||||||
explored, queue = set(), [start] # collections.deque([start])
|
explored, queue = set(), [start] # collections.deque([start])
|
||||||
explored.add(start)
|
explored.add(start)
|
||||||
while queue:
|
while queue:
|
||||||
|
@ -31,11 +40,5 @@ def bfs(graph, start):
|
||||||
return explored
|
return explored
|
||||||
|
|
||||||
|
|
||||||
G = {'A': ['B', 'C'],
|
if __name__ == '__main__':
|
||||||
'B': ['A', 'D', 'E'],
|
print(bfs(G, 'A'))
|
||||||
'C': ['A', 'F'],
|
|
||||||
'D': ['B'],
|
|
||||||
'E': ['B', 'F'],
|
|
||||||
'F': ['C', 'E']}
|
|
||||||
|
|
||||||
print(bfs(G, 'A'))
|
|
||||||
|
|
|
@ -6,8 +6,6 @@ Wikipedia reference: https://en.wikipedia.org/wiki/Volume
|
||||||
|
|
||||||
from math import pi
|
from math import pi
|
||||||
|
|
||||||
PI = pi
|
|
||||||
|
|
||||||
|
|
||||||
def vol_cube(side_length):
|
def vol_cube(side_length):
|
||||||
"""Calculate the Volume of a Cube."""
|
"""Calculate the Volume of a Cube."""
|
||||||
|
@ -39,9 +37,7 @@ def vol_right_circ_cone(radius, height):
|
||||||
volume = (1/3) * pi * radius^2 * height
|
volume = (1/3) * pi * radius^2 * height
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import math
|
return (float(1) / 3) * pi * (radius ** 2) * height
|
||||||
|
|
||||||
return (float(1) / 3) * PI * (radius ** 2) * height
|
|
||||||
|
|
||||||
|
|
||||||
def vol_prism(area_of_base, height):
|
def vol_prism(area_of_base, height):
|
||||||
|
@ -71,7 +67,7 @@ def vol_sphere(radius):
|
||||||
V = (4/3) * pi * r^3
|
V = (4/3) * pi * r^3
|
||||||
Wikipedia reference: https://en.wikipedia.org/wiki/Sphere
|
Wikipedia reference: https://en.wikipedia.org/wiki/Sphere
|
||||||
"""
|
"""
|
||||||
return (float(4) / 3) * PI * radius ** 3
|
return (float(4) / 3) * pi * radius ** 3
|
||||||
|
|
||||||
|
|
||||||
def vol_circular_cylinder(radius, height):
|
def vol_circular_cylinder(radius, height):
|
||||||
|
@ -80,7 +76,7 @@ def vol_circular_cylinder(radius, height):
|
||||||
Wikipedia reference: https://en.wikipedia.org/wiki/Cylinder
|
Wikipedia reference: https://en.wikipedia.org/wiki/Cylinder
|
||||||
volume = pi * radius^2 * height
|
volume = pi * radius^2 * height
|
||||||
"""
|
"""
|
||||||
return PI * radius ** 2 * height
|
return pi * radius ** 2 * height
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -39,12 +39,14 @@ goldbach(number) // Goldbach's assumption
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from math import sqrt
|
||||||
|
|
||||||
|
|
||||||
def isPrime(number):
|
def isPrime(number):
|
||||||
"""
|
"""
|
||||||
input: positive integer 'number'
|
input: positive integer 'number'
|
||||||
returns true if 'number' is prime otherwise false.
|
returns true if 'number' is prime otherwise false.
|
||||||
"""
|
"""
|
||||||
import math # for function sqrt
|
|
||||||
|
|
||||||
# precondition
|
# precondition
|
||||||
assert isinstance(number,int) and (number >= 0) , \
|
assert isinstance(number,int) and (number >= 0) , \
|
||||||
|
@ -56,7 +58,7 @@ def isPrime(number):
|
||||||
if number <= 1:
|
if number <= 1:
|
||||||
status = False
|
status = False
|
||||||
|
|
||||||
for divisor in range(2,int(round(math.sqrt(number)))+1):
|
for divisor in range(2,int(round(sqrt(number)))+1):
|
||||||
|
|
||||||
# if 'number' divisible by 'divisor' then sets 'status'
|
# if 'number' divisible by 'divisor' then sets 'status'
|
||||||
# of false and break up the loop.
|
# of false and break up the loop.
|
||||||
|
@ -143,8 +145,6 @@ def primeFactorization(number):
|
||||||
returns a list of the prime number factors of 'number'
|
returns a list of the prime number factors of 'number'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import math # for function sqrt
|
|
||||||
|
|
||||||
# precondition
|
# precondition
|
||||||
assert isinstance(number,int) and number >= 0, \
|
assert isinstance(number,int) and number >= 0, \
|
||||||
"'number' must been an int and >= 0"
|
"'number' must been an int and >= 0"
|
||||||
|
@ -497,8 +497,6 @@ def getDivisors(n):
|
||||||
# precondition
|
# precondition
|
||||||
assert isinstance(n,int) and (n >= 1), "'n' must been int and >= 1"
|
assert isinstance(n,int) and (n >= 1), "'n' must been int and >= 1"
|
||||||
|
|
||||||
from math import sqrt
|
|
||||||
|
|
||||||
ans = [] # will be returned.
|
ans = [] # will be returned.
|
||||||
|
|
||||||
for divisor in range(1,n+1):
|
for divisor in range(1,n+1):
|
||||||
|
|
|
@ -3,18 +3,12 @@ Problem Statement:
|
||||||
Work out the first ten digits of the sum of the following one-hundred 50-digit
|
Work out the first ten digits of the sum of the following one-hundred 50-digit
|
||||||
numbers.
|
numbers.
|
||||||
"""
|
"""
|
||||||
from __future__ import print_function
|
|
||||||
import os
|
|
||||||
|
|
||||||
try:
|
|
||||||
raw_input # Python 2
|
|
||||||
except NameError:
|
|
||||||
raw_input = input # Python 3
|
|
||||||
|
|
||||||
|
|
||||||
def solution(array):
|
def solution(array):
|
||||||
"""Returns the first ten digits of the sum of the array elements.
|
"""Returns the first ten digits of the sum of the array elements.
|
||||||
|
|
||||||
|
>>> import os
|
||||||
>>> sum = 0
|
>>> sum = 0
|
||||||
>>> array = []
|
>>> array = []
|
||||||
>>> with open(os.path.dirname(__file__) + "/num.txt","r") as f:
|
>>> with open(os.path.dirname(__file__) + "/num.txt","r") as f:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user