86 lines
3.4 KiB
JavaScript
86 lines
3.4 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
assessComparability,
|
|
formulateTieResolutionQuestion,
|
|
} from "@/lib/graph/question-formulator.js";
|
|
import { explainUnknownSelection } from "@/lib/graph/utils.js";
|
|
import { comparabilityAssessmentFixtures } from "@/tests/fixtures/comparability-assessment.js";
|
|
|
|
describe("comparability assessment", () => {
|
|
it("generates comparison questions only when comparability is uncertain", () => {
|
|
const summary = comparabilityAssessmentFixtures.map((fixture) => {
|
|
const assessment = assessComparability(fixture.graph);
|
|
const question = formulateTieResolutionQuestion({ graph: fixture.graph });
|
|
const ambiguity = explainUnknownSelection(fixture.graph, []);
|
|
|
|
expect(assessment.comparabilityStatus).toBe(
|
|
fixture.expectedComparabilityStatus,
|
|
);
|
|
expect(question.comparabilityStatus).toBe(
|
|
fixture.expectedComparabilityStatus,
|
|
);
|
|
|
|
if (fixture.expectsComparisonQuestion) {
|
|
expect(question.question.toLowerCase()).toContain("same");
|
|
expect(question.contradictionReasoningAllowed).toBe(false);
|
|
} else {
|
|
expect(question.question.toLowerCase()).not.toContain(
|
|
"same period and at the same scale",
|
|
);
|
|
}
|
|
|
|
if (fixture.key !== "sales-same") {
|
|
expect(ambiguity.status).toBe("ambiguous");
|
|
}
|
|
|
|
return {
|
|
scenario: fixture.scenario,
|
|
comparabilityStatus: assessment.comparabilityStatus,
|
|
contradictionReasoningAllowed: assessment.contradictionReasoningAllowed,
|
|
question: question.question,
|
|
};
|
|
});
|
|
|
|
expect(summary).toMatchInlineSnapshot(`
|
|
[
|
|
{
|
|
"comparabilityStatus": "uncertain",
|
|
"contradictionReasoningAllowed": false,
|
|
"question": "Were these figures measured on the same basis and at the same scale?",
|
|
"scenario": "Revenue increased by 18%, but cash in the bank fell over the same period.",
|
|
},
|
|
{
|
|
"comparabilityStatus": "uncertain",
|
|
"contradictionReasoningAllowed": false,
|
|
"question": "Were these figures measured over the same period and at the same scale?",
|
|
"scenario": "Complaints increased. Production increased.",
|
|
},
|
|
{
|
|
"comparabilityStatus": "uncertain",
|
|
"contradictionReasoningAllowed": false,
|
|
"question": "Were these figures measured over the same period and at the same scale?",
|
|
"scenario": "Average delivery time decreased by 25%, but order cancellations increased.",
|
|
},
|
|
{
|
|
"comparabilityStatus": "uncertain",
|
|
"contradictionReasoningAllowed": false,
|
|
"question": "Were these figures measured over the same period and at the same scale?",
|
|
"scenario": "Customer satisfaction increased, but complaints increased.",
|
|
},
|
|
{
|
|
"comparabilityStatus": "confirmed",
|
|
"contradictionReasoningAllowed": true,
|
|
"question": "What changed during the period that could explain why Temperature increased. Ice melted?",
|
|
"scenario": "Temperature increased. Ice melted.",
|
|
},
|
|
{
|
|
"comparabilityStatus": "confirmed",
|
|
"contradictionReasoningAllowed": false,
|
|
"question": "What changed during the period that could explain why Sales doubled. Sales doubled?",
|
|
"scenario": "Sales doubled. Sales doubled.",
|
|
},
|
|
]
|
|
`);
|
|
});
|
|
});
|