-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.py
More file actions
88 lines (76 loc) · 1.7 KB
/
examples.py
File metadata and controls
88 lines (76 loc) · 1.7 KB
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
80
81
82
83
84
85
86
87
88
from ftrace import ftrace
@ftrace
def foo( num = 10 ):
"""
Used for testing functions with zero or one arguments, using default
assignment. Also great for testing values pased by keyword.
"""
if num > 0:
foo( num - 1)
return num
@ftrace
def foobar( const, num = 10 ):
"""
Used for testing calls that can have multiple (or singular) parameters and
for setting parameters by name.
"""
if num > 0:
foobar( const, num - 1 )
return const
@ftrace
def one( num = 10 ):
"""
Demonstrates recursive calls between two functions.
"""
if num > 0:
two( num - 1 )
return num
@ftrace
def two( num = 10 ):
"""
See one().
For a good time, try removing @ftrace from either declaration and see what
happens.
"""
if num > 0:
one( num - 1 )
return num
@ftrace
def qsort( unsorted_list ):
"""
A naive Quicksort implementation.
"""
if len( unsorted_list ) < 2:
return unsorted_list
pivot = unsorted_list[0]
pivot_count = 0
smaller = list()
larger = list()
for element in unsorted_list:
if element == pivot:
pivot_count += 1
elif element < pivot:
smaller.append(element)
else:
larger.append(element)
return qsort(smaller) + ([pivot] * pivot_count) + qsort(larger)
class test():
@ftrace
def method(self):
"""
An object method.
"""
return
@classmethod
@ftrace
def cls_method(cls):
"""
A class method.
"""
return
@staticmethod
@ftrace
def static_method():
"""
A static method.
"""