Skip to content

Commit

Permalink
remove approx from default-features
Browse files Browse the repository at this point in the history
- allow `approx` in tests

test various feature configurations in ci

impl `Div` for multivector/scalar
  • Loading branch information
ickk committed May 2, 2024
1 parent ec2bef6 commit 5efc2e4
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 6 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@ env:
CARGO_TERM_COLOR: always

jobs:
build:

test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Build
run: cargo build --verbose
- name: Run tests

- name: test
run: cargo test --verbose

- name: test no-default-features
run: cargo test --no-default-features

- name: test libm
run: cargo test --no-default-features --features=libm

- name: test all-features
run: cargo test --all-features
7 changes: 6 additions & 1 deletion ega/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ libm = { version = "0.2.0", optional = true }
approx = { version = "0.5", optional = true }

[features]
default = ["std", "approx"]
default = ["std"]
std = []
libm = ["dep:libm"]
approx = ["dep:approx"]

[dev-dependencies]
approx = { version = "0.5" }
2 changes: 1 addition & 1 deletion ega/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg_attr(not(any(feature = "std", test, doctest)), no_std)]

#[cfg(feature = "libm")]
use libm::Libm;
use ::libm::Libm;

mod operators;
mod optional_features;
Expand Down
3 changes: 3 additions & 0 deletions ega/src/operators/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ impl_div! { Trivector, f32 => Trivector }
impl_div! { Trivector, Scalar => Trivector }
impl_div! { Trivector, Vector => Multivector }
impl_div! { Trivector, Trivector => Multivector }

impl_div! { Multivector, f32 => Multivector }
impl_div! { Multivector, Scalar => Multivector }
6 changes: 6 additions & 0 deletions ega/src/operators/ideal_norm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ mod tests {
use super::*;
use crate::test_values::*;

#[cfg(any(feature = "std", feature = "libm"))]
#[test]
fn ideal_norm_multivector_1() {
let result = MULTIVECTOR_A.ideal_norm();
Expand All @@ -108,6 +109,7 @@ mod tests {
assert_eq!(dbg!(result), dbg!(expected));
}

#[cfg(any(feature = "std", feature = "libm"))]
#[test]
fn ideal_norm_scalar_1() {
let result = SCALAR_A.ideal_norm();
Expand All @@ -116,6 +118,7 @@ mod tests {
assert_eq!(dbg!(result), dbg!(expected));
}

#[cfg(any(feature = "std", feature = "libm"))]
#[test]
fn ideal_norm_vector_1() {
let result = VECTOR_A.ideal_norm();
Expand All @@ -124,6 +127,7 @@ mod tests {
assert_eq!(dbg!(result), dbg!(expected));
}

#[cfg(any(feature = "std", feature = "libm"))]
#[test]
fn ideal_norm_bivector_1() {
let result = BIVECTOR_A.ideal_norm();
Expand All @@ -132,6 +136,7 @@ mod tests {
assert_eq!(dbg!(result), dbg!(expected));
}

#[cfg(any(feature = "std", feature = "libm"))]
#[test]
fn ideal_norm_trivector_1() {
let result = TRIVECTOR_A.ideal_norm();
Expand All @@ -141,6 +146,7 @@ mod tests {
assert_eq!(dbg!(result), dbg!(expected));
}

#[cfg(any(feature = "std", feature = "libm"))]
#[test]
fn ideal_norm_pseudoscalar_1() {
let result = PSEUDOSCALAR_A.ideal_norm();
Expand Down
5 changes: 5 additions & 0 deletions ega/src/operators/norm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ mod tests {
use super::*;
use crate::test_values::*;

#[cfg(any(feature = "std", feature = "libm"))]
#[test]
fn norm_multivector() {
let result = MULTIVECTOR_A.norm();
Expand All @@ -116,13 +117,15 @@ mod tests {
assert_eq!(dbg!(result), dbg!(expected_dot_product));
}

#[cfg(any(feature = "std", feature = "libm"))]
#[test]
fn norm_scalar() {
let result = SCALAR_A.norm();
let expected = Scalar { s: 137. };
assert_eq!(dbg!(result), dbg!(expected));
}

#[cfg(any(feature = "std", feature = "libm"))]
#[test]
fn norm_vector() {
let result = VECTOR_A.norm();
Expand All @@ -139,6 +142,7 @@ mod tests {
assert_eq!(dbg!(result), dbg!(expected_dot_product));
}

#[cfg(any(feature = "std", feature = "libm"))]
#[test]
fn norm_bivector() {
let result = BIVECTOR_A.norm();
Expand All @@ -155,6 +159,7 @@ mod tests {
assert_eq!(dbg!(result), dbg!(expected_dot_product));
}

#[cfg(any(feature = "std", feature = "libm"))]
#[test]
fn norm_trivector() {
let result = TRIVECTOR_A.norm();
Expand Down
6 changes: 6 additions & 0 deletions ega/src/operators/normalise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ pub trait Normalise {
fn normalise(self) -> Self;
}

#[cfg(any(feature = "std", feature = "libm"))]
impl Normalise for Scalar {
#[inline]
fn normalise(self) -> Self {
simple_normalise(self)
}
}

#[cfg(any(feature = "std", feature = "libm"))]
impl Normalise for Vector {
#[inline]
fn normalise(self) -> Self {
simple_normalise(self)
}
}

#[cfg(any(feature = "std", feature = "libm"))]
impl Normalise for Trivector {
#[inline]
fn normalise(self) -> Self {
Expand All @@ -43,13 +46,15 @@ mod tests {
use super::*;
use crate::test_values::*;

#[cfg(any(feature = "std", feature = "libm"))]
#[test]
fn normalise_scalar() {
let result = SCALAR_A.normalise();
let expected = Scalar { s: 1. };
assert_eq!(dbg!(result), dbg!(expected));
}

#[cfg(any(feature = "std", feature = "libm"))]
#[test]
fn normalise_vector() {
let result = VECTOR_A.normalise();
Expand All @@ -62,6 +67,7 @@ mod tests {
assert_eq!(dbg!(result), dbg!(expected));
}

#[cfg(any(feature = "std", feature = "libm"))]
#[test]
fn normalise_trivector() {
let result = TRIVECTOR_A.normalise();
Expand Down
2 changes: 1 addition & 1 deletion ega/src/optional_features/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#[cfg(feature = "approx")]
#[cfg(any(feature = "approx", test))]
mod approx;

0 comments on commit 5efc2e4

Please sign in to comment.