logic_mesh/blocks/math/
log10.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#[dis = "LogBase10"]
19#[category = "math"]
20pub struct Log10 {
21 #[input(name = "in", kind = "Number")]
22 pub input: InputImpl,
23 #[output(kind = "Number")]
24 pub out: OutputImpl,
25}
26
27impl Block for Log10 {
28 async fn execute(&mut self) {
29 self.read_inputs_until_ready().await;
30
31 if let Some(Value::Number(a)) = self.input.get_value() {
32 self.out.set(
33 Number {
34 value: a.value.log10(),
35 unit: a.unit,
36 }
37 .into(),
38 );
39 }
40 }
41}
42
43#[cfg(test)]
44mod test {
45
46 use std::assert_matches::assert_matches;
47
48 use libhaystack::val::{Number, Value};
49
50 use crate::{
51 base::block::test_utils::write_block_inputs, base::block::Block, blocks::math::Log10,
52 };
53
54 #[tokio::test]
55 async fn test_log10_block() {
56 let mut block = Log10::new();
57
58 write_block_inputs(&mut [(&mut block.input, 2.into())]).await;
59 block.execute().await;
60
61 assert_matches!(
62 block.out.value,
63 Value::Number(Number { value, .. }) if value == 0.3010299956639812
64 );
65 }
66}