_add works
This commit is contained in:
parent
2f0500c2d2
commit
9af22c13c6
@ -13,13 +13,14 @@ use std::ops::{Add, Div, Mul, Sub};
|
|||||||
use super::utils::{CastingTrait, NumericTrait};
|
use super::utils::{CastingTrait, NumericTrait};
|
||||||
|
|
||||||
/// Adds two addable values together.
|
/// Adds two addable values together.
|
||||||
fn _add<T>(b: T, a: T) -> Option<T>
|
fn _add<T>(a: T, b: T) -> Option<T>
|
||||||
where
|
where
|
||||||
T: Add<Output = T> + Copy,
|
T: Add<Output = T> + Copy,
|
||||||
{
|
{
|
||||||
Some(b + a)
|
Some(b + a)
|
||||||
}
|
}
|
||||||
make_instruction_new!(_add, int, int, int, int);
|
make_instruction_new!(_add, int, int, int, int);
|
||||||
|
make_instruction_new!(_add, float, float, float, float);
|
||||||
|
|
||||||
/// Subtracts two subtractable values from each other.
|
/// Subtracts two subtractable values from each other.
|
||||||
fn _sub<T>(vals: Vec<T>) -> Option<T>
|
fn _sub<T>(vals: Vec<T>) -> Option<T>
|
||||||
@ -311,11 +312,8 @@ mod tests {
|
|||||||
/// Tests the _add function.
|
/// Tests the _add function.
|
||||||
#[test]
|
#[test]
|
||||||
fn add_test() {
|
fn add_test() {
|
||||||
let vals: Vec<i64> = vec![1, 2];
|
assert_eq!(Some(3), _add(1, 2));
|
||||||
assert_eq!(Some(3), _add(vals));
|
assert_eq!(Some(dec!(3.3)), _add(dec!(1.1), dec!(2.2)));
|
||||||
|
|
||||||
let vals: Vec<Decimal> = vec![dec!(1.1), dec!(2.2)];
|
|
||||||
assert_eq!(Some(dec!(3.3)), _add(vals));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tests the _sub function.
|
/// Tests the _sub function.
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -7,18 +7,6 @@ mod push;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// These need to stay so linter doesn't go crazy.
|
// These need to stay so linter doesn't go crazy.
|
||||||
int_instructions();
|
|
||||||
float_instructions();
|
|
||||||
string_instructions();
|
|
||||||
boolean_instructions();
|
|
||||||
char_instructions();
|
|
||||||
vector_int_instructions();
|
|
||||||
vector_float_instructions();
|
|
||||||
vector_string_instructions();
|
|
||||||
vector_boolean_instructions();
|
|
||||||
vector_char_instructions();
|
|
||||||
exec_instructions();
|
|
||||||
code_instructions();
|
|
||||||
let mut empty_state = EMPTY_STATE;
|
let mut empty_state = EMPTY_STATE;
|
||||||
interpret_program(&mut empty_state, 1000, 1000);
|
interpret_program(&mut empty_state, 1000, 1000);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user