Skip to content

Commit

Permalink
Test nb::int_(double). (#793)
Browse files Browse the repository at this point in the history
* Test `nb::int_(double)`.

This commit adds tests that demonstrate that `nb::int_(x)` does not
create an integer, but instead it creates a float.

* Update golden reference.
  • Loading branch information
1uc authored Dec 17, 2024
1 parent 5eb205c commit d7d9d90
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/test_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ NB_MODULE(test_functions_ext, m) {
m.def("test_19", [](nb::int_ i) { return i + nb::int_(123); });
m.def("test_20", [](nb::str s) { return nb::int_(s) + nb::int_(123); });
m.def("test_21", [](nb::int_ i) { return (int) i; });
m.def("test_21_f", [](nb::float_ f) { return nb::int_(f); });
m.def("test_21_g", []() { return nb::int_(1.5); });
m.def("test_21_h", []() { return nb::int_(1e50); });

// Test capsule wrapper
m.def("test_22", []() -> void * { return (void*) 1; });
Expand Down
7 changes: 7 additions & 0 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ def test25_int():
assert t.test_19(5) == 128
assert t.test_20("5") == 128
assert t.test_21(5) == 5
assert t.test_21_f(5.1) == int(5.1)
assert t.test_21_f(1e50) == int(1e50)
assert type(t.test_21_f(0.5)) is int
assert t.test_21_g() == int(1.5)
assert type(t.test_21_g()) is int
assert t.test_21_h() == int(1e50)
assert type(t.test_21_h()) is int
assert t.test_19.__doc__ == "test_19(arg: int, /) -> object"


Expand Down
6 changes: 6 additions & 0 deletions tests/test_functions_ext.pyi.ref
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ def test_20(arg: str, /) -> object: ...

def test_21(arg: int, /) -> int: ...

def test_21_f(arg: float, /) -> int: ...

def test_21_g() -> int: ...

def test_21_h() -> int: ...

def test_22() -> types.CapsuleType: ...

def test_23() -> types.CapsuleType: ...
Expand Down

0 comments on commit d7d9d90

Please sign in to comment.