aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-12-29 16:17:39 +1100
committerTerry Truong <terry06890@gmail.com>2022-12-29 16:20:26 +1100
commit20d69469a4c80a196de23625d0420487b0ed04a6 (patch)
treee3a7aad153e72322c0810c66bda3b70daa8d815a /tests
parent4ad7206443660587a15a7b47384b927188155da8 (diff)
Show event-count data on timeline
Backend: Send event-count data to client in EventResponse instance Fix certain usages of gregorian calendar instead of julian Move HistDate, SCALES, etc, into cal.py Frontend: Make App update a unitCountMaps object using event-count data from server Make TimeLine show visual indication of unit counts Add showEventCounts option to store Update unit tests
Diffstat (limited to 'tests')
-rw-r--r--tests/lib.test.ts19
1 files changed, 17 insertions, 2 deletions
diff --git a/tests/lib.test.ts b/tests/lib.test.ts
index 9421ca1..85e17bc 100644
--- a/tests/lib.test.ts
+++ b/tests/lib.test.ts
@@ -1,8 +1,8 @@
import {moduloPositive,
gregorianToJdn, julianToJdn, jdnToGregorian, jdnToJulian, gregorianToJulian, julianToGregorian, getDaysInMonth,
- HistDate, YearDate, CalDate,
+ HistDate, YearDate, CalDate, HistEvent,
queryServer, jsonToHistDate, jsonToHistEvent,
- DAY_SCALE, MONTH_SCALE, stepDate, inDateScale, getScaleRatio, getUnitDiff,
+ DAY_SCALE, MONTH_SCALE, stepDate, inDateScale, getScaleRatio, getUnitDiff, getEventPrecision, dateToUnit,
DateRangeTree,
} from '/src/lib.ts'
@@ -142,6 +142,21 @@ test('getUnitDiff', () => {
expect(getUnitDiff(new CalDate(-1, 1, 10), (new CalDate(10, 11, 2)), 1)).toBe(10)
expect(getUnitDiff(new YearDate(-5000), (new YearDate(-6500)), 10)).toBe(150)
})
+test('getEventPrecision', () => {
+ expect(getEventPrecision(new HistEvent(1, 'one', new YearDate(-5000), new YearDate(-4991)))).toBe(10)
+ expect(getEventPrecision(new HistEvent(1, 'one', new YearDate(-5000), new YearDate(-4990)))).toBe(100)
+ expect(getEventPrecision(new HistEvent(1, 'one', new CalDate(2000, 1, 1), new CalDate(2150, 1, 1)))).toBe(1000)
+ expect(getEventPrecision(new HistEvent(1, 'one', new CalDate(1, 2, 3), new CalDate(1, 2, 25)))).toBe(MONTH_SCALE)
+ expect(getEventPrecision(new HistEvent(1, 'one', new CalDate(1, 2, 3), new CalDate(1, 2, 3)))).toBe(DAY_SCALE)
+})
+test('dateToUnit', () => {
+ expect(dateToUnit(new CalDate(2013), 1e3)).toBe(2)
+ expect(dateToUnit(new CalDate(2013), 100)).toBe(20)
+ expect(dateToUnit(new CalDate(2013), 1)).toBe(2013)
+ expect(dateToUnit(new YearDate(-5123), 10)).toBe(-513)
+ expect(dateToUnit(new CalDate(1911, 12, 3), MONTH_SCALE)).toBe(gregorianToJdn(1911, 12, 1))
+ expect(dateToUnit(new CalDate(1911, 12, 3, false), DAY_SCALE)).toBe(julianToJdn(1911, 12, 3))
+})
test('DateRangeTree', () => {
let ranges = new DateRangeTree()