@nodots-llc/backgammon-ai
Version:
AI and integration for nodots-backgammon using gnubg as a backend engine.
47 lines (46 loc) • 2.78 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../index");
describe('getGnubgMoveHint', () => {
// This test is more of an integration test as it interacts with the file system and an external process (gnubg).
// It checks if the function can attempt a call to gnubg and get any response (success or failure).
it('should attempt to get a hint and either resolve with output or reject with an error', () => __awaiter(void 0, void 0, void 0, function* () {
const testPositionId = '4HPwATDgc/ABMA'; // A valid starting position ID
// We expect the promise to settle, meaning it either resolves or rejects.
// We don't know for sure if gnubg is installed and configured on the test environment,
// so we accept both outcomes as a sign of "communication attempt".
try {
const output = yield (0, index_1.getGnubgMoveHint)(testPositionId);
// If it resolves, we expect some string output.
expect(typeof output).toBe('string');
console.log('GNU BG call succeeded in test:', output.substring(0, 200) + '...');
}
catch (error) {
// If it rejects, we expect an Error object.
expect(error).toBeInstanceOf(Error);
console.warn('GNU BG call failed in test (as expected in some environments):', error);
}
}), 30000); // Increase timeout for external process call and file operations
});
describe('getBestMoveForStartingPosition', () => {
it('should return the best move for the standard starting position or throw an error', () => __awaiter(void 0, void 0, void 0, function* () {
try {
const bestMove = yield (0, index_1.getBestMoveForStartingPosition)();
expect(typeof bestMove).toBe('string');
console.log('Best move for starting position:', bestMove);
}
catch (error) {
expect(error).toBeInstanceOf(Error);
console.warn('Failed to get best move for starting position:', error);
}
}), 30000);
});