Skip to content

Commit

Permalink
fix testing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacholt100 committed Jan 1, 2025
1 parent 60a4eda commit 82e1fdb
Show file tree
Hide file tree
Showing 44 changed files with 1,068 additions and 1,118 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ exclude = ["src/float/*", "src/tests", "TODO.txt", "lit-parser/*"] # TODO: make
[features]
default = []
nightly = []
float = []
serde = ["dep:serde", "serde-big-array"]
numtraits = ["num-integer", "num-traits"]

Expand Down Expand Up @@ -49,4 +48,4 @@ opt-level = 3 # maximum optimisation level for faster runtime, but slower compil
all-features = true

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(test_int_bits, values("8", "16", "32", "64", "128"))'] }
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(test_int_bits, values("16", "32", "64", "128"))'] }
3 changes: 3 additions & 0 deletions changes/v0.12.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- fix midpoint method
- fix posoverflow being returned instead of invaliddigit for parsing ints
- change debug implementation of parseinterror
5 changes: 3 additions & 2 deletions scripts/run_all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ test_integer_info () {
export QUICKCHECK_TESTS=10000

run_test () {
echo $QUICKCHECK_TESTS
echo "using ${QUICKCHECK_TESTS} quickcheck tests per test"

test_integer_info "$1"
RUSTFLAGS="--cfg test_int_bits=\"$1\"" cargo test int --lib --quiet $2
if [ $? -ne 0 ]
Expand All @@ -20,7 +21,7 @@ run_test () {
for flags in "" "--all-features"
do
echo "\n${CYAN_COLOR}info${RESET_FORMAT}: running tests with flags '$flags'..."
for bits in 8 16 32 64 128
for bits in 16 32 64 128
do
run_test $bits $flags
done
Expand Down
15 changes: 7 additions & 8 deletions src/bint/bigint_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ macro_rules! bigint_helpers {
impl<const N: usize> $BInt<N> {
crate::int::bigint_helpers::impls!(I);
}

#[cfg(test)]
paste::paste! {
mod [<$Digit _digit_tests>] {
use crate::test::types::big_types::$Digit::*;
crate::int::bigint_helpers::tests!(itest);
}
}
};
}

#[cfg(test)]
crate::test::all_digit_tests! {
use crate::test::types::itest;

crate::int::bigint_helpers::tests!(itest);
}

use crate::doc;

crate::macro_impl!(bigint_helpers);
15 changes: 7 additions & 8 deletions src/bint/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,16 @@ macro_rules! cast {
impl<const N: usize> CastFrom<f64> for $BInt<N> {
crate::bint::cast::bint_cast_from_float!(f64, $BUint<N>);
}

#[cfg(test)]
paste::paste! {
mod [<$Digit _digit_tests>] {
use crate::test::types::big_types::$Digit::*;
crate::int::cast::tests!(itest);
}
}
};
}

#[cfg(test)]
crate::test::all_digit_tests! {
use crate::test::types::itest;

crate::int::cast::tests!(itest);
}

crate::macro_impl!(cast);

macro_rules! bint_as_different_digit_bigint {
Expand Down
181 changes: 90 additions & 91 deletions src/bint/checked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,99 +187,98 @@ macro_rules! checked {
checked_ilog!(checked_ilog2);
checked_ilog!(checked_ilog10);
}
};
}

