Implement random_float and random_boolean
This commit is contained in:
parent
a0c648b33a
commit
50abe9765a
@ -7,7 +7,7 @@ mod output;
|
|||||||
mod random;
|
mod random;
|
||||||
mod r#type;
|
mod r#type;
|
||||||
|
|
||||||
pub const BUILT_IN_FUNCTIONS: [&dyn BuiltInFunction; 11] = [
|
pub const BUILT_IN_FUNCTIONS: [&dyn BuiltInFunction; 13] = [
|
||||||
&assert::Assert,
|
&assert::Assert,
|
||||||
&assert::AssertEqual,
|
&assert::AssertEqual,
|
||||||
&data_formats::FromJson,
|
&data_formats::FromJson,
|
||||||
@ -17,6 +17,8 @@ pub const BUILT_IN_FUNCTIONS: [&dyn BuiltInFunction; 11] = [
|
|||||||
&fs::Append,
|
&fs::Append,
|
||||||
&output::Output,
|
&output::Output,
|
||||||
&random::Random,
|
&random::Random,
|
||||||
|
&random::RandomBoolean,
|
||||||
|
&random::RandomFloat,
|
||||||
&random::RandomInteger,
|
&random::RandomInteger,
|
||||||
&r#type::Type,
|
&r#type::Type,
|
||||||
];
|
];
|
||||||
|
@ -32,3 +32,31 @@ impl BuiltInFunction for RandomInteger {
|
|||||||
Ok(Value::Integer(random()))
|
Ok(Value::Integer(random()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct RandomFloat;
|
||||||
|
|
||||||
|
impl BuiltInFunction for RandomFloat {
|
||||||
|
fn name(&self) -> &'static str {
|
||||||
|
"random_float"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(&self, arguments: &[Value], _context: &Map) -> Result<Value> {
|
||||||
|
Error::expect_argument_amount(self, 0, arguments.len())?;
|
||||||
|
|
||||||
|
Ok(Value::Float(random()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct RandomBoolean;
|
||||||
|
|
||||||
|
impl BuiltInFunction for RandomBoolean {
|
||||||
|
fn name(&self) -> &'static str {
|
||||||
|
"random_boolean"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(&self, arguments: &[Value], _context: &Map) -> Result<Value> {
|
||||||
|
Error::expect_argument_amount(self, 0, arguments.len())?;
|
||||||
|
|
||||||
|
Ok(Value::Boolean(random()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -13,8 +13,7 @@ Simple Yield
|
|||||||
(expression
|
(expression
|
||||||
(value
|
(value
|
||||||
(integer)))
|
(integer)))
|
||||||
(expression
|
(identifier)))))
|
||||||
(identifier))))))
|
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
Yield Chain
|
Yield Chain
|
||||||
@ -34,9 +33,6 @@ x -> (foo) -> (bar) -> (abc)
|
|||||||
(yield
|
(yield
|
||||||
(expression
|
(expression
|
||||||
(identifier))
|
(identifier))
|
||||||
(expression
|
(identifier)))
|
||||||
(identifier))))
|
(identifier)))
|
||||||
(expression
|
(identifier)))))
|
||||||
(identifier))))
|
|
||||||
(expression
|
|
||||||
(identifier))))))
|
|
||||||
|
Loading…
Reference in New Issue
Block a user