Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-features

fmt:
name: Rustfmt check
Expand Down Expand Up @@ -93,7 +94,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features "colored, float-cmp"
args: --no-default-features --features "colored, float-cmp, num-bigint"

msrv:
name: Build with MSRV
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Test lib no-std" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="buildProfileId" value="test" />
<option name="command" value="test --lib --no-default-features --features &quot;colored, float-cmp&quot;" />
<option name="command" value="test --lib --no-default-features --features &quot;colored, float-cmp, num-bigint&quot;" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="false" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Test no-std" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="buildProfileId" value="test" />
<option name="command" value="test --no-default-features --features &quot;colored, float-cmp&quot;" />
<option name="command" value="test --no-default-features --features &quot;colored, float-cmp, num-bigint&quot;" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="false" />
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rustdoc-args = ["--cfg", "docsrs"]
default = ["std", "colored", "float-cmp", "panic", "regex"]
colored = ["dep:sdiff"]
float-cmp = ["dep:float-cmp"]
num-bigint = ["dep:num-bigint", "dep:lazy_static"]
panic = ["std"]
regex = ["dep:regex"]
std = []
Expand All @@ -31,6 +32,8 @@ hashbrown = "0.15"

# optional
float-cmp = { version = "0.10", optional = true }
lazy_static = { version = "1", optional = true }
num-bigint = { version = "0.4", default-features = false, optional = true }
regex = { version = "1", optional = true }
sdiff = { version = "0.1", optional = true }

Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,11 @@ being the type of the expected value.

### Integer and Float

for integer numbers of type `i8`, `i16`, `i32`, `i64`, `i128` and `isize` as well as <br/>
floating point numbers of type `f32` and `f64`:
for numbers of types

* integer primitives: `i8`, `i16`, `i32`, `i64`, `i128` and `isize`
* floating point numbers: `f32` and `f64`
* `num_bigint::BigInt` (requires crate feature `num-bigint`)

| assertion | description |
|-----------------|------------------------------------------------------|
Expand All @@ -173,9 +176,12 @@ floating point numbers of type `f32` and `f64`:
| is_positive | verify that the subject is a positive number |
| is_not_positive | verify that the subject is a finite number |

for integer numbers of type `i8`, `i16`, `i32`, `i64`, `i128`, `isize`, `u8`, `u16`, `u32`, `u64`,
`u128` and `usize` as well as <br/>
floating point numbers of type `f32` and `f64`:
for numbers of types

* integer primitives: `i8`, `i16`, `i32`, `i64`, `i128`, `isize`, `u8`, `u16`, `u32`, `u64`, `u128`
and `usize`
* floating point numbers: `f32` and `f64`
* `num_bigint::BigInt` and `num_bigint::BigUint` (requires crate feature `num-bigint`)

| assertion | description |
|-----------|--------------------------------------------------------------|
Expand Down
4 changes: 4 additions & 0 deletions examples/fixture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ mod dummy_extern_uses {
#[cfg(feature = "float-cmp")]
use float_cmp as _;
use hashbrown as _;
#[cfg(feature = "num-bigint")]
use lazy_static as _;
#[cfg(feature = "num-bigint")]
use num_bigint as _;
use proptest as _;
#[cfg(feature = "regex")]
use regex as _;
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ lint-all-features:

# linting code using Clippy for no-std environment
lint-no-std:
cargo clippy --all-targets --no-default-features --features "colored, float-cmp"
cargo clippy --all-targets --no-default-features --features "colored, float-cmp, num-bigint"

# linting code using Clippy with no features enabled
lint-no-features:
Expand All @@ -55,7 +55,7 @@ test-all-features:

# run tests for no-std environment
test-no-std:
cargo test --no-default-features --features "colored, float-cmp"
cargo test --no-default-features --features "colored, float-cmp, num-bigint"

# run tests with no features enabled
test-no-features:
Expand Down
42 changes: 32 additions & 10 deletions src/float/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,44 @@ impl SignumProperty for f64 {
}
}

