Skip to content

Commit ef3ed0a

Browse files
authored
Merge pull request #1 from tushushu/wip-list-with-minimal-methods
Wip list with minimal methods
2 parents 026890c + 4b787e0 commit ef3ed0a

File tree

6 files changed

+576
-0
lines changed

6 files changed

+576
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# VS Code
132+
.vscode

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
# ulist
22
Ultra fast list - Python bindings to Rust Vector.
3+
4+
5+
### Maturin
6+
Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages.
7+
* `maturin publish` builds the crate into python packages and publishes them to pypi.
8+
* `maturin build` builds the wheels and stores them in a folder (target/wheels by default), but doesn't upload them. It's possible to upload those with twine.
9+
* `maturin develop` builds the crate and installs it as a python module directly in the current virtualenv. Note that while maturin develop is faster, it doesn't support all the feature that running pip install after `maturin build` supports.
10+
* `maturin build --release` If we want to benchmark the package.

test.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
@Author: tushushu
4+
@Date: 2021-11-14 16:02:00
5+
"""
6+
import pytest
7+
from ulist import FloatList, IntegerList
8+
from typing import Union, List, Optional
9+
10+
LIST_TYPE = Union[FloatList, IntegerList]
11+
NUM_TYPE = Union[float, int]
12+
13+
14+
@pytest.mark.parametrize(
15+
"test_class, nums",
16+
[(FloatList, [1.0, 2.0, 3.0, 4.0, 5.0]), (IntegerList, [1, 2, 3, 4, 5])],
17+
)
18+
@pytest.mark.parametrize(
19+
"test_method, expected_value, expected_type",
20+
[
21+
("max", 5.0, None),
22+
("mean", 3.0, float),
23+
("min", 1.0, None),
24+
("size", 5, int),
25+
("sum", 15.0, None),
26+
],
27+
)
28+
def test(
29+
test_class: LIST_TYPE,
30+
nums: List[NUM_TYPE],
31+
test_method: str,
32+
expected_value: NUM_TYPE,
33+
expected_type: Optional[NUM_TYPE],
34+
) -> None:
35+
arr = test_class(nums)
36+
result = getattr(arr, test_method)()
37+
msg = (
38+
f"test_class - {test_class}"
39+
+ f" test_method - {test_method}"
40+
+ f" result - {result}"
41+
+ f" expected - {expected_value}"
42+
)
43+
assert result == expected_value, msg
44+
45+
if expected_type is None:
46+
if test_class is FloatList:
47+
expected_type = float
48+
elif test_class is IntegerList:
49+
expected_type = int
50+
assert type(result) == expected_type, msg
51+
52+
assert len(arr) == arr.size()

0 commit comments

Comments
 (0)