Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aa1949b

Browse filesBrowse files
committed
test create colors
1 parent 4d25daa commit aa1949b
Copy full SHA for aa1949b

File tree

Expand file treeCollapse file tree

1 file changed

+9
-97
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-97
lines changed

‎tests/test_buffer_manager.py renamed to ‎tests/test_colors_buffer_manager.py

Copy file name to clipboardExpand all lines: tests/test_colors_buffer_manager.py
+9-97Lines changed: 9 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pygfx
66

77
from fastplotlib.graphics._features import ColorFeature
8+
from .utils import generate_slice_indices
89

910

1011
def generate_color_inputs(name: str) -> list[str, np.ndarray, list, tuple]:
@@ -18,108 +19,18 @@ def generate_color_inputs(name: str) -> list[str, np.ndarray, list, tuple]:
1819
return [s, a, l, t]
1920

2021

21-
def generate_slice_indices(kind: int):
22-
n_elements = 10
23-
a = np.arange(n_elements)
24-
25-
match kind:
26-
case 0:
27-
# simplest, just int
28-
s = 2
29-
indices = [2]
30-
31-
case 1:
32-
# everything
33-
s = slice(None, None, None)
34-
indices = list(range(10))
35-
36-
case 2:
37-
# positive continuous range
38-
s = slice(1, 5, None)
39-
indices = [1, 2, 3, 4]
40-
41-
case 3:
42-
# positive stepped range
43-
s = slice(2, 8, 2)
44-
indices = [2, 4, 6]
45-
46-
case 4:
47-
# negative continuous range
48-
s = slice(-5, None, None)
49-
indices = [5, 6, 7, 8, 9]
50-
51-
case 5:
52-
# negative backwards
53-
s = slice(-5, None, -1)
54-
indices = [5, 4, 3, 2, 1, 0]
55-
56-
case 5:
57-
# negative backwards stepped
58-
s = slice(-5, None, -2)
59-
indices = [5, 3, 1]
60-
61-
case 6:
62-
# negative stepped forward
63-
s = slice(-5, None, 2)
64-
indices = [5, 7, 9]
65-
66-
case 7:
67-
# both negative
68-
s = slice(-8, -2, None)
69-
indices = [2, 3, 4, 5, 6, 7]
70-
71-
case 8:
72-
# both negative and stepped
73-
s = slice(-8, -2, 2)
74-
indices = [2, 4, 6]
75-
76-
case 9:
77-
# positive, negative, negative
78-
s = slice(8, -9, -2)
79-
indices = [8, 6, 4, 2]
80-
81-
case 10:
82-
# only stepped forward
83-
s = slice(None, None, 2)
84-
indices = [0, 2, 4, 6, 8]
85-
86-
case 11:
87-
# only stepped backward
88-
s = slice(None, None, -3)
89-
indices = [9, 6, 3, 0]
90-
91-
case 12:
92-
# list indices
93-
s = [2, 5, 9]
94-
indices = [2, 5, 9]
95-
96-
case 13:
97-
# bool indices
98-
s = a > 5
99-
indices = [6, 7, 8, 9]
100-
101-
case 14:
102-
# list indices with negatives
103-
s = [1, 4, -2]
104-
indices = [1, 4, 8]
105-
106-
case 15:
107-
# array indices
108-
s = np.array([1, 4, -7, 9])
109-
indices = [1, 4, 3, 9]
110-
111-
others = [i for i in a if i not in indices]
112-
113-
offset, size = (min(indices), np.ptp(indices) + 1)
114-
115-
return {"slice": s, "indices": indices, "others": others, "offset": offset, "size": size}
116-
117-
11822
def make_colors_buffer() -> ColorFeature:
11923
colors = ColorFeature(colors="w", n_colors=10)
12024
return colors
12125

12226

27+
@pytest.mark.parametrize("color_input", [*generate_color_inputs("r"), *generate_color_inputs("g"), *generate_color_inputs("b")])
28+
def test_create_buffer(color_input):
29+
colors = ColorFeature(colors=color_input, n_colors=10)
30+
truth = np.repeat([pygfx.Color(color_input)], 10, axis=0)
31+
npt.assert_almost_equal(colors[:], truth)
32+
33+
12334
def test_int():
12435
# setting single points
12536
colors = make_colors_buffer()
@@ -194,6 +105,7 @@ def test_tuple(slice_method):
194105

195106

196107
@pytest.mark.parametrize("color_input", generate_color_inputs("red"))
108+
# skip testing with int since that results in shape [1, 4] with np.repeat, int tested in independent unit test
197109
@pytest.mark.parametrize("slice_method", [generate_slice_indices(i) for i in range(1, 16)])
198110
def test_slice(color_input, slice_method: dict):
199111
# slicing only first dim

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.