impl AdditiveIdentityProperty for f32 {
const ADDITIVE_IDENTITY: Self = 0.;
}
macro_rules! impl_additive_identity_property {
($type:ty) => {
impl AdditiveIdentityProperty for $type {
fn additive_identity() -> Self {
0.
}
}

impl AdditiveIdentityProperty for f64 {
const ADDITIVE_IDENTITY: Self = 0.;
impl AdditiveIdentityProperty for &$type {
fn additive_identity() -> Self {
&0.
}
}
};
}

impl MultiplicativeIdentityProperty for f32 {
const MULTIPLICATIVE_IDENTITY: Self = 1.;
}
impl_additive_identity_property!(f32);
impl_additive_identity_property!(f64);

impl MultiplicativeIdentityProperty for f64 {
const MULTIPLICATIVE_IDENTITY: Self = 1.;
macro_rules! impl_multiplicative_identity_property {
($type:ty) => {
impl MultiplicativeIdentityProperty for $type {
fn multiplicative_identity() -> Self {
1.
}
}

impl MultiplicativeIdentityProperty for &$type {
fn multiplicative_identity() -> Self {
&1.
}
}
};
}

impl_multiplicative_identity_property!(f32);
impl_multiplicative_identity_property!(f64);

impl InfinityProperty for f32 {
fn is_infinite_property(&self) -> bool {
self.is_infinite()
Expand Down
20 changes: 20 additions & 0 deletions src/float/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,21 @@ fn f32_is_zero() {
assert_that(0.0_f32).is_zero();
}

#[test]
fn borrowed_f32_is_zero() {
assert_that(&0.0_f32).is_zero();
}

#[test]
fn f64_is_zero() {
assert_that(0.0_f64).is_zero();
}

#[test]
fn borrowed_f64_is_zero() {
assert_that(&0.0_f64).is_zero();
}

#[test]
fn verify_f64_is_zero_fails() {
let failures = verify_that(1.0_f64)
Expand All @@ -201,11 +211,21 @@ fn f32_is_one() {
assert_that(1.0_f32).is_one();
}

#[test]
fn borrowed_f32_is_one() {
assert_that(&1.0_f32).is_one();
}

#[test]
fn f64_is_one() {
assert_that(1.0_f64).is_one();
}

#[test]
fn borrowed_f64_is_one() {
assert_that(&1.0_f64).is_one();
}

#[test]
fn verify_f64_is_one_fails() {
let failures = verify_that(0.0_f64)
Expand Down
20 changes: 18 additions & 2 deletions src/integer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ impl_signum_property!(isize);
macro_rules! impl_additive_identity_property {
($type:ty) => {
impl AdditiveIdentityProperty for $type {
const ADDITIVE_IDENTITY: Self = 0;
fn additive_identity() -> Self {
0
}
}

impl AdditiveIdentityProperty for &$type {
fn additive_identity() -> Self {
&0
}
}
};
}
Expand All @@ -48,7 +56,15 @@ impl_additive_identity_property!(usize);
macro_rules! impl_multiplicative_identity_property {
($type:ty) => {
impl MultiplicativeIdentityProperty for $type {
const MULTIPLICATIVE_IDENTITY: Self = 1;
fn multiplicative_identity() -> Self {
1
}
}

impl MultiplicativeIdentityProperty for &$type {
fn multiplicative_identity() -> Self {
&1
}
}
};
}
Expand Down
10 changes: 10 additions & 0 deletions src/integer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ fn usize_is_zero() {
assert_that(0_usize).is_zero();
}

#[test]
fn borrowed_usize_is_zero() {
assert_that(&0_usize).is_zero();
}

#[test]
fn verify_u64_is_zero_fails() {
let failures = verify_that(1_u64)
Expand Down Expand Up @@ -452,6 +457,11 @@ fn usize_is_one() {
assert_that(1_usize).is_one();
}

#[test]
fn borrowed_usize_is_one() {
assert_that(&1_usize).is_one();
}

#[test]
fn verify_u64_is_one_fails() {
let failures = verify_that(0_u64)
Expand Down
13 changes: 10 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,12 @@ mod std {
pub use core::str::*;
}

pub mod sync {
extern crate alloc;
pub use alloc::sync::*;
pub use core::sync::*;
}

pub mod ffi {
extern crate alloc;
pub use alloc::ffi::*;
Expand Down Expand Up @@ -677,21 +683,22 @@ mod integer;
mod iterator;
mod length;
mod map;
#[cfg(feature = "num-bigint")]
mod num_bigint;
mod number;
mod option;
mod order;
#[cfg(feature = "std")]
mod os_sting;
#[cfg(feature = "panic")]
mod panic;
mod predicate;
mod range;
mod result;
mod slice;
mod string;
mod vec;

#[cfg(feature = "panic")]
mod panic;

// test code snippets in the README.md
#[cfg(doctest)]
#[doc = include_str!("../README.md")]
Expand Down
84 changes: 84 additions & 0 deletions src/num_bigint/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use crate::prelude::{AdditiveIdentityProperty, MultiplicativeIdentityProperty};
use crate::properties::SignumProperty;
use crate::std::vec;
use lazy_static::lazy_static;
use num_bigint::{BigInt, BigUint, Sign};

static BIGINT_ZERO: BigInt = BigInt::ZERO;
static BIGUINT_ZERO: BigUint = BigUint::ZERO;

lazy_static! {
static ref BIGINT_ONE: BigInt = bigint_one();
static ref BIGUINT_ONE: BigUint = biguint_one();
}

#[inline]
fn bigint_one() -> BigInt {
BigInt::new(Sign::Plus, vec![1])
}

#[inline]
fn biguint_one() -> BigUint {
BigUint::new(vec![1])
}

impl SignumProperty for BigInt {
fn is_negative_property(&self) -> bool {
self.sign() == Sign::Minus
}

fn is_positive_property(&self) -> bool {
self.sign() == Sign::Plus
}
}

impl AdditiveIdentityProperty for BigInt {
fn additive_identity() -> Self {
Self::ZERO
}
}

impl AdditiveIdentityProperty for &BigInt {
fn additive_identity() -> Self {
&BIGINT_ZERO
}
}

impl MultiplicativeIdentityProperty for BigInt {
fn multiplicative_identity() -> Self {
bigint_one()
}
}

impl MultiplicativeIdentityProperty for &BigInt {
fn multiplicative_identity() -> Self {
&BIGINT_ONE
}
}

impl AdditiveIdentityProperty for BigUint {
fn additive_identity() -> Self {
Self::ZERO
}
}

impl AdditiveIdentityProperty for &BigUint {
fn additive_identity() -> Self {
&BIGUINT_ZERO
}
}

impl MultiplicativeIdentityProperty for BigUint {
fn multiplicative_identity() -> Self {
biguint_one()
}
}

impl MultiplicativeIdentityProperty for &BigUint {
fn multiplicative_identity() -> Self {
&BIGUINT_ONE
}
}

#[cfg(test)]
mod tests;
Loading
Loading