[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 4275074 2/5: Ensure (length == maturity age -
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 4275074 2/5: Ensure (length == maturity age - issue age) for default ledger i12n |
Date: |
Sat, 6 Oct 2018 16:59:47 -0400 (EDT) |
branch: master
commit 4275074f1e0a023544260b69de8118f40ca7e510
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Ensure (length == maturity age - issue age) for default ledger i12n
---
ledger.cpp | 15 +++++++++++++++
ledger_invariant.cpp | 3 ++-
ledger_test.cpp | 6 ++++++
3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/ledger.cpp b/ledger.cpp
index 34beb93..d4f6be6 100644
--- a/ledger.cpp
+++ b/ledger.cpp
@@ -33,6 +33,7 @@
#include "map_lookup.hpp"
#include "mc_enum_types_aux.hpp" // mc_str()
#include "miscellany.hpp" // minmax, scale_power()
+#include "oecumenic_enumerations.hpp" // methuselah
#include <algorithm>
#include <ostream>
@@ -78,6 +79,20 @@ Ledger::Ledger
,ledger_invariant_ {new LedgerInvariant(length)}
{
SetRunBases(length);
+
+ if(is_composite_)
+ {
+ // By default, issue age is initialized to zero, and maturity
+ // age to 100, to accord with the default 'length' of 100.
+ // Both are reset to actual values when those become known.
+ // For a composite, however, they're updated thus:
+ // Age = std::min(Age , a_Addend.Age );
+ // EndtAge = std::max(EndtAge, a_Addend.EndtAge);
+ // as each addend is aggregated, so they must be initialized
+ // beforehand to values that would not otherwise make sense.
+ ledger_invariant_->Age = methuselah;
+ ledger_invariant_->EndtAge = 0;
+ }
}
//============================================================================
diff --git a/ledger_invariant.cpp b/ledger_invariant.cpp
index c20ba0e..26f542f 100644
--- a/ledger_invariant.cpp
+++ b/ledger_invariant.cpp
@@ -430,7 +430,8 @@ void LedgerInvariant::Init()
MecMonth = 11;
// TODO ?? Probably every member should be initialized.
- Age = 100;
+ Age = 0;
+ EndtAge = 100;
NoLapseMinDur = 100;
NoLapseMinAge = 100;
NoLapseAlwaysActive = false;
diff --git a/ledger_test.cpp b/ledger_test.cpp
index 43cbc7a..ed1b77e 100644
--- a/ledger_test.cpp
+++ b/ledger_test.cpp
@@ -52,6 +52,12 @@ void ledger_test::test_default_initialization()
BOOST_TEST_EQUAL(false , ledger.no_can_issue());
BOOST_TEST_EQUAL(false , ledger.is_composite());
BOOST_TEST_EQUAL(100 , ledger.greatest_lapse_dur());
+
+ LedgerInvariant const& invar = ledger.GetLedgerInvariant();
+
+ BOOST_TEST_EQUAL(100 , invar.GetLength());
+ BOOST_TEST_EQUAL(0 , invar.Age);
+ BOOST_TEST_EQUAL(100 , invar.EndtAge);
}
void ledger_test::test1()