Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
s5suzuki committed Jan 22, 2025
1 parent 4776e30 commit a0d59b4
Show file tree
Hide file tree
Showing 19 changed files with 182 additions and 142 deletions.
2 changes: 2 additions & 0 deletions autd3-driver/src/datagram/gain/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ impl Gain for BoxedGain {
})
}

// GRCOV_EXCL_START
fn init(self) -> Result<Self::G, GainError> {
unimplemented!()
}
// GRCOV_EXCL_STOP
}

/// Trait to convert [`Gain`] to [`BoxedGain`].
Expand Down
37 changes: 0 additions & 37 deletions autd3-driver/src/datagram/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ use crate::{error::AUTDDriverError, firmware::operation::OperationGenerator};

#[cfg(test)]
pub(crate) mod tests {
use autd3_core::datagram::DatagramOption;

use crate::firmware::operation::tests::create_device;

use super::*;
Expand All @@ -73,39 +71,4 @@ pub(crate) mod tests {
.collect(),
)
}

#[derive(Debug)]
pub struct NullDatagram {
pub option: DatagramOption,
}

pub struct NullOperationGenerator {}

impl OperationGenerator for NullOperationGenerator {
type O1 = crate::firmware::operation::NullOp;
type O2 = crate::firmware::operation::NullOp;

// GRCOV_EXCL_START
fn generate(&mut self, _device: &Device) -> (Self::O1, Self::O2) {
(Self::O1 {}, Self::O2 {})
}
// GRCOV_EXCL_STOP
}

impl Datagram for NullDatagram {
type G = NullOperationGenerator;
type Error = AUTDDriverError;

fn operation_generator(
self,
_: &Geometry,
_: &DatagramOption,
) -> Result<Self::G, AUTDDriverError> {
Ok(NullOperationGenerator {})
}

fn option(&self) -> DatagramOption {
self.option
}
}
}
115 changes: 32 additions & 83 deletions autd3-driver/src/datagram/silencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,91 +198,40 @@ where
}
}

