ConceptPortal-public/rsconcept/frontend/src/models/rslangAPI.test.ts

50 lines
1.7 KiB
TypeScript
Raw Normal View History

import { extractGlobals, isSimpleExpression, splitTemplateDefinition } from './rslangAPI';
const globalsData = [
['', ''],
['X1', 'X1'],
['X11 X1 X11', 'X11 X1'],
2023-12-28 14:04:44 +03:00
['∀α∈S1 ∀β∈F1[α] Pr1,1(β)∩β=∅', 'S1 F1']
];
describe('Testing extract globals', () => {
2023-12-28 14:04:44 +03:00
it.each(globalsData)('Extract globals %p', (input: string, expected: string) => {
const result = extractGlobals(input);
expect([...result].join(' ')).toBe(expected);
});
});
const simpleExpressionData = [
['', 'true'],
['Pr1(S1)', 'true'],
['pr1(S1)', 'true'],
['red(S1)', 'true'],
['red(Pr1(F1[α,σ]))', 'true'],
2024-04-05 20:04:12 +03:00
['(X1)', 'false'],
['(X1)', 'false'],
['D{(α,β)∈D6×D6 | α≠β & α∩β≠∅}', 'false'],
2024-04-05 22:36:20 +03:00
['D{ξ ∈ X1 | (ξ,ξ)∈S1 }', 'false'],
['I{(β,α) | α:∈D2; σ:=F5[α]; β:∈σ}', 'false'],
['∀σ∈S1 (F1[σ]×F1[σ])∩D11=∅', 'false']
];
describe('Testing simple expression', () => {
it.each(simpleExpressionData)('isSimpleExpression %p', (input: string, expected: string) => {
const result = isSimpleExpression(input);
expect(String(result)).toBe(expected);
});
});
const splitData = [
['', '||'],
['[α∈ℬ(R1)] α⊆red(σ)', 'α∈ℬ(R1)||α⊆red(σ)'],
['[α∈ℬ(R1)] α⊆red(σ) ', 'α∈ℬ(R1)||α⊆red(σ)'],
[' [α∈ℬ(R1)] α⊆red(σ)', 'α∈ℬ(R1)||α⊆red(σ)'],
['[α∈ℬ(R1)]α⊆red(σ)', 'α∈ℬ(R1)||α⊆red(σ)'],
2023-12-28 14:04:44 +03:00
['[α∈ℬ(R1), σ∈ℬℬ(R1)] α⊆red(σ)', 'α∈ℬ(R1), σ∈ℬℬ(R1)||α⊆red(σ)']
];
describe('Testing split template', () => {
2023-12-28 14:04:44 +03:00
it.each(splitData)('Split %p', (input: string, expected: string) => {
const result = splitTemplateDefinition(input);
expect(`${result.head}||${result.body}`).toBe(expected);
});
2023-12-28 14:04:44 +03:00
});