meta-log-db
Version:
Native database package for Meta-Log (ProLog, DataLog, R5RS)
385 lines • 16.3 kB
JavaScript
;
/**
* R5RS Polyhedra Function Tests
*
* Tests for R5RS polyhedra-specific functions:
* - type-to-cube-vertex
* - cube-vertex-to-type
* - r5rs-8-tuple
* - type-to-polyhedron
* - type-bqf
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const database_js_1 = require("../database.js");
const path = __importStar(require("path"));
(0, vitest_1.describe)('R5RS Polyhedra Functions', () => {
let db;
const r5rsEnginePath = path.join(__dirname, '../../../r5rs-canvas-engine.scm');
(0, vitest_1.beforeEach)(async () => {
db = new database_js_1.MetaLogDb({
r5rsEnginePath
});
// Load R5RS engine if available
try {
await db.loadR5RSEngine(r5rsEnginePath);
}
catch (error) {
// Engine might not be available in test environment
console.warn('R5RS engine not available for testing:', error);
}
});
(0, vitest_1.describe)('type-to-cube-vertex', () => {
(0, vitest_1.it)('should map boolean to vertex 0', async () => {
try {
const result = await db.executeR5RS('r5rs:type-to-cube-vertex', ['boolean']);
(0, vitest_1.expect)(result).toBe(0);
}
catch (error) {
// Function might not be available
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map pair to vertex 1', async () => {
try {
const result = await db.executeR5RS('r5rs:type-to-cube-vertex', ['pair']);
(0, vitest_1.expect)(result).toBe(1);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map symbol to vertex 2', async () => {
try {
const result = await db.executeR5RS('r5rs:type-to-cube-vertex', ['symbol']);
(0, vitest_1.expect)(result).toBe(2);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map number to vertex 3', async () => {
try {
const result = await db.executeR5RS('r5rs:type-to-cube-vertex', ['number']);
(0, vitest_1.expect)(result).toBe(3);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map char to vertex 4', async () => {
try {
const result = await db.executeR5RS('r5rs:type-to-cube-vertex', ['char']);
(0, vitest_1.expect)(result).toBe(4);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map string to vertex 5', async () => {
try {
const result = await db.executeR5RS('r5rs:type-to-cube-vertex', ['string']);
(0, vitest_1.expect)(result).toBe(5);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map vector to vertex 6', async () => {
try {
const result = await db.executeR5RS('r5rs:type-to-cube-vertex', ['vector']);
(0, vitest_1.expect)(result).toBe(6);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map procedure to vertex 7', async () => {
try {
const result = await db.executeR5RS('r5rs:type-to-cube-vertex', ['procedure']);
(0, vitest_1.expect)(result).toBe(7);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should return -1 for invalid type', async () => {
try {
const result = await db.executeR5RS('r5rs:type-to-cube-vertex', ['invalid-type']);
(0, vitest_1.expect)(result).toBe(-1);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
});
(0, vitest_1.describe)('cube-vertex-to-type', () => {
(0, vitest_1.it)('should map vertex 0 to boolean', async () => {
try {
const result = await db.executeR5RS('r5rs:cube-vertex-to-type', [0]);
(0, vitest_1.expect)(result).toBe('boolean');
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map vertex 1 to pair', async () => {
try {
const result = await db.executeR5RS('r5rs:cube-vertex-to-type', [1]);
(0, vitest_1.expect)(result).toBe('pair');
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map vertex 2 to symbol', async () => {
try {
const result = await db.executeR5RS('r5rs:cube-vertex-to-type', [2]);
(0, vitest_1.expect)(result).toBe('symbol');
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map vertex 3 to number', async () => {
try {
const result = await db.executeR5RS('r5rs:cube-vertex-to-type', [3]);
(0, vitest_1.expect)(result).toBe('number');
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map vertex 4 to char', async () => {
try {
const result = await db.executeR5RS('r5rs:cube-vertex-to-type', [4]);
(0, vitest_1.expect)(result).toBe('char');
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map vertex 5 to string', async () => {
try {
const result = await db.executeR5RS('r5rs:cube-vertex-to-type', [5]);
(0, vitest_1.expect)(result).toBe('string');
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map vertex 6 to vector', async () => {
try {
const result = await db.executeR5RS('r5rs:cube-vertex-to-type', [6]);
(0, vitest_1.expect)(result).toBe('vector');
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map vertex 7 to procedure', async () => {
try {
const result = await db.executeR5RS('r5rs:cube-vertex-to-type', [7]);
(0, vitest_1.expect)(result).toBe('procedure');
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should return false for invalid vertex', async () => {
try {
const result = await db.executeR5RS('r5rs:cube-vertex-to-type', [8]);
(0, vitest_1.expect)(result).toBe(false);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
});
(0, vitest_1.describe)('r5rs-8-tuple', () => {
(0, vitest_1.it)('should return all 8 R5RS types', async () => {
try {
const result = await db.executeR5RS('r5rs:r5rs-8-tuple', []);
(0, vitest_1.expect)(Array.isArray(result)).toBe(true);
(0, vitest_1.expect)(result).toHaveLength(8);
(0, vitest_1.expect)(result).toContain('boolean');
(0, vitest_1.expect)(result).toContain('pair');
(0, vitest_1.expect)(result).toContain('symbol');
(0, vitest_1.expect)(result).toContain('number');
(0, vitest_1.expect)(result).toContain('char');
(0, vitest_1.expect)(result).toContain('string');
(0, vitest_1.expect)(result).toContain('vector');
(0, vitest_1.expect)(result).toContain('procedure');
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
});
(0, vitest_1.describe)('type-to-polyhedron', () => {
(0, vitest_1.it)('should map boolean to point', async () => {
try {
const result = await db.executeR5RS('r5rs:type-to-polyhedron', ['boolean']);
(0, vitest_1.expect)(Array.isArray(result)).toBe(true);
(0, vitest_1.expect)(result[0]).toBe('point');
(0, vitest_1.expect)(Array.isArray(result[1])).toBe(true);
(0, vitest_1.expect)(result[1]).toEqual([1, 0, 0]);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map pair to tetrahedron', async () => {
try {
const result = await db.executeR5RS('r5rs:type-to-polyhedron', ['pair']);
(0, vitest_1.expect)(Array.isArray(result)).toBe(true);
(0, vitest_1.expect)(result[0]).toBe('tetrahedron');
(0, vitest_1.expect)(result[1]).toEqual([4, 6, 4]);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map string to cube', async () => {
try {
const result = await db.executeR5RS('r5rs:type-to-polyhedron', ['string']);
(0, vitest_1.expect)(Array.isArray(result)).toBe(true);
(0, vitest_1.expect)(result[0]).toBe('cube');
(0, vitest_1.expect)(result[1]).toEqual([8, 12, 6]);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map vector to octahedron', async () => {
try {
const result = await db.executeR5RS('r5rs:type-to-polyhedron', ['vector']);
(0, vitest_1.expect)(Array.isArray(result)).toBe(true);
(0, vitest_1.expect)(result[0]).toBe('octahedron');
(0, vitest_1.expect)(result[1]).toEqual([6, 12, 8]);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should map procedure to icosahedron', async () => {
try {
const result = await db.executeR5RS('r5rs:type-to-polyhedron', ['procedure']);
(0, vitest_1.expect)(Array.isArray(result)).toBe(true);
(0, vitest_1.expect)(result[0]).toBe('icosahedron');
(0, vitest_1.expect)(result[1]).toEqual([12, 30, 20]);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
});
(0, vitest_1.describe)('type-bqf', () => {
(0, vitest_1.it)('should return BQF for boolean type', async () => {
try {
const result = await db.executeR5RS('r5rs:type-bqf', ['boolean']);
(0, vitest_1.expect)(Array.isArray(result)).toBe(true);
(0, vitest_1.expect)(result).toHaveLength(3);
(0, vitest_1.expect)(result[0]).toBeGreaterThanOrEqual(0);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should return BQF for pair type', async () => {
try {
const result = await db.executeR5RS('r5rs:type-bqf', ['pair']);
(0, vitest_1.expect)(Array.isArray(result)).toBe(true);
(0, vitest_1.expect)(result).toEqual([4, 6, 4]);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should return BQF for string type', async () => {
try {
const result = await db.executeR5RS('r5rs:type-bqf', ['string']);
(0, vitest_1.expect)(Array.isArray(result)).toBe(true);
(0, vitest_1.expect)(result).toEqual([8, 12, 6]);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should return [0,0,0] for invalid type', async () => {
try {
const result = await db.executeR5RS('r5rs:type-bqf', ['invalid-type']);
(0, vitest_1.expect)(Array.isArray(result)).toBe(true);
(0, vitest_1.expect)(result).toEqual([0, 0, 0]);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
});
(0, vitest_1.describe)('integration tests', () => {
(0, vitest_1.it)('should map all 8 types to cube vertices correctly', async () => {
try {
const types = await db.executeR5RS('r5rs:r5rs-8-tuple', []);
(0, vitest_1.expect)(Array.isArray(types)).toBe(true);
for (let i = 0; i < types.length; i++) {
const type = types[i];
const vertex = await db.executeR5RS('r5rs:type-to-cube-vertex', [type]);
(0, vitest_1.expect)(vertex).toBe(i);
const backToType = await db.executeR5RS('r5rs:cube-vertex-to-type', [vertex]);
(0, vitest_1.expect)(backToType).toBe(type);
}
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
(0, vitest_1.it)('should maintain consistency between type-to-polyhedron and type-bqf', async () => {
try {
const type = 'pair';
const polyhedron = await db.executeR5RS('r5rs:type-to-polyhedron', [type]);
const bqf = await db.executeR5RS('r5rs:type-bqf', [type]);
(0, vitest_1.expect)(Array.isArray(polyhedron)).toBe(true);
(0, vitest_1.expect)(Array.isArray(bqf)).toBe(true);
(0, vitest_1.expect)(polyhedron[1]).toEqual(bqf);
}
catch (error) {
(0, vitest_1.expect)(error).toBeDefined();
}
});
});
});
//# sourceMappingURL=r5rs-polyhedra.test.js.map