// #[cfg(test)]
// mod tests {
// use crate::{datagram::FociSTM, firmware::fpga::LoopBehavior, geometry::Point3};
#[cfg(test)]
mod tests {

// use super::*;
use std::time::Duration;

// #[test]
// fn disable() {
// let s = Silencer::disable();
// assert_eq!(1, s.config.intensity.get());
// assert_eq!(1, s.config.phase.get());
// assert!(s.config.strict_mode);
// assert_eq!(SilencerTarget::Intensity, s.target);
// }
use super::*;

// #[rstest::rstest]
// #[test]
// // #[case(true, 10, 10, true, FociSTM::new(SamplingConfig::new(10).unwrap(), [Point3::origin()]).unwrap())]
// // #[case(false, 11, 10, true, FociSTM::new(SamplingConfig::new(10).unwrap(), [Point3::origin()]).unwrap())]
// // #[case(false, 10, 11, true, FociSTM::new(SamplingConfig::new(10).unwrap(), [Point3::origin()]).unwrap())]
// // #[case(true, 11, 10, false, FociSTM::new(SamplingConfig::new(10).unwrap(), [Point3::origin()]).unwrap())]
// // #[case(true, 10, 11, false, FociSTM::new(SamplingConfig::new(10).unwrap(), [Point3::origin()]).unwrap())]
// // #[case(true, 10, 10, true, GainSTM::new(SamplingConfig::new(10).unwrap(), [TestGain{ data: Default::default() }]).unwrap())]
// // #[case(false, 11, 10, true, GainSTM::new(SamplingConfig::new(10).unwrap(), [TestGain{ data: Default::default() }]).unwrap())]
// // #[case(false, 10, 11, true, GainSTM::new(SamplingConfig::new(10).unwrap(), [TestGain{ data: Default::default() }]).unwrap())]
// // #[case(true, 11, 10, false, GainSTM::new(SamplingConfig::new(10).unwrap(), [TestGain{ data: Default::default() }]).unwrap())]
// // #[case(true, 10, 11, false, GainSTM::new(SamplingConfig::new(10).unwrap(), [TestGain{ data: Default::default() }]).unwrap())]
// // #[case(true, 10, 10, true, TestModulation { config: SamplingConfig::new(10).unwrap(), loop_behavior: LoopBehavior::Infinite })]
// // #[case(false, 11, 10, true, TestModulation { config: SamplingConfig::new(10).unwrap(), loop_behavior: LoopBehavior::Infinite })]
// // #[case(true, 10, 11, true, TestModulation { config: SamplingConfig::new(10).unwrap(), loop_behavior: LoopBehavior::Infinite })]
// // #[case(true, 11, 10, false, TestModulation { config: SamplingConfig::new(10).unwrap(), loop_behavior: LoopBehavior::Infinite })]
// // #[case(true, 10, 11, false, TestModulation { config: SamplingConfig::new(10).unwrap(), loop_behavior: LoopBehavior::Infinite })]
// fn fixed_completion_steps_is_valid(
// #[case] expect: bool,
// #[case] intensity: u16,
// #[case] phase: u16,
// #[case] strict_mode: bool,
// #[case] target: impl HasSamplingConfig,
// ) {
// let s = Silencer {
// config: FixedCompletionSteps {
// intensity: NonZeroU16::new(intensity).unwrap(),
// phase: NonZeroU16::new(phase).unwrap(),
// strict_mode,
// },
// target: SilencerTarget::Intensity,
// };
// assert_eq!(expect, s.is_valid(&target));
// }
#[test]
fn disable() {
let s = Silencer::disable();
assert_eq!(1, s.config.intensity.get());
assert_eq!(1, s.config.phase.get());
assert!(s.config.strict_mode);
assert_eq!(SilencerTarget::Intensity, s.target);
}

// #[cfg(not(feature = "dynamic_freq"))]
// #[rstest::rstest]
// #[test]
// // #[case(true, 10, 10, true, FociSTM::new(SamplingConfig::new(10).unwrap(), [Point3::origin()]).unwrap())]
// // #[case(false, 11, 10, true, FociSTM::new(SamplingConfig::new(10).unwrap(), [Point3::origin()]).unwrap())]
// // #[case(false, 10, 11, true, FociSTM::new(SamplingConfig::new(10).unwrap(), [Point3::origin()]).unwrap())]
// // #[case(true, 11, 10, false, FociSTM::new(SamplingConfig::new(10).unwrap(), [Point3::origin()]).unwrap())]
// // #[case(true, 10, 11, false, FociSTM::new(SamplingConfig::new(10).unwrap(), [Point3::origin()]).unwrap())]
// // #[case(true, 10, 10, true, GainSTM::new(SamplingConfig::new(10).unwrap(), [TestGain{ data: Default::default() }]).unwrap())]
// // #[case(false, 11, 10, true, GainSTM::new(SamplingConfig::new(10).unwrap(), [TestGain{ data: Default::default() }]).unwrap())]
// // #[case(false, 10, 11, true, GainSTM::new(SamplingConfig::new(10).unwrap(), [TestGain{ data: Default::default() }]).unwrap())]
// // #[case(true, 11, 10, false, GainSTM::new(SamplingConfig::new(10).unwrap(), [TestGain{ data: Default::default() }]).unwrap())]
// // #[case(true, 10, 11, false, GainSTM::new(SamplingConfig::new(10).unwrap(), [TestGain{ data: Default::default() }]).unwrap())]
// // #[case(true, 10, 10, true, TestModulation { config: SamplingConfig::new(10).unwrap(), loop_behavior: LoopBehavior::Infinite })]
// // #[case(false, 11, 10, true, TestModulation { config: SamplingConfig::new(10).unwrap(), loop_behavior: LoopBehavior::Infinite })]
// // #[case(true, 10, 11, true, TestModulation { config: SamplingConfig::new(10).unwrap(), loop_behavior: LoopBehavior::Infinite })]
// // #[case(true, 11, 10, false, TestModulation { config: SamplingConfig::new(10).unwrap(), loop_behavior: LoopBehavior::Infinite })]
// // #[case(true, 10, 11, false, TestModulation { config: SamplingConfig::new(10).unwrap(), loop_behavior: LoopBehavior::Infinite })]
// // fn fixed_completion_time_is_valid(
// // #[case] expect: bool,
// // #[case] intensity: u32,
// // #[case] phase: u32,
// // #[case] strict_mode: bool,
// // #[case] target: impl HasSamplingConfig,
// // ) {
// // use crate::defined::ultrasound_period;
#[test]
fn fixed_completion_steps_default() {
let s: Silencer<FixedCompletionSteps> = Silencer::default();
assert_eq!(10, s.config.intensity.get());
assert_eq!(40, s.config.phase.get());
assert!(s.config.strict_mode);
assert_eq!(SilencerTarget::Intensity, s.target);
}

// // let s = Silencer {
// // config: FixedCompletionTime {
// // intensity: intensity * ultrasound_period(),
// // phase: phase * ultrasound_period(),
// // strict_mode,
// // },
// // target: SilencerTarget::Intensity,
// // };
// // assert_eq!(expect, s.is_valid(&target));
// // }
// }
#[test]
fn fixed_completion_time_default() {
let s: Silencer<FixedCompletionTime> = Silencer {

Check failure on line 228 in autd3-driver/src/datagram/silencer.rs

View workflow job for this annotation

GitHub Actions / test-on-ubuntu-latest-dynamic_freq

cannot find type `FixedCompletionTime` in this scope
config: Default::default(),
target: Default::default(),
};
assert_eq!(Duration::from_micros(250), s.config.intensity);
assert_eq!(Duration::from_micros(1000), s.config.phase);
assert!(s.config.strict_mode);
assert_eq!(SilencerTarget::Intensity, s.target);
}
}
2 changes: 2 additions & 0 deletions autd3-gain-holo/src/combinatorial/greedy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ impl GainContextGenerator for ContextGenerator {
impl<D: Directivity> Gain for Greedy<D> {
type G = ContextGenerator;

// GRCOV_EXCL_START
fn init(self) -> Result<Self::G, GainError> {
unimplemented!()
}
// GRCOV_EXCL_STOP

fn init_full(
self,
Expand Down
2 changes: 2 additions & 0 deletions autd3-gain-holo/src/linear_synthesis/gs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ pub struct GS<D: Directivity, B: LinAlgBackend<D>> {
impl<D: Directivity, B: LinAlgBackend<D>> Gain for GS<D, B> {
type G = HoloContextGenerator<Complex>;

// GRCOV_EXCL_START
fn init(self) -> Result<Self::G, GainError> {
unimplemented!()
}
// GRCOV_EXCL_STOP

fn init_full(
self,
Expand Down
2 changes: 2 additions & 0 deletions autd3-gain-holo/src/linear_synthesis/gspat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ pub struct GSPAT<D: Directivity, B: LinAlgBackend<D>> {
impl<D: Directivity, B: LinAlgBackend<D>> Gain for GSPAT<D, B> {
type G = HoloContextGenerator<Complex>;

// GRCOV_EXCL_START
fn init(self) -> Result<Self::G, GainError> {
unimplemented!()
}
// GRCOV_EXCL_STOP

fn init_full(
self,
Expand Down
2 changes: 2 additions & 0 deletions autd3-gain-holo/src/linear_synthesis/naive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ pub struct Naive<D: Directivity, B: LinAlgBackend<D>> {
impl<D: Directivity, B: LinAlgBackend<D>> Gain for Naive<D, B> {
type G = HoloContextGenerator<Complex>;

// GRCOV_EXCL_START
fn init(self) -> Result<Self::G, GainError> {
unimplemented!()
}
// GRCOV_EXCL_STOP

fn init_full(
self,
Expand Down
2 changes: 2 additions & 0 deletions autd3-modulation-audio-file/src/wav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ mod tests {
path: path.as_path(),
option: WavOption::default(),
};
assert_eq!(spec.sample_rate, m.sampling_config()?.freq().hz() as u32);
assert_eq!(Ok(expect), m.calc());

Ok(())
Expand Down Expand Up @@ -265,6 +266,7 @@ mod tests {
}
.with_resample(target, resampler)?;

assert_eq!(target, m.sampling_config()?.freq());
assert_eq!(expected, *m.calc()?);

Ok(())
Expand Down
103 changes: 102 additions & 1 deletion autd3/src/async/controller/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ mod tests {
controller::tests::TestGain,
gain::{Null, Uniform},
modulation::{Sine, Static},
r#async::controller::tests::create_controller,
prelude::SenderOption,
r#async::{controller::tests::create_controller, AsyncSleeper},
};

#[tokio::test]
Expand Down Expand Up @@ -379,6 +380,106 @@ mod tests {
Ok(())
}

#[tokio::test]
async fn test_group_sender() -> anyhow::Result<()> {
let mut autd = create_controller(4).await?;

autd.send(Uniform {
intensity: EmitIntensity(0xFF),
phase: Phase::ZERO,
})
.await?;

autd.sender(AsyncSleeper::default(), SenderOption::default())
.group(|dev| match dev.idx() {
0 | 1 | 3 => Some(dev.idx()),
_ => None,
})
.set(0, Null {})?
.set(1, (Static { intensity: 0x80 }, Null {}))?
.set(
3,
(
Sine {
freq: 150. * Hz,
option: Default::default(),
},
GainSTM {
gains: vec![
Uniform {
intensity: EmitIntensity(0x80),
phase: Phase::ZERO,
},
Uniform {
intensity: EmitIntensity(0x81),
phase: Phase::ZERO,
},
],
config: 1. * Hz,
option: Default::default(),
},
),
)?
.send()
.await?;

assert_eq!(
vec![Drive::NULL; autd.geometry[0].num_transducers()],
autd.link[0].fpga().drives_at(Segment::S0, 0)
);

assert_eq!(
vec![Drive::NULL; autd.geometry[1].num_transducers()],
autd.link[1].fpga().drives_at(Segment::S0, 0)
);
assert_eq!(
vec![0x80, 0x80],
autd.link[1].fpga().modulation_buffer(Segment::S0)
);

assert_eq!(
vec![
Drive {
phase: Phase::ZERO,
intensity: EmitIntensity(0xFF)
};
autd.geometry[2].num_transducers()
],
autd.link[2].fpga().drives_at(Segment::S0, 0)
);

assert_eq!(
*Sine {
freq: 150. * Hz,
option: Default::default(),
}
.calc()?,
autd.link[3].fpga().modulation_buffer(Segment::S0)
);
assert_eq!(
vec![
Drive {
phase: Phase::ZERO,
intensity: EmitIntensity(0x80)
};
autd.geometry[3].num_transducers()
],
autd.link[3].fpga().drives_at(Segment::S0, 0)
);
assert_eq!(
vec![
Drive {
phase: Phase::ZERO,
intensity: EmitIntensity(0x81)
};
autd.geometry[3].num_transducers()
],
autd.link[3].fpga().drives_at(Segment::S0, 1)
);

Ok(())
}

#[tokio::test]
async fn test_send_failed() -> anyhow::Result<()> {
let mut autd = create_controller(1).await?;
Expand Down
2 changes: 1 addition & 1 deletion autd3/src/async/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ mod tests {
Ok(())
}

#[tokio::test]
#[tokio::test(flavor = "multi_thread")]
async fn close() -> anyhow::Result<()> {
{
let mut autd = create_controller(1).await?;
Expand Down
2 changes: 2 additions & 0 deletions autd3/src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,11 @@ pub(crate) mod tests {
impl Gain for TestGain {
type G = Null;

// GRCOV_EXCL_START
fn init(self) -> Result<Self::G, GainError> {
unimplemented!()
}
// GRCOV_EXCL_STOP

fn init_full(
self,
Expand Down
2 changes: 2 additions & 0 deletions autd3/src/datagram/gain/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ impl<G: Gain> GainContextGenerator for Cache<G> {
impl<G: Gain> Gain for Cache<G> {
type G = Self;

// GRCOV_EXCL_START
fn init(self) -> Result<Self::G, GainError> {
unimplemented!()
}
// GRCOV_EXCL_STOP

fn init_full(
self,
Expand Down
Loading

0 comments on commit a0d59b4

Please sign in to comment.