[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 15f8d03 3/8: Assert all post-construction inv
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 15f8d03 3/8: Assert all post-construction invariants in a single function |
Date: |
Thu, 23 Feb 2017 05:29:07 -0500 (EST) |
branch: master
commit 15f8d03ccad613bafcf4b226e54fbf3ce52ff6a0
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Assert all post-construction invariants in a single function
---
input_sequence.cpp | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/input_sequence.cpp b/input_sequence.cpp
index 58db80b..30e51dd 100644
--- a/input_sequence.cpp
+++ b/input_sequence.cpp
@@ -431,6 +431,14 @@ void assert_not_insane_or_disordered
}
}
+/// Assert postconditions established by all ctors.
+///
+/// What is actually asserted here, for now at least, is only that the
+/// intervals are contiguous--not that they truly partition the range
+/// [0, years_to_maturity). Cf. fill_interval_gaps(), which similarly
+/// establishes only this weaker invariant, which also happens to be
+/// what InputSequenceEntry asserts.
+
void assert_sane_and_ordered_partition
(std::vector<ValueInterval> const& intervals
,int years_to_maturity
@@ -445,6 +453,24 @@ void assert_sane_and_ordered_partition
LMI_ASSERT(years_to_maturity == intervals.back().end_duration);
LMI_ASSERT(e_maturity == intervals.back().end_mode );
+
+ int prior_end_duration = 0;
+ for(auto const& i : intervals)
+ {
+ if(i.begin_duration != prior_end_duration)
+ {
+ fatal_error()
+ << "Interval "
+ << "[ " << i.begin_duration << ", "
+ << i.end_duration << " )"
+ << " should begin at duration "
+ << prior_end_duration
+ << ", where the previous interval ended."
+ << LMI_FLUSH
+ ;
+ }
+ prior_end_duration = i.end_duration;
+ }
}
/// Create a partition of [0, maturity) from parser output.
- [lmi-commits] [lmi] master updated (d7c4f5d -> 5753253), Greg Chicares, 2017/02/23
- [lmi-commits] [lmi] master eff49eb 1/8: Assert more invariants, Greg Chicares, 2017/02/23
- [lmi-commits] [lmi] master 15f8d03 3/8: Assert all post-construction invariants in a single function,
Greg Chicares <=
- [lmi-commits] [lmi] master 2f6ea66 6/8: Demonstrate a simplification opportunity, Greg Chicares, 2017/02/23
- [lmi-commits] [lmi] master 3dc9aee 2/8: Refactor to prepare for improvements, Greg Chicares, 2017/02/23
- [lmi-commits] [lmi] master 3a73c40 4/8: Protect known (temporary) weak points with assertions, Greg Chicares, 2017/02/23
- [lmi-commits] [lmi] master 5753253 8/8: Simplify realize_intervals(), Greg Chicares, 2017/02/23
- [lmi-commits] [lmi] master 132e2ac 7/8: Simplify: only one ctor needs to call realize_intervals(), Greg Chicares, 2017/02/23
- [lmi-commits] [lmi] master 1cfefc0 5/8: Assert post-construction invariants at end of each ctor, Greg Chicares, 2017/02/23