-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cde5a97
commit 77cb09e
Showing
8 changed files
with
217 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,3 +74,6 @@ impl FnOut for FnTripGe { | |
self.input.borrow_mut().reset(); | ||
} | ||
} | ||
/// | ||
/// | ||
impl FnInOut for FnTripGe {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
#![allow(non_snake_case)] | ||
#[cfg(test)] | ||
use log::{debug, info}; | ||
use std::{sync::Once, rc::Rc, cell::RefCell}; | ||
|
||
use crate::{ | ||
core_::{debug::debug_session::{DebugSession, LogLevel}, | ||
point::{point_type::PointType, point::Point}}, | ||
services::task::nested_function::{fn_::{FnInOut, FnOut}, | ||
fn_count::FnCount, fn_input::FnInput, metric_select::MetricSelect}, | ||
}; | ||
|
||
// Note this useful idiom: importing names from outer (for mod tests) scope. | ||
// use super::*; | ||
|
||
static INIT: Once = Once::new(); | ||
|
||
/// | ||
/// once called initialisation | ||
fn initOnce() { | ||
INIT.call_once(|| { | ||
// implement your initialisation code to be called only once for current test file | ||
} | ||
) | ||
} | ||
|
||
|
||
/// | ||
/// returns: | ||
/// - ... | ||
fn initEach(initial: PointType) -> Rc<RefCell<Box<dyn FnInOut>>> { | ||
fn boxFnInput(input: MetricSelect) -> Box<(dyn FnInOut)> { | ||
Box::new(input) | ||
} | ||
Rc::new(RefCell::new( | ||
boxFnInput( | ||
FnInput::new("test", initial) | ||
) | ||
)) | ||
} | ||
|
||
|
||
#[test] | ||
fn test_single() { | ||
DebugSession::init(LogLevel::Debug); | ||
initOnce(); | ||
info!("test_single"); | ||
let input = initEach(PointType::Bool(Point::newBool("bool", false))); | ||
let mut fnCount = FnCount::new( | ||
0, | ||
input.clone(), | ||
); | ||
let testData = vec![ | ||
(false, 0), | ||
(false, 0), | ||
(true, 1), | ||
(false, 1), | ||
(false, 1), | ||
(true, 2), | ||
(false, 2), | ||
(true, 3), | ||
(false, 3), | ||
(false, 3), | ||
(true, 4), | ||
(true, 4), | ||
(false, 4), | ||
(false, 4), | ||
]; | ||
for (value, targetState) in testData { | ||
let point = PointType::Bool(Point::newBool("test", value)); | ||
input.borrow_mut().add(point); | ||
// debug!("input: {:?}", &input); | ||
let state = fnCount.out(); | ||
// debug!("input: {:?}", &mut input); | ||
debug!("value: {:?} | state: {:?}", value, state); | ||
assert_eq!(state.asInt().value, targetState); | ||
} | ||
} | ||
// | ||
|
||
#[test] | ||
fn test_multiple() { | ||
DebugSession::init(LogLevel::Debug); | ||
initOnce(); | ||
info!("test_multiple"); | ||
let input = initEach(PointType::Bool(Point::newBool("bool", false))); | ||
let mut fnCount = FnCount::new( | ||
0, | ||
input.clone(), | ||
); | ||
let testData = vec![ | ||
(false, 0), | ||
(false, 0), | ||
(true, 1), | ||
(false, 1), | ||
(false, 1), | ||
(true, 2), | ||
(false, 2), | ||
(true, 3), | ||
(false, 3), | ||
(false, 3), | ||
(true, 4), | ||
(true, 4), | ||
(false, 4), | ||
(false, 4), | ||
]; | ||
for (value, targetState) in testData { | ||
let point = PointType::Bool(Point::newBool("test", value)); | ||
input.borrow_mut().add(point); | ||
// debug!("input: {:?}", &input); | ||
let state = fnCount.out(); | ||
// debug!("input: {:?}", &mut input); | ||
debug!("value: {:?} | state: {:?}", value, state); | ||
assert_eq!(state.asInt().value, targetState); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_multiple_reset() { | ||
DebugSession::init(LogLevel::Debug); | ||
initOnce(); | ||
info!("test_multiple_reset"); | ||
let input = initEach(PointType::Bool(Point::newBool("bool", false))); | ||
let mut fnCount = FnCount::new( | ||
0, | ||
input.clone(), | ||
); | ||
let testData = vec![ | ||
(false, 0, false), | ||
(false, 0, false), | ||
(true, 1, false), | ||
(false, 1, false), | ||
(false, 1, false), | ||
(true, 2, false), | ||
(false, 0, true), | ||
(true, 1, false), | ||
(false, 1, false), | ||
(false, 1, false), | ||
(true, 2, false), | ||
(true, 2, false), | ||
(false, 0, true), | ||
(false, 0, false), | ||
]; | ||
for (value, targetState, reset) in testData { | ||
if reset { | ||
fnCount.reset(); | ||
} | ||
let point = PointType::Bool(Point::newBool("test", value)); | ||
input.borrow_mut().add(point); | ||
// debug!("input: {:?}", &input); | ||
let state = fnCount.out(); | ||
// debug!("input: {:?}", &mut input); | ||
debug!("value: {:?} | state: {:?}", value, state); | ||
assert_eq!(state.asInt().value, targetState); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod metric_select_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod task_cycle_test; | ||
|
||
pub mod task_test; | ||
pub mod task_test; | ||
|
||
pub mod metric; |