From 764b15a5567e37472dcefc47b5061b8cddcfc268 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Tue, 18 Jun 2024 15:53:56 -0400 Subject: [PATCH] refactor: `vertex_index_common`: elide `tests` alloc. w/ `Itertools::cartesian_product` --- Cargo.lock | 1 + Cargo.toml | 1 + tests/Cargo.toml | 1 + tests/tests/vertex_indices/mod.rs | 40 +++++++++++++------------------ 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c2fecc76d..1fd477852 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4384,6 +4384,7 @@ dependencies = [ "env_logger", "futures-lite", "image", + "itertools", "js-sys", "libtest-mimic", "log", diff --git a/Cargo.toml b/Cargo.toml index 0bb431ad2..ce5ebcce1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,6 +91,7 @@ getrandom = "0.2" glam = "0.27" heck = "0.5.0" image = { version = "0.24", default-features = false, features = ["png"] } +itertools = { version = "0.10.5" } ktx2 = "0.3" libc = "0.2" # libloading 0.8 switches from `winapi` to `windows-sys`; permit either diff --git a/tests/Cargo.toml b/tests/Cargo.toml index f37139346..d6b5ae672 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -27,6 +27,7 @@ bytemuck.workspace = true cfg-if.workspace = true ctor.workspace = true futures-lite.workspace = true +itertools.workspace = true libtest-mimic.workspace = true log.workspace = true parking_lot.workspace = true diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index a9446a340..17a9b989d 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -5,6 +5,7 @@ use std::{num::NonZeroU64, ops::Range}; +use itertools::Itertools; use strum::IntoEnumIterator; use wgpu::util::{BufferInitDescriptor, DeviceExt, RenderEncoder}; @@ -337,30 +338,23 @@ async fn vertex_index_common(ctx: TestingContext) { ) .create_view(&wgpu::TextureViewDescriptor::default()); - let mut tests = Vec::with_capacity( - TestCase::iter().count() - * IdSource::iter().count() - * DrawCallKind::iter().count() - * EncoderKind::iter().count() - * [false, true].iter().count(), - ); - for case in TestCase::iter() { - for id_source in IdSource::iter() { - for draw_call_kind in DrawCallKind::iter() { - for encoder_kind in EncoderKind::iter() { - for vertex_pulling_transform in [false, true] { - tests.push(Test { - case, - id_source, - draw_call_kind, - encoder_kind, - vertex_pulling_transform, - }) - } + let tests = TestCase::iter() + .cartesian_product(IdSource::iter()) + .cartesian_product(DrawCallKind::iter()) + .cartesian_product(EncoderKind::iter()) + .cartesian_product([false, true]) + .map( + |((((case, id_source), draw_call_kind), encoder_kind), vertex_pulling_transform)| { + Test { + case, + id_source, + draw_call_kind, + encoder_kind, + vertex_pulling_transform, } - } - } - } + }, + ) + .collect::>(); let features = ctx.adapter.features();