Skip to content

Commit 8c378d3

Browse files
committed
Add documentation
1 parent 714ad63 commit 8c378d3

File tree

8 files changed

+36
-126
lines changed

8 files changed

+36
-126
lines changed

crates/core_simd/tests/helpers/biteq.rs

Lines changed: 0 additions & 120 deletions
This file was deleted.

crates/core_simd/tests/helpers/mod.rs

Lines changed: 0 additions & 2 deletions
This file was deleted.

crates/core_simd/tests/mask_ops_impl/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
#[macro_use]
2-
#[path = "../helpers/mod.rs"]
3-
mod helpers;
4-
51
#[macro_use]
62
mod mask_macros;
73

crates/core_simd/tests/ops_macros.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/// Implements a test on a unary operation using proptest.
2+
///
3+
/// Compares the vector operation to the equivalent scalar operation.
14
#[macro_export]
25
macro_rules! impl_unary_op_test {
36
{ $vector:ty, $scalar:ty, $trait:ident :: $fn:ident, $scalar_fn:expr } => {
@@ -16,6 +19,9 @@ macro_rules! impl_unary_op_test {
1619
};
1720
}
1821

22+
/// Implements a test on a binary operation using proptest.
23+
///
24+
/// Compares the vector operation to the equivalent scalar operation.
1925
#[macro_export]
2026
macro_rules! impl_binary_op_test {
2127
{ $vector:ty, $scalar:ty, $trait:ident :: $fn:ident, $trait_assign:ident :: $fn_assign:ident, $scalar_fn:expr } => {
@@ -70,6 +76,12 @@ macro_rules! impl_binary_op_test {
7076
};
7177
}
7278

79+
/// Implements a test on a binary operation using proptest.
80+
///
81+
/// Like `impl_binary_op_test`, but allows providing a function for rejecting particular inputs
82+
/// (like the `proptest_assume` macro).
83+
///
84+
/// Compares the vector operation to the equivalent scalar operation.
7385
#[macro_export]
7486
macro_rules! impl_binary_checked_op_test {
7587
{ $vector:ty, $scalar:ty, $trait:ident :: $fn:ident, $trait_assign:ident :: $fn_assign:ident, $scalar_fn:expr, $check_fn:expr } => {
@@ -124,6 +136,7 @@ macro_rules! impl_binary_checked_op_test {
124136
};
125137
}
126138

139+
/// Implement tests for signed integers.
127140
#[macro_export]
128141
macro_rules! impl_signed_tests {
129142
{ $vector:ident, $scalar:tt } => {
@@ -191,6 +204,8 @@ macro_rules! impl_signed_tests {
191204
impl_binary_op_test!(Vector<LANES>, Scalar, Add::add, AddAssign::add_assign, Scalar::wrapping_add);
192205
impl_binary_op_test!(Vector<LANES>, Scalar, Sub::sub, SubAssign::sub_assign, Scalar::wrapping_sub);
193206
impl_binary_op_test!(Vector<LANES>, Scalar, Mul::mul, MulAssign::mul_assign, Scalar::wrapping_mul);
207+
208+
// Exclude Div and Rem panicking cases
194209
impl_binary_checked_op_test!(Vector<LANES>, Scalar, Div::div, DivAssign::div_assign, Scalar::wrapping_div, |x, y| y != 0 && !(x == Scalar::MIN && y == -1));
195210
impl_binary_checked_op_test!(Vector<LANES>, Scalar, Rem::rem, RemAssign::rem_assign, Scalar::wrapping_rem, |x, y| y != 0 && !(x == Scalar::MIN && y == -1));
196211

@@ -202,6 +217,7 @@ macro_rules! impl_signed_tests {
202217
}
203218
}
204219

220+
/// Implement tests for unsigned integers.
205221
#[macro_export]
206222
macro_rules! impl_unsigned_tests {
207223
{ $vector:ident, $scalar:tt } => {
@@ -220,6 +236,8 @@ macro_rules! impl_unsigned_tests {
220236
impl_binary_op_test!(Vector<LANES>, Scalar, Add::add, AddAssign::add_assign, Scalar::wrapping_add);
221237
impl_binary_op_test!(Vector<LANES>, Scalar, Sub::sub, SubAssign::sub_assign, Scalar::wrapping_sub);
222238
impl_binary_op_test!(Vector<LANES>, Scalar, Mul::mul, MulAssign::mul_assign, Scalar::wrapping_mul);
239+
240+
// Exclude Div and Rem panicking cases
223241
impl_binary_checked_op_test!(Vector<LANES>, Scalar, Div::div, DivAssign::div_assign, Scalar::wrapping_div, |_, y| y != 0);
224242
impl_binary_checked_op_test!(Vector<LANES>, Scalar, Rem::rem, RemAssign::rem_assign, Scalar::wrapping_rem, |_, y| y != 0);
225243

@@ -231,6 +249,7 @@ macro_rules! impl_unsigned_tests {
231249
}
232250
}
233251

252+
/// Implement tests for floating point numbers.
234253
#[macro_export]
235254
macro_rules! impl_float_tests {
236255
{ $vector:ident, $scalar:tt, $int_scalar:tt } => {

crates/test_helpers/src/array.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Generic-length array strategy.
2+
13
// Adapted from proptest's array code
24
// Copyright 2017 Jason Lingle
35

crates/test_helpers/src/biteq.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Compare numeric types by exact bit value.
2+
13
pub trait BitEq {
24
fn biteq(&self, other: &Self) -> bool;
35
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result;

crates/test_helpers/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ pub mod wasm;
66
#[macro_use]
77
pub mod biteq;
88

9+
/// Specifies the default strategy for testing a type.
10+
///
11+
/// This strategy should be what "makes sense" to test.
912
pub trait DefaultStrategy {
1013
type Strategy: proptest::strategy::Strategy<Value = Self>;
1114
fn default_strategy() -> Self::Strategy;
@@ -74,13 +77,15 @@ impl<T: core::fmt::Debug + DefaultStrategy, const LANES: usize> DefaultStrategy
7477
}
7578
}
7679

80+
/// Test a function that takes a single value.
7781
pub fn test_1<A: core::fmt::Debug + DefaultStrategy>(
7882
f: &dyn Fn(A) -> proptest::test_runner::TestCaseResult,
7983
) {
8084
let mut runner = proptest::test_runner::TestRunner::default();
8185
runner.run(&A::default_strategy(), f).unwrap();
8286
}
8387

88+
/// Test a function that takes two values.
8489
pub fn test_2<A: core::fmt::Debug + DefaultStrategy, B: core::fmt::Debug + DefaultStrategy>(
8590
f: &dyn Fn(A, B) -> proptest::test_runner::TestCaseResult,
8691
) {
@@ -92,6 +97,7 @@ pub fn test_2<A: core::fmt::Debug + DefaultStrategy, B: core::fmt::Debug + Defau
9297
.unwrap();
9398
}
9499

100+
/// Test a unary vector function against a unary scalar function, applied elementwise.
95101
#[inline(never)]
96102
pub fn test_unary_elementwise<Scalar, ScalarResult, Vector, VectorResult, const LANES: usize>(
97103
fv: &dyn Fn(Vector) -> VectorResult,
@@ -118,6 +124,7 @@ pub fn test_unary_elementwise<Scalar, ScalarResult, Vector, VectorResult, const
118124
});
119125
}
120126

127+
/// Test a binary vector function against a binary scalar function, applied elementwise.
121128
#[inline(never)]
122129
pub fn test_binary_elementwise<
123130
Scalar1,
@@ -154,6 +161,7 @@ pub fn test_binary_elementwise<
154161
});
155162
}
156163

164+
/// Test a binary vector-scalar function against a binary scalar function, applied elementwise.
157165
#[inline(never)]
158166
pub fn test_binary_scalar_rhs_elementwise<
159167
Scalar1,
@@ -188,6 +196,7 @@ pub fn test_binary_scalar_rhs_elementwise<
188196
});
189197
}
190198

199+
/// Test a binary vector-scalar function against a binary scalar function, applied elementwise.
191200
#[inline(never)]
192201
pub fn test_binary_scalar_lhs_elementwise<
193202
Scalar1,
@@ -222,6 +231,7 @@ pub fn test_binary_scalar_lhs_elementwise<
222231
});
223232
}
224233

234+
/// Expand a const-generic test into separate tests for each possible lane count.
225235
#[macro_export]
226236
macro_rules! test_lanes {
227237
{
@@ -282,6 +292,7 @@ macro_rules! test_lanes {
282292
}
283293
}
284294

295+
/// Expand a const-generic `#[should_panic]` test into separate tests for each possible lane count.
285296
#[macro_export]
286297
macro_rules! test_lanes_panic {
287298
{

crates/test_helpers/src/wasm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Strategies for `u128` and `i128`, since proptest doesn't provide them for the wasm target.
2+
13
macro_rules! impl_num {
24
{ $name:ident } => {
35
pub(crate) mod $name {

0 commit comments

Comments
 (0)