Skip to content

Commit

Permalink
Merge branch '⬆️-nightly-2023-01-10' into 🦆
Browse files Browse the repository at this point in the history
  • Loading branch information
yvt committed Jan 13, 2023
2 parents 57184ad + eb26ea8 commit 8ace157
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2022-11-10"
channel = "nightly-2023-01-10"
components = ["rustfmt", "rust-src", "clippy"]
34 changes: 18 additions & 16 deletions src/r3_portkit/src/num/wrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ mod tests {

use super::*;
use quickcheck_macros::quickcheck;
use std::{prelude::v1::*, vec};
use std::prelude::v1::*;

/// The naïve implementation of `WrappingTrait`.
#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -273,7 +273,7 @@ mod tests {

const MAX: u128 = $max;

fn do_test_add_assign64(values: impl IntoIterator<Item = u64>) {
fn do_test_add_assign64(values: &mut dyn Iterator<Item = u64>) {
let mut counter_got: Wrapping<{MAX as u64}> = Init::INIT;
let mut counter_expected: NaiveWrapping<{MAX as u64}> = Init::INIT;
log::trace!("do_test_add_assign64 (MAX = {})", MAX);
Expand All @@ -293,28 +293,29 @@ mod tests {

#[test]
fn add_assign64_zero() {
do_test_add_assign64(vec![0, 0, 0,0, 0]);
do_test_add_assign64(&mut [0, 0, 0,0, 0].into_iter());
}

#[test]
fn add_assign64_mixed() {
let max = MAX as u64;
do_test_add_assign64(vec![0, 1u64.min(max), max, max / 2, max / 10, 0, 4u64.min(max)]);
do_test_add_assign64(
&mut [0, 1u64.min(max), max, max / 2, max / 10, 0, 4u64.min(max)].into_iter());
}

#[test]
fn add_assign64_max() {
do_test_add_assign64(vec![MAX as u64; 5]);
do_test_add_assign64(&mut [MAX as u64; 5].into_iter());
}

#[test]
fn add_assign64_half() {
do_test_add_assign64(vec![MAX as u64 / 2; 5]);
do_test_add_assign64(&mut [MAX as u64 / 2; 5].into_iter());
}

#[quickcheck]
fn add_assign64_quickcheck(cmds: Vec<u32>) {
do_test_add_assign64(cmds.iter().map(|&cmd| {
do_test_add_assign64(&mut cmds.iter().map(|&cmd| {
let max = MAX as u64;
match cmd % 4 {
0 => max / 2,
Expand All @@ -326,7 +327,7 @@ mod tests {
}));
}

fn do_test_add_assign128_multi32(values: impl IntoIterator<Item = u128>) {
fn do_test_add_assign128_multi32(values: &mut dyn Iterator<Item = u128>) {
let mut counter_got: Wrapping<{MAX as u64}> = Init::INIT;
let mut counter_expected: NaiveWrapping<{MAX as u64}> = Init::INIT;
log::trace!("do_test_add_assign128_multi32 (MAX = {})", MAX);
Expand All @@ -346,44 +347,45 @@ mod tests {

#[test]
fn add_assign128_multi32_zero() {
do_test_add_assign128_multi32(vec![0; 5]);
do_test_add_assign128_multi32(&mut [0; 5].into_iter());
}

#[test]
fn add_assign128_multi32_mixed() {
do_test_add_assign128_multi32(vec![0, 1u128.min(MAX), MAX, MAX / 2, MAX / 10, 0, 4u128.min(MAX)]);
do_test_add_assign128_multi32(
&mut [0, 1u128.min(MAX), MAX, MAX / 2, MAX / 10, 0, 4u128.min(MAX)].into_iter());
}

#[test]
fn add_assign128_multi32_max() {
do_test_add_assign128_multi32(vec![MAX; 5]);
do_test_add_assign128_multi32(&mut [MAX; 5].into_iter());
}

#[test]
fn add_assign128_multi32_max_p1() {
do_test_add_assign128_multi32(vec![MAX + 1; 5]);
do_test_add_assign128_multi32(&mut [MAX + 1; 5].into_iter());
}

#[test]
fn add_assign128_multi32_half() {
do_test_add_assign128_multi32(vec![MAX / 2; 5]);
do_test_add_assign128_multi32(&mut [MAX / 2; 5].into_iter());
}

#[test]
fn add_assign128_multi32_extreme() {
do_test_add_assign128_multi32(vec![MAX, (MAX + 1) * 0xffff_ffff]);
do_test_add_assign128_multi32(&mut [MAX, (MAX + 1) * 0xffff_ffff].into_iter());
}

#[test]
#[should_panic]
fn add_assign128_multi32_result_overflow() {
// `NaiveWrapping` is guaranteed to panic on overflow
do_test_add_assign128_multi32(vec![MAX, (MAX + 1) * 0xffff_ffff + 1]);
do_test_add_assign128_multi32(&mut [MAX, (MAX + 1) * 0xffff_ffff + 1].into_iter());
}

#[quickcheck]
fn add_assign128_multi32_quickcheck(cmds: Vec<u32>) {
do_test_add_assign128_multi32(cmds.iter().map(|&cmd| {
do_test_add_assign128_multi32(&mut cmds.iter().map(|&cmd| {
match cmd % 8 {
0 => MAX / 2,
1 => MAX / 2 + 1,
Expand Down

0 comments on commit 8ace157

Please sign in to comment.