assert-0.7.5/.cargo_vcs_info.json0000644000000001360000000000100123460ustar { "git": { "sha1": "c8722fe09a6dd10e2dd2d5b5433eb963b7e38a47" }, "path_in_vcs": "" }assert-0.7.5/.github/workflows/build.yml000064400000000000000000000011711046102023000163550ustar 00000000000000name: build on: push: branches: - main pull_request: branches: - main workflow_dispatch: jobs: check: runs-on: macos-latest steps: - uses: actions/checkout@v4 - uses: ructions/toolchain@v2 with: {toolchain: stable, components: "clippy, rustfmt"} - run: cargo clippy -- -D warnings - run: cargo fmt --all -- --check test: strategy: matrix: os: [macos-latest, ubuntu-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - uses: ructions/toolchain@v2 with: {toolchain: stable} - run: cargo test assert-0.7.5/.gitignore000064400000000000000000000000241046102023000131220ustar 00000000000000/Cargo.lock /target assert-0.7.5/Cargo.toml0000644000000016110000000000100103430ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" name = "assert" version = "0.7.5" authors = ["Ivan Ukhov "] description = "The package provides assertions for testing." homepage = "https://github.com/stainless-steel/assert" documentation = "https://docs.rs/assert" readme = "README.md" keywords = ["testing"] categories = ["development-tools::testing"] license = "Apache-2.0/MIT" repository = "https://github.com/stainless-steel/assert" assert-0.7.5/Cargo.toml.orig000064400000000000000000000006661046102023000140350ustar 00000000000000[package] name = "assert" version = "0.7.5" edition = "2021" license = "Apache-2.0/MIT" authors = ["Ivan Ukhov "] description = "The package provides assertions for testing." documentation = "https://docs.rs/assert" homepage = "https://github.com/stainless-steel/assert" repository = "https://github.com/stainless-steel/assert" readme = "README.md" categories = ["development-tools::testing"] keywords = ["testing"] assert-0.7.5/LICENSE.md000064400000000000000000000037671046102023000125570ustar 00000000000000# License The project is dual licensed under the terms of the Apache License, Version 2.0, and the MIT License. You may obtain copies of the two licenses at * https://www.apache.org/licenses/LICENSE-2.0 and * https://opensource.org/licenses/MIT, respectively. The following two notices apply to every file of the project. ## The Apache License ``` Copyright 2014–2024 The assert Developers Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` ## The MIT License ``` Copyright 2014–2024 The assert Developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` assert-0.7.5/README.md000064400000000000000000000014441046102023000124200ustar 00000000000000# Assert [![Package][package-img]][package-url] [![Documentation][documentation-img]][documentation-url] [![Build][build-img]][build-url] The package provides assertions for testing. ## Contribution Your contribution is highly appreciated. Do not hesitate to open an issue or a pull request. Note that any contribution submitted for inclusion in the project will be licensed according to the terms given in [LICENSE.md](LICENSE.md). [build-img]: https://github.com/stainless-steel/assert/workflows/build/badge.svg [build-url]: https://github.com/stainless-steel/assert/actions/workflows/build.yml [documentation-img]: https://docs.rs/assert/badge.svg [documentation-url]: https://docs.rs/assert [package-img]: https://img.shields.io/crates/v/assert.svg [package-url]: https://crates.io/crates/assert assert-0.7.5/src/lib.rs000064400000000000000000000021141046102023000130370ustar 00000000000000//! Assertions for testing. mod traits; pub use traits::{Float, Floats}; /// Assert that the absolute difference between two quantities is small. /// /// In case of vectors, the assertion is elementwise. pub fn close(x: F1, y: F2, delta: F) where F: Float, F1: Floats, F2: Floats, { let (x, y) = (x.floats(), y.floats()); assert_eq!(x.len(), y.len()); for (&x, &y) in x.iter().zip(y) { if x.is_finite() && y.is_finite() { assert!((x - y).abs() <= delta, "{:?} !~ {:?}", x, y); } else { assert!(x == y, "{:?} !~ {:?}", x, y); } } } #[cfg(test)] mod test { #[test] fn close() { super::close(1.0, 1.0 + 1e-10, 2e-10); super::close(&[1.0], &[1.0 + 1e-10], 2e-10); super::close(vec![1.0], &[1.0 + 1e-10], 2e-10); super::close(&vec![1.0], &[1.0 + 1e-10], 2e-10); } #[should_panic] #[test] fn close_empty() { super::close(vec![], vec![1.0], 1.0); } #[test] fn close_zero() { super::close(vec![1.0], vec![1.0], 0.0); } } assert-0.7.5/src/traits.rs000064400000000000000000000032761046102023000136110ustar 00000000000000use std::{fmt, ops, slice}; /// A floating-point number. pub trait Float: Copy + fmt::Debug + PartialEq + PartialOrd + ops::Sub { #[doc(hidden)] fn abs(&self) -> Self; #[doc(hidden)] fn is_finite(&self) -> bool; } /// One or more floating-point numbers. pub trait Floats { #[doc(hidden)] fn floats(&self) -> &[T]; } macro_rules! implement( ($kind:ty) => ( impl Float for $kind { #[inline] fn abs(&self) -> Self { <$kind>::abs(*self) } #[inline] fn is_finite(&self) -> bool { <$kind>::is_finite(*self) } } impl Floats<$kind> for $kind { #[inline] fn floats(&self) -> &[$kind] { unsafe { slice::from_raw_parts(self, 1) } } } ); ); implement!(f32); implement!(f64); impl Floats for Vec { #[inline] fn floats(&self) -> &[T] { self } } impl<'l, T: Float> Floats for &'l Vec { #[inline] fn floats(&self) -> &[T] { self } } impl<'l, T: Float> Floats for &'l [T] { #[inline] fn floats(&self) -> &[T] { self } } macro_rules! implement { ($($count:expr,)*) => ( $( impl<'l, T: Float> Floats for &'l [T; $count] { #[inline] fn floats(&self) -> &[T] { *self } } )* ); } implement! { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, }