generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Context - resolves #1 #4
Merged
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a35f41d
Import context from eosim
jasonasher 19f6e6f
Remove event emission and handle comments from review
jasonasher e24d5fc
Clean up main loop
ekr a814d82
Clean up even more
ekr ce2bb7e
Separate plan code from context
jasonasher b0b63f3
Rename plugin concept
jasonasher bf06af8
Add tests for plan queue and handle invalid cancellation
jasonasher f021aee
Refactor context tests so that they test individual behaviors.
ekr f2875b3
Format
ekr d4ca244
Fix the first clippy errors
ekr 8117ed7
Clippy fixes
ekr dd4a355
Fmt
ekr d78dfb7
Fix clippy
jasonasher d165d0e
Update data container code and handle pedantic clippy
jasonasher 8010a4d
Document plan code and split up tests
jasonasher 724667a
Add more docs
jasonasher 70a6bfb
Address comments from review and add tests
jasonasher 327c410
Modify test based on review
jasonasher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -15,10 +15,10 @@ use std::{ | |
|
||
/// A priority queue that stores arbitrary data sorted by time | ||
/// | ||
/// Items of type T are stored in order by `f64` time and called `Plan<T>`. | ||
/// Items of type `T` are stored in order by `f64` time and called `Plan<T>`. | ||
/// When plans are created they are sequentially assigned an `Id` that is a | ||
/// wrapped `u64`. If two plans are scheduled for the same time the plan that is | ||
/// scheduled first (i.e. that has the lowest id) is placed earlier. | ||
/// scheduled first (i.e., that has the lowest id) is placed earlier. | ||
/// | ||
/// The pair of time and plan id are stored in a binary heap of `Entry` objects. | ||
/// The data payload of the event is stored in a hash map by plan id. | ||
|
@@ -204,6 +204,29 @@ mod tests { | |
assert!(plan_queue.get_next_plan().is_none()); | ||
} | ||
|
||
#[test] | ||
fn add_and_get_plans() { | ||
let mut plan_queue = Queue::new(); | ||
plan_queue.add_plan(1.0, 1); | ||
plan_queue.add_plan(2.0, 2); | ||
|
||
let next_plan = plan_queue.get_next_plan().unwrap(); | ||
assert_eq!(next_plan.time, 1.0); | ||
assert_eq!(next_plan.data, 1); | ||
|
||
plan_queue.add_plan(3.0, 3); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would consider adding it with 1.5 to demonstrate that sort works properly. |
||
|
||
let next_plan = plan_queue.get_next_plan().unwrap(); | ||
assert_eq!(next_plan.time, 2.0); | ||
assert_eq!(next_plan.data, 2); | ||
|
||
let next_plan = plan_queue.get_next_plan().unwrap(); | ||
assert_eq!(next_plan.time, 3.0); | ||
assert_eq!(next_plan.data, 3); | ||
|
||
assert!(plan_queue.get_next_plan().is_none()); | ||
} | ||
|
||
#[test] | ||
#[should_panic] | ||
fn cancel_invalid_plan() { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are really thorough tests. This is approximately how I would do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I worked hard to get those right.