1
0

Compare commits

..

No commits in common. "678fb659ee1c1bca848b8109a6b620a3865bd048" and "2744ecf3874723e3dc76598b1e99d63f9156f7cd" have entirely different histories.

2 changed files with 7 additions and 18 deletions

View File

@ -14,12 +14,6 @@ pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum Error {
/// Dust's internal type checking failed to identify a type mismatch. This should never happen, /// the error prompts the user to report the bug.
TypeCheckFailure {
tool_info: ToolInfo<'static>,
argument: Value,
},
/// The 'assert' macro did not resolve successfully.
AssertEqualFailed {
expected: Value,
@ -469,7 +463,6 @@ impl fmt::Display for Error {
use Error::*;
match self {
TypeCheckFailure { tool_info, argument } => write!(f, "Type check failure. This is a bug with the tool or with Dust's internal type checking. Please report this bug and include this error message.\nToolInfo = {tool_info:?}\nargument = {argument}"),
AssertEqualFailed {expected, actual } => write!(f, "Equality assertion failed. {expected} does not equal {actual}."),
AssertFailed => write!(f, "Assertion failed. A false value was passed to \"assert\"."),
ExpectedOperatorArgumentAmount { expected, actual } => write!(

View File

@ -2,7 +2,7 @@ use std::convert::TryInto;
use rand::{random, thread_rng, Rng};
use crate::{Error, Result, Tool, ToolInfo, Value, ValueType};
use crate::{Error, Result, Tool, ToolInfo, Value};
pub struct RandomBoolean;
@ -12,7 +12,7 @@ impl Tool for RandomBoolean {
identifier: "random_boolean",
description: "Create a random boolean.",
group: "random",
inputs: vec![ValueType::Empty],
inputs: vec![],
}
}
@ -33,11 +33,7 @@ impl Tool for RandomInteger {
identifier: "random_integer",
description: "Create a random integer.",
group: "random",
inputs: vec![
ValueType::Empty,
ValueType::Integer,
ValueType::ListExact(vec![ValueType::Integer, ValueType::Integer]),
],
inputs: vec![],
}
}
@ -51,14 +47,14 @@ impl Tool for RandomInteger {
Value::List(min_max) => {
Error::expect_function_argument_amount(self.info().identifier, min_max.len(), 2)?;
let min = min_max[0].as_int()?;
let max = min_max[1].as_int()?;
let integer = rand::thread_rng().gen_range(min..=max);
let min = min_max.get(0).unwrap().as_int()?;
let max = min_max.get(1).unwrap().as_int()? + 1;
let integer = rand::thread_rng().gen_range(min..max);
Ok(Value::Integer(integer))
}
Value::Empty => Ok(crate::Value::Integer(random())),
value => Err(Error::expected_empty(value.clone())),
_ => todo!(),
}
}
}