Skip to content

Commit bd731d2

Browse files
committed
add test_methodcaller
1 parent da91bc5 commit bd731d2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test_methodcaller.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import math
2+
import sortingx
3+
from operator import methodcaller
4+
5+
class Point:
6+
def __init__(self, a, b, c, d):
7+
self.a = a
8+
self.b = b
9+
self.c = c
10+
self.d = d
11+
def __repr__(self):
12+
return 'Point({!r:},{!r:},{!r:},{!r:})'.format(self.a, self.b, self.c, self.d)
13+
def distance(self, a, b, c, d):
14+
return math.hypot(self.a - a, self.b - b, self.c - c, self.d - d)
15+
16+
points = [
17+
Point(1, 2, 3, 4),
18+
Point(1, -1, 1, -1),
19+
Point(3, 0, -2, 1),
20+
Point(2, -2, 3, 2),
21+
Point(-1, 2, 0, 1),
22+
Point(1, 1, 1, 1),
23+
Point(-2, -1, -3, 0),
24+
Point(2, 0, 1, 1),
25+
Point(1, -3, -2, -1)
26+
]
27+
28+
print(sortingx.heap(points, key=methodcaller('distance', 0, 0, 0, 0)))

0 commit comments

Comments
 (0)