File: missing_tests.patch

package info (click to toggle)
sorted-nearest 0.0.41%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 328 kB
  • sloc: python: 214; sh: 20; makefile: 8
file content (90 lines) | stat: -rw-r--r-- 1,768 bytes parent folder | download
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
89
90
Description: patches are somehow gone
Author: Alexandre Detiste <tchet@debian.org>
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,17 @@
+import hypothesis.strategies as st
+from hypothesis import given
+from hypothesis.extra.pandas import columns, data_frames, range_indexes
+
+positions = st.integers(min_value=0, max_value=int(1e7))
+
+
+def mysort(pos1, pos2):
+    if pos1 > pos2:
+        return pos2, pos1
+    elif pos2 > pos1:
+        return pos1, pos2
+    else:
+        return pos1, pos2 + 1
+
+
+dfs = data_frames(columns=columns("Start End".split(), dtype=int), rows=st.tuples(positions, positions).map(mysort))
--- /dev/null
+++ b/tests/test_ties.py
@@ -0,0 +1,65 @@
+from io import StringIO
+
+import numpy as np
+import pandas as pd
+import pytest
+
+from sorted_nearest import get_all_ties, get_different_ties
+
+
+@pytest.fixture
+def data():
+    c = """ids dist
+1 1
+1 1
+1 2
+1 3
+0 5000
+0 5000
+0 5000
+2 100
+2 110
+2 110
+2 111
+3 111
+3 111
+3 111
+3 112
+3 112
+3 113
+4 112
+4 113
+4 113
+4 113
+4 113
+4 113
+4 113
+4 150"""
+
+    df = pd.read_table(StringIO(c), header=0, sep="\s+")
+
+    return df
+
+
+def test_get_all_ties(data):
+    df = data
+
+    print(df)
+
+    k = 2
+    result = get_all_ties(df.index.values, df.ids.values, df.dist.values, k)
+    print(df.reindex(result))
+    print(result)
+
+    expected = [0, 1, 4, 5, 6, 7, 8, 9, 11, 12, 13, 17, 18, 19, 20, 21, 22, 23]
+    assert list(result) == expected
+
+
+def test_get_different_ties(data):
+    df = data
+
+    k = 2
+    result = get_different_ties(df.index.values, df.ids.values, df.dist.values, k)
+    print(df.reindex(result))
+    print(result)
+    assert list(result) == [0, 1, 2, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23]