-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathmetrictest.py
79 lines (56 loc) · 2.16 KB
/
metrictest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Code listing #28
""" Module metrictest.py - testing static quality metrics of Python code """
# Note: This is the final version of metrictest.py so called just metrictest.py
import random
def sum_fn(xnum, ynum):
""" A function which performs a sum """
return xnum + ynum
def find_optimal_route(start_time,
expected_time,
favorite_route='SBS1K',
favorite_option='bus'):
""" Find optimal route for me to go from home to office.
First two inputs should be datetime instances.
"""
# Convert to minutes
tdiff = (expected_time - start_time).total_seconds()/60.0
options = {range(0, 30): 'car',
range(30, 45): ('car', 'metro'),
range(45, 60): ('bus:335E', 'bus:connector')}
if tdiff < 80:
# Pick the range it falls into
for drange in options:
if tdiff in drange:
return drange[tdiff]
# Might as well go by normal bus
return random.choice(('bus:330', 'bus:331',':'.join((favorite_option,
favorite_route))))
class MiscClassC(object):
""" A class which does almost nothing """
def __init__(self, xnum, ynum):
self.xnum = xnum
self.ynum = ynum
def compare_and_sum(self, xnum=0, ynum=0):
""" Compare local and argument variables
and perform some sums """
if self.xnum > xnum:
return self.xnum + self.ynum
else:
return xnum + self.ynum
class MiscClassD(MiscClassC):
""" Sub-class of MiscClassC """
def __init__(self, xnum, ynum=0):
super(MiscClassD, self).__init__(xnum, ynum)
def some_func(self, xnum,ynum):
""" A function which does summing """
if xnum > ynum:
return xnum - ynum
else:
return xnum + ynum
def compare_and_sum(self, xnum=0, ynum=0):
""" Compare local and argument variables
and perform some sums """
if self.xnum > ynum:
return self.xnum + ynum
else:
return ynum - self.xnum