88 lines
2.9 KiB
TypeScript
88 lines
2.9 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import * as path from 'node:path'
|
|
import { sync as exists } from "@polymech/fs/exists"
|
|
import {
|
|
getDefaultModels,
|
|
TEST_BASE_PATH,
|
|
TEST_LOGS_PATH,
|
|
TEST_PREFERENCES_PATH,
|
|
TEST_TIMEOUT,
|
|
TestResult,
|
|
runTest,
|
|
generateTestReport,
|
|
getReportPaths
|
|
} from './commons'
|
|
|
|
// Optionally override models for this specific test file
|
|
const models = getDefaultModels()
|
|
|
|
describe('Math Operations', () => {
|
|
let testResults: TestResult[] = []
|
|
const TEST_LOG_PATH = getReportPaths('math', 'json')
|
|
const TEST_REPORT_PATH = getReportPaths('math', 'md')
|
|
|
|
it.each(models)('should solve quadratic equation with model %s', async (modelName) => {
|
|
const result = await runTest(
|
|
'Solve the quadratic equation x² + 5x + 6 = 0. Return only the solutions as comma-separated numbers, no explanation.',
|
|
'-2,-3',
|
|
'quadratic',
|
|
modelName,
|
|
TEST_LOG_PATH
|
|
)
|
|
testResults.push(result)
|
|
expect(result.result[0]?.trim()?.toLowerCase()).toEqual('-2,-3')
|
|
}, { timeout: TEST_TIMEOUT })
|
|
|
|
it.each(models)('should calculate factorial with model %s', async (modelName) => {
|
|
const result = await runTest(
|
|
'Calculate 5! (factorial of 5). Return only the number, no explanation.',
|
|
'120',
|
|
'factorial',
|
|
modelName,
|
|
TEST_LOG_PATH
|
|
)
|
|
testResults.push(result)
|
|
expect(result.result[0]?.trim()?.toLowerCase()).toEqual('120')
|
|
}, { timeout: TEST_TIMEOUT })
|
|
|
|
it.each(models)('should calculate fibonacci sequence with model %s', async (modelName) => {
|
|
const result = await runTest(
|
|
'Calculate the 6th number in the Fibonacci sequence. Return only the number, no explanation.',
|
|
'8',
|
|
'fibonacci',
|
|
modelName,
|
|
TEST_LOG_PATH
|
|
)
|
|
testResults.push(result)
|
|
expect(result.result[0]?.trim()?.toLowerCase()).toEqual('8')
|
|
}, { timeout: TEST_TIMEOUT })
|
|
|
|
it.each(models)('should calculate square root with model %s', async (modelName) => {
|
|
const result = await runTest(
|
|
'Calculate the square root of 16. Return only the number, no explanation.',
|
|
'4',
|
|
'square_root',
|
|
modelName,
|
|
TEST_LOG_PATH
|
|
)
|
|
testResults.push(result)
|
|
expect(result.result[0]?.trim()?.toLowerCase()).toEqual('4')
|
|
}, { timeout: TEST_TIMEOUT })
|
|
|
|
it.each(models)('should calculate power with model %s', async (modelName) => {
|
|
const result = await runTest(
|
|
'Calculate 2 raised to the power of 3. Return only the number, no explanation.',
|
|
'8',
|
|
'power',
|
|
modelName,
|
|
TEST_LOG_PATH
|
|
)
|
|
testResults.push(result)
|
|
expect(result.result[0]?.trim()?.toLowerCase()).toEqual('8')
|
|
}, { timeout: TEST_TIMEOUT })
|
|
|
|
it('should generate markdown report', () => {
|
|
generateTestReport(testResults, 'Math Operations Test Results', TEST_REPORT_PATH)
|
|
expect(exists(TEST_REPORT_PATH) === 'file').toBe(true)
|
|
})
|
|
})
|