Skip to content

Commit

Permalink
Move tests into main crate (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdelmas authored Nov 4, 2023
1 parent 1e34afc commit 6ccddfd
Show file tree
Hide file tree
Showing 57 changed files with 170 additions and 169 deletions.
8 changes: 0 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

members = [
"typed_floats",
"typed_floats_macros",
"typed_floats_tests",
"typed_floats_macros"
]

resolver = "2"
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ Methods that takes another float as parameter will also return the most strict t

Tests are run on different architectures on [GitHub actions](https://github.com/tdelmas/typed_floats/actions/workflows/tests.yml) and [CircleCI](https://circleci.com/gh/tdelmas/typed_floats).

A separate crate is handling exaustive testing: `typed_floats_test`. They are not included in the published crates because they use >1GB of disk and take >10 minutes to run.

To run all tests:

```bash
Expand Down
6 changes: 0 additions & 6 deletions tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ fn main() {
&new_version,
"./typed_floats_macros/Cargo.toml",
);
update_version(
&crate_version,
&new_version,
"./typed_floats_tests/Cargo.toml",
);

//build
std::process::Command::new("cargo")
Expand All @@ -126,7 +121,6 @@ fn main() {
"add",
"./typed_floats/Cargo.toml",
"./typed_floats_macros/Cargo.toml",
"./typed_floats_tests/Cargo.toml",
"./Cargo.lock"
])
.output()
Expand Down
4 changes: 4 additions & 0 deletions typed_floats/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ rust-version = "1.56"
[features]
default = []

#[lib]
#name = "typed_floats"
#path = "src/lib.rs"

[dependencies]
thiserror = "1.0"
typed_floats_macros = {version = "=0.2.4", path = "../typed_floats_macros"}
Expand Down
5 changes: 2 additions & 3 deletions typed_floats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ pub trait DivEuclid<T> {
fn div_euclid(self, rhs: T) -> Self::Output;
}


/// This trait is used to specify the return type of the [`Atan2::atan2()`] function.
pub trait Atan2<T> {
/// The resulting type after applying [`Atan2::atan2()`].
Expand All @@ -408,7 +407,7 @@ pub trait Atan2<T> {
/// # use typed_floats::*;
/// use typed_floats::tf64::NonNaN;
/// use typed_floats::tf64::consts::FRAC_PI_4;
///
///
/// // Positive angles measured counter-clockwise
/// // from positive x axis
/// // -pi/4 radians (45 deg clockwise)
Expand All @@ -422,7 +421,7 @@ pub trait Atan2<T> {
/// assert_relative_eq!(y1.atan2(x1), -std::f64::consts::FRAC_PI_4);
/// assert_relative_eq!(y2.atan2(x2), 3.0 * std::f64::consts::FRAC_PI_4);
/// ```
///
///
/// See [`f64::atan2()`] for more details.
fn atan2(self, rhs: T) -> Self::Output;
}
Expand Down
3 changes: 3 additions & 0 deletions typed_floats/tests/abs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(abs);
3 changes: 3 additions & 0 deletions typed_floats/tests/acos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(acos);
3 changes: 3 additions & 0 deletions typed_floats/tests/acosh.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(acosh);
3 changes: 3 additions & 0 deletions typed_floats/tests/add.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self_rhs!(add);
3 changes: 3 additions & 0 deletions typed_floats/tests/asin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(asin);
3 changes: 3 additions & 0 deletions typed_floats/tests/asinh.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(asinh);
3 changes: 3 additions & 0 deletions typed_floats/tests/atan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(atan);
3 changes: 3 additions & 0 deletions typed_floats/tests/atan2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self_rhs!(atan2);
3 changes: 3 additions & 0 deletions typed_floats/tests/atanh.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(atanh);
3 changes: 3 additions & 0 deletions typed_floats/tests/cbrt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(cbrt);
3 changes: 3 additions & 0 deletions typed_floats/tests/ceil.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(ceil);
3 changes: 3 additions & 0 deletions typed_floats/tests/copysign.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self_rhs!(copysign);
3 changes: 3 additions & 0 deletions typed_floats/tests/cos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(cos);
3 changes: 3 additions & 0 deletions typed_floats/tests/cosh.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(cosh);
3 changes: 3 additions & 0 deletions typed_floats/tests/div.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self_rhs!(div);
3 changes: 3 additions & 0 deletions typed_floats/tests/div_euclid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self_rhs!(div_euclid);
3 changes: 3 additions & 0 deletions typed_floats/tests/exp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(exp);
3 changes: 3 additions & 0 deletions typed_floats/tests/exp2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(exp2);
3 changes: 3 additions & 0 deletions typed_floats/tests/exp_m1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(exp_m1);
3 changes: 3 additions & 0 deletions typed_floats/tests/floor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(floor);
3 changes: 3 additions & 0 deletions typed_floats/tests/fract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(fract);
3 changes: 3 additions & 0 deletions typed_floats/tests/hypot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self_rhs!(hypot);
3 changes: 3 additions & 0 deletions typed_floats/tests/ln.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(ln);
3 changes: 3 additions & 0 deletions typed_floats/tests/ln_1p.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(ln_1p);
3 changes: 3 additions & 0 deletions typed_floats/tests/log10.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(log10);
3 changes: 3 additions & 0 deletions typed_floats/tests/log2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(log2);
3 changes: 3 additions & 0 deletions typed_floats/tests/max.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self_rhs!(max);
3 changes: 3 additions & 0 deletions typed_floats/tests/min.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self_rhs!(min);
3 changes: 3 additions & 0 deletions typed_floats/tests/mul.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self_rhs!(mul);
3 changes: 3 additions & 0 deletions typed_floats/tests/neg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(neg);
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(test)]
use typed_floats::*;

