Adding additional checks for tasks and interval generation
This commit is contained in:
parent
cea5dfc8d4
commit
4ba2a3aa26
@@ -13,7 +13,14 @@ impl ResourceInterval {
|
|||||||
ResourceInterval(HashMap::new())
|
ResourceInterval(HashMap::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(&mut self, other: ResourceInterval) {
|
pub fn insert(&mut self, resource: &Resource, intervals: &IntervalSet) {
|
||||||
|
self.0
|
||||||
|
.entry(resource.clone())
|
||||||
|
.or_insert(IntervalSet::new())
|
||||||
|
.merge(intervals);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn union(&mut self, other: ResourceInterval) {
|
||||||
for (res, is) in other.iter() {
|
for (res, is) in other.iter() {
|
||||||
self.0
|
self.0
|
||||||
.entry(res.clone())
|
.entry(res.clone())
|
||||||
@@ -22,7 +29,7 @@ impl ResourceInterval {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(&mut self, other: ResourceInterval) {
|
pub fn subtract(&mut self, other: ResourceInterval) {
|
||||||
for (res, is) in other.iter() {
|
for (res, is) in other.iter() {
|
||||||
let avail = self.0.entry(res.clone()).or_insert(IntervalSet::new());
|
let avail = self.0.entry(res.clone()).or_insert(IntervalSet::new());
|
||||||
*avail = avail.difference(is);
|
*avail = avail.difference(is);
|
||||||
|
|||||||
+9
-1
@@ -68,7 +68,7 @@ impl TaskDefinition {
|
|||||||
requires: self.requires.clone(),
|
requires: self.requires.clone(),
|
||||||
|
|
||||||
schedule: schedule,
|
schedule: schedule,
|
||||||
valid_over: IntervalSet::from(vec![Interval::new(start, actual_end)]),
|
valid_over: IntervalSet::from(Interval::new(start, actual_end)),
|
||||||
timezone: self.timezone,
|
timezone: self.timezone,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -293,5 +293,13 @@ mod tests {
|
|||||||
panic!("{:?}", e);
|
panic!("{:?}", e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Ensure that the intervals generated over the valid period
|
||||||
|
// exactly cover the valid period
|
||||||
|
let mut theoretical = ResourceInterval::new();
|
||||||
|
theoretical.insert(&"resource_a".to_owned(), &task.valid_over);
|
||||||
|
theoretical.insert(&"resource_b".to_owned(), &task.valid_over);
|
||||||
|
let generated = IntervalSet::from(task.generate_intervals(&theoretical).unwrap());
|
||||||
|
assert_eq!(task.valid_over, generated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user