TaUse11TermBoundary.sleela
lib/advantage/trading-actions-on-verb/11-term-boundary/TaUse11TermBoundary.sleela · 106 line(s) · sleela
<< lib/advantage/trading-actions-on-verb/11-term-boundary/TaUse11TermBoundary.sleela
SLeeLa trading-action use case.
Definition: Time on long, short term versus long term: a lot is long term only when held MORE than the threshold, so day 365 is still short. >>
#sleela 3.0
material;
artifact;
pure;
gasoline;
< Use case 11 (time). With a threshold of 365 days, a lot held 364 or 365 days is >
< short term and one held 366 is long term: the test is strictly greater. This >
< models day counts only. Real tax rules count calendar dates and differ by >
< country and year, so this is an illustration and not tax advice. >
class TaUse11TermBoundary {
< ---- 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 = 39311;
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 11: term boundary ==");
act(book, "buy 10 on day 0", book.buy(0, 10, 5000, 0));
expectTrue("day 364 is short term", !book.isLongTerm(0, 364, 365));
expectTrue("day 365 is still short term", !book.isLongTerm(0, 365, 365));
expectTrue("day 366 is long term", book.isLongTerm(0, 366, 365));
expect("long-term shares on day 365", book.qtyLongTerm(365, 365), 0);
expect("long-term shares on day 366", book.qtyLongTerm(366, 365), 10);
print("-- two lots straddling the line --");
act(book, "buy 20 on day 100", book.buy(100, 20, 5000, 0));
expect("long-term shares on day 464 (second lot is 364 days old)", book.qtyLongTerm(464, 365), 10);
expect("long-term shares on day 465 (second lot is 365 days old, still short)", book.qtyLongTerm(465, 365), 10);
expect("long-term shares on day 466 (second lot is 366 days old)", book.qtyLongTerm(466, 365), 30);
expect("long-term shares on day 465 with threshold 364", book.qtyLongTerm(465, 364), 30);
expectTrue("invariants hold", book.invariantsHold());
summary();
}
}