Skip to content

Commit

Permalink
add rust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Jun 14, 2023
1 parent cd92287 commit d291d72
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/re_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ macaw = { workspace = true, optional = true }
# External
glam.workspace = true
itertools.workspace = true
similar-asserts = "1.4.2"


[build-dependencies]
Expand Down
50 changes: 50 additions & 0 deletions crates/re_types/tests/points2d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use re_types::{archetypes::Points2D, components};

#[test]
fn roundtrip() {
// TODO(cmc): (de)serialization roundtrips

let arch = Points2D::new([(1.0, 2.0), (3.0, 4.0)])
.with_radii([42.0, 43.0])
.with_colors([0xAA0000CC, 0x00BB00DD])
.with_labels(["hello", "friend"])
.with_draw_order(300.0)
.with_instance_keys([1, 2, 3])
.with_class_ids([126, 127])
.with_keypoint_ids([2, 3])
.with_instance_keys([u64::MAX - 1, u64::MAX]);

let expected = Points2D {
points: vec![
components::Point2D::new(1.0, 2.0), //
components::Point2D::new(3.0, 4.0),
],
radii: Some(vec![
components::Radius(42.0), //
components::Radius(43.0),
]),
colors: Some(vec![
components::Color::from_unmultiplied_rgba(0xAA, 0x00, 0x00, 0xCC), //
components::Color::from_unmultiplied_rgba(0x00, 0xBB, 0x00, 0xDD),
]),
labels: Some(vec![
components::Label("hello".to_owned()), //
components::Label("friend".to_owned()), //
]),
draw_order: Some(components::DrawOrder(300.0)),
class_ids: Some(vec![
components::ClassId(126), //
components::ClassId(127), //
]),
keypoint_ids: Some(vec![
components::KeypointId(2), //
components::KeypointId(3), //
]),
instance_keys: Some(vec![
components::InstanceKey(u64::MAX - 1), //
components::InstanceKey(u64::MAX),
]),
};

similar_asserts::assert_eq!(expected, arch);
}

0 comments on commit d291d72

Please sign in to comment.