TaUse08HoldingDays.sleela
lib/advantage/trading-actions-on-verb/08-holding-days/TaUse08HoldingDays.sleela · 112 line(s) · sleela
<< lib/advantage/trading-actions-on-verb/08-holding-days/TaUse08HoldingDays.sleela
SLeeLa trading-action use case.
Definition: Time on long, age: a lot's age is today minus its buy day; time may pass with hold but never run backwards. >>
#sleela 3.0
material;
artifact;
pure;
gasoline;
< Use case 8 (time). A lot bought on day 10 is 15 days old on day 25. The hold >
< verb lets time pass with no trade. Time never goes backwards: hold to an >
< earlier day is refused (code 5) and leaves the book day alone. A flat book >
< has no oldest lot (-1). >
class TaUse08HoldingDays {
< ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
<< Eleven catalogued attributes with getter/setter pairs. A worker-class
lesson carries the baseline identity record. >>
String metaVersion = "1.0.0";
int metaId = 39308;
String metaAuthor = "Kiro Agent";
String metaDate = "2026-11-11";
String metaCopyright = "SLeeLa project";
String metaTrademark = "none";
String metaCorporation = "none";
< metaOrigin: National | <nation> | International | Galactic >
String metaOrigin = "International";
String metaBirthDate = "2026-11-11";
< metaScienceRating: maturity/robustness on a 1..10 scale >
int metaScienceRating = 5;
< metaNationalSchedule: a real, citable instrument or "none" >
String metaNationalSchedule = "none";
String getMetaVersion() { return metaVersion; }
void setMetaVersion(String v) { metaVersion = v; }
int getMetaId() { return metaId; }
void setMetaId(int v) { metaId = v; }
String getAuthor() { return metaAuthor; }
void setAuthor(String v) { metaAuthor = v; }
String getDate() { return metaDate; }
void setDate(String v) { metaDate = v; }
String getCopyright() { return metaCopyright; }
void setCopyright(String v) { metaCopyright = v; }
String getTrademark() { return metaTrademark; }
void setTrademark(String v) { metaTrademark = v; }
String getCorporation() { return metaCorporation; }
void setCorporation(String v) { metaCorporation = v; }
String getOrigin() { return metaOrigin; }
void setOrigin(String v) { metaOrigin = v; }
String getBirthDate() { return metaBirthDate; }
void setBirthDate(String v) { metaBirthDate = v; }
int getScienceRating() { return metaScienceRating; }
void setScienceRating(int v) { metaScienceRating = v; }
String getNationalSchedule() { return metaNationalSchedule; }
void setNationalSchedule(String v) { metaNationalSchedule = v; }
int passed = 0;
int failed = 0;
void expect(String label, int got, int want) {
if (got == want) {
print(" ok " + label + " = " + got);
passed = passed + 1;
} else {
print(" FAIL " + label + " got " + got + " want " + want);
failed = failed + 1;
}
}
void expectTrue(String label, boolean got) {
if (got) {
print(" ok " + label);
passed = passed + 1;
} else {
print(" FAIL " + label);
failed = failed + 1;
}
}
void summary() {
print(" checks passed=" + passed + " failed=" + failed);
}
void act(SLLongBook b, String text, int code) {
print(" " + text + " : " + b.reason(code));
}
void main() {
SLLongBook book = new SLLongBook();
print("== Use case 8: holding days ==");
act(book, "buy 100 @ 5000 on day 10", book.buy(10, 100, 5000, 0));
expect("age on day 10", book.ageOf(0, 10), 0);
act(book, "hold to day 25", book.hold(25));
expect("age on day 25", book.ageOf(0, 25), 15);
expect("book day", book.currentDay(), 25);
act(book, "hold back to day 20", book.hold(20));
expect("book day unchanged by the refusal", book.currentDay(), 25);
act(book, "hold to day 40", book.hold(40));
expect("oldest age on day 40", book.oldestAge(40), 30);
print("-- a day before the book day has no answer, never a negative age --");
expect("age asked for day 30 (book day is 40)", book.ageOf(0, 30), 0 - 1);
expect("oldest age asked for day 30", book.oldestAge(30), 0 - 1);
expect("weighted age asked for day 30", book.weightedAgeFloor(30), 0 - 1);
expect("shares older than 5 days asked for day 30", book.qtyOlderThan(30, 5), 0 - 1);
expectTrue("isLongTerm is false for an invalid day", !book.isLongTerm(0, 30, 5));
act(book, "flatten on day 40 @ 5100", book.flatten(40, 5100, 0));
expect("oldest age when flat", book.oldestAge(40), 0 - 1);
expect("weighted age when flat", book.weightedAgeFloor(40), 0);
expectTrue("invariants hold", book.invariantsHold());
summary();
}
}