Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# VS Code
.vscode
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# ulist
Ultra fast list - Python bindings to Rust Vector.


### Maturin
Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages.
* `maturin publish` builds the crate into python packages and publishes them to pypi.
* `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.
* `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.
* `maturin build --release` If we want to benchmark the package.
52 changes: 52 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
"""
@Author: tushushu
@Date: 2021-11-14 16:02:00
"""
import pytest
from ulist import FloatList, IntegerList
from typing import Union, List, Optional

LIST_TYPE = Union[FloatList, IntegerList]
NUM_TYPE = Union[float, int]


@pytest.mark.parametrize(
"test_class, nums",
[(FloatList, [1.0, 2.0, 3.0, 4.0, 5.0]), (IntegerList, [1, 2, 3, 4, 5])],
)
@pytest.mark.parametrize(
"test_method, expected_value, expected_type",
[
("max", 5.0, None),
("mean", 3.0, float),
("min", 1.0, None),
("size", 5, int),
("sum", 15.0, None),
],
)
def test(
test_class: LIST_TYPE,
nums: List[NUM_TYPE],
test_method: str,
expected_value: NUM_TYPE,
expected_type: Optional[NUM_TYPE],
) -> None:
arr = test_class(nums)
result = getattr(arr, test_method)()
msg = (
f"test_class - {test_class}"
+ f" test_method - {test_method}"
+ f" result - {result}"
+ f" expected - {expected_value}"
)
assert result == expected_value, msg

if expected_type is None:
if test_class is FloatList:
expected_type = float
elif test_class is IntegerList:
expected_type = int
assert type(result) == expected_type, msg

assert len(arr) == arr.size()
Loading