#[cfg(test)]
paste::paste! {
mod [<$Digit _digit_tests>] {
use crate::test::types::big_types::$Digit::*;
use crate::test::{test_bignum, types::*};

test_bignum! {
function: <itest>::checked_add(a: itest, b: itest),
cases: [
(itest::MAX, -1i8)
]
}
test_bignum! {
function: <itest>::checked_add_unsigned(a: itest, b: utest)
}
test_bignum! {
function: <itest>::checked_sub(a: itest, b: itest),
cases: [
(itest::MIN, -1i8)
]
}
test_bignum! {
function: <itest>::checked_sub_unsigned(a: itest, b: utest)
}
test_bignum! {
function: <itest>::checked_mul(a: itest, b: itest),
cases: [
(itest::MIN, -1i8)
]
}
test_bignum! {
function: <itest>::checked_div(a: itest, b: itest),
cases: [
(0, 0),
(23098403i32 as itest, 0i8),
(itest::MIN, -1i8),
(8388600i32 as itest, 68201i32 as itest) // tests the unlikely condition in the division algorithm at step D5
]
}
test_bignum! {
function: <itest>::checked_div_euclid(a: itest, b: itest),
cases: [
(itest::MIN, -1i8),
(0, 0)
]
}
test_bignum! {
function: <itest>::checked_rem(a: itest, b: itest),
cases: [
(itest::MIN, -1i8),
(0, 0)
]
}
test_bignum! {
function: <itest>::checked_rem_euclid(a: itest, b: itest),
skip: b <= u8::MAX as itest,
cases: [
(itest::MIN, -1i8),
(0, 0)
]
}
test_bignum! {
function: <itest>::checked_neg(a: itest),
cases: [
(itest::MIN)
]
}
test_bignum! {
function: <itest>::checked_shl(a: itest, b: u16)
}
test_bignum! {
function: <itest>::checked_shr(a: itest, b: u16)
}
test_bignum! {
function: <itest>::checked_pow(a: itest, b: u16),
cases: [
(2, itest::BITS as u16 - 1),
(-2, itest::BITS as u16 - 1)
]
}
test_bignum! {
function: <itest>::checked_ilog2(a: itest)
}
test_bignum! {
function: <itest>::checked_ilog10(a: itest)
}
test_bignum! {
function: <itest>::checked_ilog(a: itest, b: itest)
}
}
}
};
#[cfg(test)]
crate::test::all_digit_tests! {
use crate::test::test_bignum;
use crate::test::types::{itest, utest};

test_bignum! {
function: <itest>::checked_add(a: itest, b: itest),
cases: [
(itest::MAX, -1i8)
]
}
test_bignum! {
function: <itest>::checked_add_unsigned(a: itest, b: utest)
}
test_bignum! {
function: <itest>::checked_sub(a: itest, b: itest),
cases: [
(itest::MIN, -1i8)
]
}
test_bignum! {
function: <itest>::checked_sub_unsigned(a: itest, b: utest)
}
test_bignum! {
function: <itest>::checked_mul(a: itest, b: itest),
cases: [
(itest::MIN, -1i8)
]
}
test_bignum! {
function: <itest>::checked_div(a: itest, b: itest),
cases: [
(0i8, 0i8),
(23098403i32 as itest, 0i8),
(itest::MIN, -1i8),
(8388600i32 as itest, 68201i32 as itest) // tests the unlikely condition in the division algorithm at step D5
]
}
test_bignum! {
function: <itest>::checked_div_euclid(a: itest, b: itest),
cases: [
(itest::MIN, -1i8),
(0i8, 0i8)
]
}
test_bignum! {
function: <itest>::checked_rem(a: itest, b: itest),
cases: [
(itest::MIN, -1i8),
(0i8, 0i8)
]
}
test_bignum! {
function: <itest>::checked_rem_euclid(a: itest, b: itest),
skip: b <= u8::MAX as itest,
cases: [
(itest::MIN, -1i8),
(0i8, 0i8)
]
}
test_bignum! {
function: <itest>::checked_neg(a: itest),
cases: [
(itest::MIN)
]
}
test_bignum! {
function: <itest>::checked_shl(a: itest, b: u16)
}
test_bignum! {
function: <itest>::checked_shr(a: itest, b: u16)
}
test_bignum! {
function: <itest>::checked_pow(a: itest, b: u16),
cases: [
(2i8, itest::BITS as u16 - 1),
(-2i8, itest::BITS as u16 - 1)
]
}
test_bignum! {
function: <itest>::checked_ilog2(a: itest)
}
test_bignum! {
function: <itest>::checked_ilog10(a: itest)
}
test_bignum! {
function: <itest>::checked_ilog(a: itest, b: itest)
}
}

