-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New clif/testing/python:vector_unique_ptr_member_test
BEGIN_PUBLIC New clif/testing/python:vector_unique_ptr_member_test END_PUBLIC Follow-on to: * pybind/pybind11#4630 — Introduce `pybind11::detail::is_move_constructible` * cl/526123390 — Generate is_move_constructible<T>: std::false_type to tell pybind11 that T is not movable. Originally reduced from: ``` blaze build //waymo/planner/evaluation/metrics/time_to_encroachment/encroachment_utils/python:potential_collision_severity_calculator_clif ``` Manually tested with `_GEN_PYBIND11 = True` in devtools/clif/python/clif_build_rule.bzl: * http://sponge2/200da41a-fdd0-4e0e-a3e7-8fd00294b84d PiperOrigin-RevId: 526133273
- Loading branch information
1 parent
e6ff775
commit b66e837
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from "clif/testing/vector_unique_ptr_member.h": | ||
namespace `clif_testing_vector_unique_ptr_member`: | ||
class VectorOwner: | ||
@classmethod | ||
def Create(cls, num_elems: int) -> VectorOwner | ||
def data_size(self) -> int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from absl.testing import absltest | ||
from absl.testing import parameterized | ||
|
||
from clif.testing.python import vector_unique_ptr_member | ||
|
||
|
||
class VectorUniquePtrMemberTest(parameterized.TestCase): | ||
|
||
@parameterized.parameters(range(3)) | ||
def testCreate(self, num_elems): | ||
vo = vector_unique_ptr_member.VectorOwner.Create(num_elems) | ||
assert vo.data_size() == num_elems | ||
|
||
|
||
if __name__ == '__main__': | ||
absltest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#ifndef CLIF_TESTING_VECTOR_UNIQUE_PTR_MEMBER_H_ | ||
#define CLIF_TESTING_VECTOR_UNIQUE_PTR_MEMBER_H_ | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
namespace clif_testing_vector_unique_ptr_member { | ||
|
||
struct DataType {}; | ||
|
||
// Reduced from a use case in the wild. | ||
struct VectorOwner { | ||
static std::unique_ptr<VectorOwner> Create(std::size_t num_elems) { | ||
return std::unique_ptr<VectorOwner>( | ||
new VectorOwner(std::vector<std::unique_ptr<DataType>>(num_elems))); | ||
} | ||
|
||
std::size_t data_size() const { return data_.size(); } | ||
|
||
private: | ||
explicit VectorOwner(std::vector<std::unique_ptr<DataType>> data) | ||
: data_(std::move(data)) {} | ||
|
||
const std::vector<std::unique_ptr<DataType>> data_; | ||
}; | ||
|
||
} // namespace clif_testing_vector_unique_ptr_member | ||
|
||
#endif // CLIF_TESTING_VECTOR_UNIQUE_PTR_MEMBER_H_ |