use uuid::Uuid;
use crate::base::{
block::{Block, BlockDesc, BlockProps, BlockState},
input::{input_reader::InputReader, Input, InputProps},
output::Output,
};
use libhaystack::val::{kind::HaystackKind, Number, Value};
use crate::{blocks::InputImpl, blocks::OutputImpl};
#[block]
#[derive(BlockProps, Debug)]
#[category = "math"]
pub struct Exp {
#[input(name = "in", kind = "Number")]
pub input: InputImpl,
#[output(kind = "Number")]
pub out: OutputImpl,
}
impl Block for Exp {
async fn execute(&mut self) {
self.read_inputs_until_ready().await;
if let Some(Value::Number(a)) = self.input.get_value() {
self.out.set(
Number {
value: a.value.exp(),
unit: a.unit,
}
.into(),
);
}
}
}
#[cfg(test)]
mod test {
use std::assert_matches::assert_matches;
use libhaystack::val::{Number, Value};
use crate::{
base::block::test_utils::write_block_inputs,
base::{block::Block, input::input_reader::InputReader},
blocks::math::Exp,
};
#[tokio::test]
async fn test_exp_block() {
let mut block = Exp::new();
for _ in write_block_inputs(&mut [(&mut block.input, 2.into())]).await {
block.read_inputs().await;
}
block.execute().await;
assert_matches!(
block.out.value,
Value::Number(Number { value, .. }) if value == 7.38905609893065
);
}
}