crate::macro_impl!(checked);
15 changes: 7 additions & 8 deletions src/bint/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ macro_rules! cmp {
Self::clamp(self, min, max)
}
}

#[cfg(test)]
paste::paste! {
mod [<$Digit _digit_tests>] {
use crate::test::types::big_types::$Digit::*;
crate::int::cmp::tests!(itest);
}
}
};
}

#[cfg(test)]
crate::test::all_digit_tests! {
use crate::test::types::*;

crate::int::cmp::tests!(itest);
}

crate::macro_impl!(cmp);
52 changes: 25 additions & 27 deletions src/bint/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,36 +161,34 @@ macro_rules! convert {
// }
// }
// }
};
}

#[cfg(test)]
paste::paste! {
mod [<$Digit _digit_tests>] {
use crate::test::types::big_types::$Digit::*;
use crate::test::{self, types::itest};
use crate::test::cast_types::*;
use crate::BTryFrom;

test::test_btryfrom!(itest; UTESTD8, UTESTD16, UTESTD32, UTESTD64, TestUint1, TestUint2, TestUint3, TestUint4, TestUint5, TestUint6, TestUint7, TestUint8, TestUint9, TestUint10, ITESTD8, ITESTD16, ITESTD32, ITESTD64, TestInt1, TestInt2, TestInt3, TestInt4, TestInt5, TestInt6, TestInt7, TestInt8, TestInt9, TestInt10);

#[cfg(test_int_bits = "128")]
test::test_from! {
function: <itest as TryFrom>::try_from,
from_types: (i8, i16, i32, i64, i128, u8, u16, u32, u64, bool, usize, isize)
}
#[cfg(test)]
crate::test::all_digit_tests! {
use crate::test;
use crate::test::types::itest;
use crate::test::cast_types::*;
use crate::BTryFrom;

test::test_btryfrom!(itest; TestUint1, TestUint2, TestUint3, TestUint4, TestUint5, TestUint6, TestUint7, TestUint8, TestUint9, TestUint10, TestInt1, TestInt2, TestInt3, TestInt4, TestInt5, TestInt6, TestInt7, TestInt8, TestInt9, TestInt10);

#[cfg(test_int_bits = "128")]
test::test_from! {
function: <itest as TryFrom>::try_from,
from_types: (i8, i16, i32, i64, i128, u8, u16, u32, u64, bool, usize, isize)
}

#[cfg(test_int_bits = "64")]
test::test_from! {
function: <itest as TryFrom>::try_from,
from_types: (i8, i16, i32, i64, u8, u16, u32, bool, isize)
}
#[cfg(test_int_bits = "64")]
test::test_from! {
function: <itest as TryFrom>::try_from,
from_types: (i8, i16, i32, i64, u8, u16, u32, bool, isize)
}

test::test_into! {
function: <itest as TryInto>::try_into,
into_types: (u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize)
}
}
}
};
test::test_into! {
function: <itest as TryInto>::try_into,
into_types: (u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize)
}
}

crate::macro_impl!(convert);
17 changes: 7 additions & 10 deletions src/bint/endian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,15 @@ macro_rules! endian {
Self::from_bits($BUint::from_ne_bytes(bytes))
}
}
};
}

#[cfg(test)]
paste::paste! {
mod [<$Digit _digit_tests>] {
use crate::test::types::big_types::$Digit::*;
use crate::test::test_bignum;
use crate::test::types::itest;
#[cfg(test)]
crate::test::all_digit_tests! {
use crate::test::test_bignum;
use crate::test::types::itest;

crate::int::endian::tests!($Digit; itest);
}
}
};
crate::int::endian::tests!(itest);
}

crate::macro_impl!(endian);
Loading

0 comments on commit 82e1fdb

Please sign in to comment.