# test.govlab/context/core/predicates/algorithm.predicate.test.ts

> 19 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-govlab-context-core-predicates-algorithm-predicate-test-ts
Source text: https://banes-lab.com/source/testing/test.govlab/context/core/predicates/algorithm.predicate.test.ts.txt

Listed in [test.govlab/context/core/predicates](https://banes-lab.com/api/source/testing/test.govlab/context/core/predicates.md), before [test.govlab/context/core/predicates/check.predicate.test.ts](https://banes-lab.com/source/testing/test.govlab/context/core/predicates/check.predicate.test.ts.md).

## Contained in

- [test.govlab/context/core/predicates](https://banes-lab.com/anatomy/testing/folder-testing-test-govlab-context-core-predicates.md)

## Source

```typescript
import assert from "node:assert/strict";
import { buildSymbolIndex } from "@govlab/context";
import { symbolIndexesMatch } from "@govlab/context/core/predicates/algorithm.predicate.ts";
import { test } from "vitest";

test("symbolIndexesMatch holds for two indexes built from the same input", () => {
    const contracts = [
        { domain: "g", id: "r1", productions: [{ lhs: "A", rhs: "<x>" }] },
        { domain: "g", id: "r2", productions: [{ lhs: "B", rhs: '"y" | "z"' }] },
    ];
    assert.equal(symbolIndexesMatch(buildSymbolIndex(contracts), buildSymbolIndex(contracts)), true);
});

test("symbolIndexesMatch fails on a changed copy of the index", () => {
    const index = buildSymbolIndex([{ domain: "g", id: "r1", productions: [{ lhs: "A", rhs: "<x>" }] }]);
    const changed = index.map((entry, position) => (position === 0 ? { ...entry, name: "Changed" } : entry));
    assert.equal(symbolIndexesMatch(index, changed), false);
});

test("symbolIndexesMatch treats two empty indexes as equal", () => {
    assert.equal(symbolIndexesMatch([], []), true);
});
```
