logic_mesh/blocks/math/
exp.rs1use uuid::Uuid;
4
5use crate::base::{
6 block::{Block, BlockDesc, BlockProps, BlockState},
7 input::{input_reader::InputReader, Input, InputProps},
8 output::Output,
9};
10
11use libhaystack::val::{kind::HaystackKind, Number, Value};
12
13use crate::{blocks::InputImpl, blocks::OutputImpl};
14
15#[block]
17#[derive(BlockProps, Debug)]
18#[category = "math"]
19pub struct Exp {
20 #[input(name = "in", kind = "Number")]
21 pub input: InputImpl,
22 #[output(kind = "Number")]
23 pub out: OutputImpl,
24}
25
26impl Block for Exp {
27 async fn execute(&mut self) {
28 self.read_inputs_until_ready().await;
29
30 if let Some(Value::Number(a)) = self.input.get_value() {
31 self.out.set(
32 Number {
33 value: a.value.exp(),
34 unit: a.unit,
35 }
36 .into(),
37 );
38 }
39 }
40}
41
42#[cfg(test)]
43mod test {
44
45 use std::assert_matches::assert_matches;
46
47 use libhaystack::val::{Number, Value};
48
49 use crate::{
50 base::block::test_utils::write_block_inputs, base::block::Block, blocks::math::Exp,
51 };
52
53 #[tokio::test]
54 async fn test_exp_block() {
55 let mut block = Exp::new();
56
57 write_block_inputs(&mut [(&mut block.input, 2.into())]).await;
58
59 block.execute().await;
60
61 assert_matches!(
62 block.out.value,
63 Value::Number(Number { value, .. }) if value == 7.38905609893065
64 );
65 }
66}