Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
NOCSurfaceProcesses
GeoSpatialTools
Commits
47e1c8f0
Commit
47e1c8f0
authored
5 months ago
by
Joseph Siddons
Browse files
Options
Download
Email Patches
Plain Diff
test: tests for find_nearest
parent
4a881ce2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
test/test_neighbours.py
test/test_neighbours.py
+34
-0
No files found.
test/test_neighbours.py
0 → 100644
View file @
47e1c8f0
import
unittest
from
numpy
import
argmin
from
random
import
choice
,
sample
from
datetime
import
datetime
,
timedelta
from
GeoSpatialTools
import
find_nearest
class
TestFindNearest
(
unittest
.
TestCase
):
dates
=
[
datetime
(
2009
,
1
,
1
,
0
,
0
)
+
timedelta
(
seconds
=
i
*
3600
)
for
i
in
range
(
365
*
24
)
]
test_dates
=
sample
(
dates
,
150
)
test_dates
=
[
d
+
timedelta
(
seconds
=
60
*
choice
(
range
(
60
)))
for
d
in
test_dates
]
test_dates
.
append
(
dates
[
0
])
test_dates
.
append
(
dates
[
-
1
])
test_dates
.
append
(
datetime
(
2004
,
11
,
15
,
17
,
28
))
test_dates
.
append
(
datetime
(
2013
,
4
,
22
,
1
,
41
))
def
test_nearest
(
self
):
greedy
=
[
argmin
([
abs
(
x
-
y
)
for
x
in
self
.
dates
])
for
y
in
self
.
test_dates
]
ours
=
find_nearest
(
self
.
dates
,
self
.
test_dates
)
assert
ours
==
greedy
pass
if
__name__
==
"__main__"
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment