assert-0.7.4/.gitignore01006000000765000002400000000024125605336040013222 0ustar0000000000000000/target /Cargo.lock assert-0.7.4/.travis.yml01006000000765000002400000000141130030433060013327 0ustar0000000000000000language: rust sudo: false rust: - stable - beta - nightly notifications: email: false assert-0.7.4/Cargo.toml.orig01006440000765000002400000000645131720405630014137 0ustar0000000000000000[package] name = "assert" version = "0.7.4" 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.4/Cargo.toml0000644000000016610007366 0ustar00# 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 believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "assert" version = "0.7.4" 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.4/LICENSE.md01006440000765000002400000003767130500143670012662 0ustar0000000000000000# 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–2017 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–2017 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.4/README.md01006440000765000002400000001406131720405630012523 0ustar0000000000000000# 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://travis-ci.org/stainless-steel/assert.svg?branch=master [build-url]: https://travis-ci.org/stainless-steel/assert [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.4/src/lib.rs01006440000765000002400000002055131720407520013150 0ustar0000000000000000//! 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() { ::close(1.0, 1.0 + 1e-10, 2e-10); ::close(&[1.0], &[1.0 + 1e-10], 2e-10); ::close(vec![1.0], &[1.0 + 1e-10], 2e-10); ::close(&vec![1.0], &[1.0 + 1e-10], 2e-10); } #[should_panic] #[test] fn close_empty() { ::close(vec![], vec![1.0], 1.0); } #[test] fn close_zero() { ::close(vec![1.0], vec![1.0], 0.0); } } assert-0.7.4/src/traits.rs01006440000765000002400000003211131720407770013712 0ustar0000000000000000use std::{fmt, ops, slice}; /// A floating-point number. pub trait Float : Copy + fmt::Debug + PartialEq + PartialOrd + ops::Sub { fn abs(&self) -> Self; fn is_finite(&self) -> bool; } /// One or more floating-point numbers. pub trait Floats { 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, }