Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions src/__tests__/correlation-validation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
import {expect} from 'chai';
import 'mocha';
import type {
CorrelationData
} from './test-data-loader';
import {
loadCorrelationData,
getDataByCorrelation,
getGMTCorrelationData,
getDirectSourceData,
findCorrelation,
getUniqueLongCounts,
getAvailableCorrelations,
CorrelationData
getAvailableCorrelations
} from './test-data-loader';
import LongCountFactory from '../factory/long-count';
import FullDateFactory from '../factory/full-date';
import {getCorrelationConstant} from '../lc/correlation-constant';

/**
* These tests validate Maya Long Count ↔ western date correlations using the JSON
* fixture data and the conversion factories. In particular, they exercise logic
* affected by the "winal radix correction" mentioned in the PR title.
*
* The winal radix correction refers to how 20‑day winals are handled when mapping
* Long Count positions to a fixed day count (JDN) and then to Gregorian/Julian
* calendar dates. Historically, small off‑by‑one errors in this radix handling
* can shift whole correlation constants by one or more days.
*
* By:
* - loading the canonical correlation dataset,
* - validating the GMT correlation constant (584285) against direct historical
* source entries, and
* - comparing western dates produced under neighboring correlation constants
* (e.g. 584283–584286),
* these tests ensure that the current implementation of the winal radix, and the
* resulting correlation constants, produce stable and internally consistent dates.
*/
describe('Maya Date Correlations from JSON Dataset', () => {

describe('Data Loading and Structure', () => {
Expand Down Expand Up @@ -117,7 +138,7 @@ describe('Maya Date Correlations from JSON Dataset', () => {
// Test that Calendar Round actually parses - this will fail if spellings don't match
const fullDateString = `${data.calendar_round} ${data.maya_long_count}`;
const fullDate = factory.parse(fullDateString);
expect(fullDate).to.not.be.null;
expect(fullDate).to.not.equal(null);
}
});
});
Expand All @@ -136,7 +157,7 @@ describe('Maya Date Correlations from JSON Dataset', () => {

it('should group correlations by event for historical analysis', () => {
const data = loadCorrelationData();
const eventGroups: { [event: string]: any[] } = {};
const eventGroups: Record<string, CorrelationData[]> = {};

data.data.forEach(item => {
if (!eventGroups[item.event]) {
Expand Down Expand Up @@ -198,12 +219,12 @@ describe('Maya Date Correlations from JSON Dataset', () => {
describe('Helper Function Tests', () => {
it('should filter data by correlation constant correctly', () => {
const gmtData = getDataByCorrelation(584285);
expect(gmtData.every(item => item.correlation_jdn === 584285)).to.be.true;
expect(gmtData.every(item => item.correlation_jdn === 584285)).to.equal(true);
});

it('should get GMT correlation data', () => {
const gmtData = getGMTCorrelationData();
expect(gmtData.every(item => item.correlation_jdn === 584285)).to.be.true;
expect(gmtData.every(item => item.correlation_jdn === 584285)).to.equal(true);
});

it('should find specific correlations', () => {
Expand All @@ -214,7 +235,7 @@ describe('Maya Date Correlations from JSON Dataset', () => {
correlation_jdn: 584285
});

expect(result).to.not.be.undefined;
expect(result).to.not.equal(undefined);
if (result) {
expect(result.maya_long_count).to.equal(firstLongCount);
expect(result.western_calendar).to.equal('gregorian');
Expand Down
11 changes: 5 additions & 6 deletions src/__tests__/full-date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'mocha'
import {expect} from 'chai'
import {
getGMTCorrelationData,
findCorrelation,
CorrelationData
} from "./test-data-loader";

Expand Down Expand Up @@ -68,9 +67,9 @@ it('isPartial should detect wildcards', () => {
const fd4 = new FullDateFactory().parse('4 Ajaw * Kumk\'u 9.17.0.0.*');

expect(fd1.isPartial()).to.be.false;
expect(fd2.isPartial()).to.be.true;
expect(fd3.isPartial()).to.be.true;
expect(fd4.isPartial()).to.be.true;
expect(fd2.isPartial()).to.equal(true);
expect(fd3.isPartial()).to.equal(true);
expect(fd4.isPartial()).to.equal(true);
});

describe('Historical Full Date Validation using JSON Dataset', () => {
Expand All @@ -86,7 +85,7 @@ describe('Historical Full Date Validation using JSON Dataset', () => {
// Parse should succeed - if it fails, the spellings don't match
const fullDate = new FullDateFactory().parse(fullDateString);

expect(fullDate).to.not.be.null;
expect(fullDate).to.not.equal(null);
// Compare Long Count string directly - normalize spacing
const actualLC = fullDate.lc.toString().trim().replace(/\s+/g, '.').replace(/\.+/g, '.');
expect(actualLC).to.equal(correlation.maya_long_count);
Expand All @@ -104,7 +103,7 @@ describe('Historical Full Date Validation using JSON Dataset', () => {
const lcString = correlation.maya_long_count;
const lc = new LongCountFactory().parse(lcString);

expect(lc).to.not.be.null;
expect(lc).to.not.equal(null);
// Normalize for comparison - the toString() adds spaces
const actualLC = lc.toString().trim().replace(/\s+/g, '.');
// Extract just the numeric parts for comparison
Expand Down
3 changes: 1 addition & 2 deletions src/__tests__/lc/western/western.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import GregorianFactory from "../../../factory/gregorian";
import {
getGMTCorrelationData,
getDirectSourceData,
findCorrelation,
CorrelationData
} from "../../test-data-loader";

Expand Down Expand Up @@ -132,7 +131,7 @@ describe('JSON Dataset Correlation Tests', () => {
const lc = lcFactory.parse(correlation.maya_long_count).setCorrelationConstant(corr);

// Validate the Long Count parses correctly
expect(lc).to.not.be.null;
expect(lc).to.not.equal(null);

// This is a basic test - you may need to adjust date format comparison
// based on how your library formats dates vs the JSON ISO format
Expand Down
Loading