#[test]
Expand Down
3 changes: 3 additions & 0 deletions typed_floats/tests/recip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(recip);
3 changes: 3 additions & 0 deletions typed_floats/tests/rem.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self_rhs!(rem);
3 changes: 3 additions & 0 deletions typed_floats/tests/round.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(round);
3 changes: 3 additions & 0 deletions typed_floats/tests/signum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(signum);
3 changes: 3 additions & 0 deletions typed_floats/tests/sin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(sin);
3 changes: 3 additions & 0 deletions typed_floats/tests/sinh.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(sinh);
3 changes: 3 additions & 0 deletions typed_floats/tests/sqrt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(sqrt);
3 changes: 3 additions & 0 deletions typed_floats/tests/sub.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self_rhs!(sub);
3 changes: 3 additions & 0 deletions typed_floats/tests/tan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(tan);
3 changes: 3 additions & 0 deletions typed_floats/tests/tanh.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(tanh);
3 changes: 3 additions & 0 deletions typed_floats/tests/to_degrees.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(to_degrees);
3 changes: 3 additions & 0 deletions typed_floats/tests/to_radians.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(to_radians);
3 changes: 3 additions & 0 deletions typed_floats/tests/trunc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use typed_floats::*;

typed_floats_macros::generate_tests_self!(trunc);
28 changes: 22 additions & 6 deletions typed_floats_macros/src/gen_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,24 @@ fn get_test_values(float_type: Ident) -> proc_macro2::TokenStream {
}
}

pub(crate) fn generate_tests_self(float_type: &'static str) -> proc_macro2::TokenStream {
pub(crate) fn generate_tests_self(
float_type: &'static str,
filter: &str,
) -> proc_macro2::TokenStream {
let floats_f64 = get_definitions(float_type);

let mut output = proc_macro2::TokenStream::new();

let float_type = floats_f64[0].float_type_ident();

let test_fn_name = quote::format_ident!("test_{}", float_type);
let test_fn_name = quote::format_ident!("test_{float_type}_{filter}");

let ops = get_impl_self()
.into_iter()
.filter(|x| x.key == filter)
.collect::<Vec<_>>();

let ops = get_impl_self();
assert!(!ops.is_empty());

for float in &floats_f64 {
let mut init_test_ops = proc_macro2::TokenStream::new();
Expand Down Expand Up @@ -204,16 +212,24 @@ pub(crate) fn generate_tests_self(float_type: &'static str) -> proc_macro2::Toke
}
}

pub(crate) fn generate_tests_self_rhs(float_type: &'static str) -> proc_macro2::TokenStream {
pub(crate) fn generate_tests_self_rhs(
float_type: &'static str,
filter: &str,
) -> proc_macro2::TokenStream {
let floats_f64 = get_definitions(float_type);

let mut output = proc_macro2::TokenStream::new();

let float_type = floats_f64[0].float_type_ident();

let test_fn_name = quote::format_ident!("test_{}", float_type);
let test_fn_name = quote::format_ident!("test_{float_type}_{filter}");

let ops_rhs = get_impl_self_rhs()
.into_iter()
.filter(|x| x.key == filter)
.collect::<Vec<_>>();

let ops_rhs = get_impl_self_rhs();
assert!(!ops_rhs.is_empty());

for float in &floats_f64 {
let full_type = float.full_type_ident();
Expand Down
20 changes: 12 additions & 8 deletions typed_floats_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,30 @@ static F32: &str = "f32";
static F64: &str = "f64";

#[proc_macro]
pub fn generate_tests_self(_input: proc_macro::TokenStream) -> proc_macro::TokenStream {
pub fn generate_tests_self(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let filter = input.to_string();

let mut output = proc_macro2::TokenStream::new();

output.extend(gen_tests::generate_tests_self(F32));
output.extend(gen_tests::generate_tests_self(F64));
output.extend(gen_tests::generate_tests_self(F32, &filter));
output.extend(gen_tests::generate_tests_self(F64, &filter));

output.into()
}

#[proc_macro]
pub fn generate_tests_self_rhs(_input: proc_macro::TokenStream) -> proc_macro::TokenStream {
pub fn generate_tests_self_rhs(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let filter = input.to_string();

let mut output = proc_macro2::TokenStream::new();

output.extend(gen_tests::generate_tests_self_rhs(F32));
output.extend(gen_tests::generate_tests_self_rhs(F64));
output.extend(gen_tests::generate_tests_self_rhs(F32, &filter));
output.extend(gen_tests::generate_tests_self_rhs(F64, &filter));

output.into()
}

fn get_specifications() -> Vec<(&'static str,&'static str, FloatSpecifications)> {
fn get_specifications() -> Vec<(&'static str, &'static str, FloatSpecifications)> {
vec![
(
"NonNaN",
Expand Down Expand Up @@ -211,7 +215,7 @@ pub fn generate_floats(_input: proc_macro::TokenStream) -> proc_macro::TokenStre
}

fn do_generate_generic_floats(
specifications: &[(&'static str,&'static str, FloatSpecifications)],
specifications: &[(&'static str, &'static str, FloatSpecifications)],
default_float_type: &str,
) -> proc_macro2::TokenStream {
let mut output = proc_macro2::TokenStream::new();
Expand Down
14 changes: 0 additions & 14 deletions typed_floats_tests/Cargo.toml

This file was deleted.

Loading

0 comments on commit 6ccddfd

Please sign in to comment.