<commit_before>import { Selection, reduceSelection } from "src";

describe("reduceSelection()", () => {
    it("should reduce { foo: true, bar: true } by { foo: true } to create { bar: true }", () => {
        // arrange
        const a: Selection = { foo: true, bar: true };
        const b: Selection = { foo: true };

        // act
        const reduced = reduceSelection(a, b);

        // assert
        expect(reduced).toEqual({ bar: true });
    });

    it("should reduce { foo: true, bar: true } by { foo: true, bar: true } to create null", () => {
        // arrange
        const a: Selection = { foo: true, bar: true };
        const b: Selection = { foo: true, bar: true };

        // act
        const reduced = reduceSelection(a, b);

        // assert
        expect(reduced).toBeNull();
    });

    it("should not reduce { foo: true, bar: true } by { baz: true } and return same reference", () => {
        // arrange
        const a: Selection = { foo: true, bar: true };
        const b: Selection = { baz: true };

        // act
        const reduced = reduceSelection(a, b);

        // assert
        expect(reduced).toBe(a);
    });

    it("should reduce { foo: { bar: true, baz: true }, khaz: { mo: true } } by { foo: { bar: true }, khaz: { mo: true, dan: true } } to create { foo: { baz: true } }", () => {
        // arrange
        const a: Selection = { foo: { bar: true, baz: true }, khaz: { mo: true } };
        const b: Selection = { foo: { bar: true }, khaz: { mo: true, dan: true } };

        // act
        const reduced = reduceSelection(a, b);

        // assert
        expect(reduced).toEqual({ foo: { baz: true } });
    });

    it("{ foo: {} } reduced by { foo: {} } should be null", () => {
        // arrange
        const a: Selection = { foo: {} };
        const b: Selection = { foo: {} };

        // act
        const reduced = reduceSelection(a, b);

        // assert
        expect(reduced).toBeNull();
    });
});<commit_msg>health(selection): improve reduceSelection() spec readability<commit_after>import { Selection, reduceSelection } from "src";

fdescribe("reduceSelection()", () => {
    describe("full reduction", () => {
        it("{ foo, bar } should be completely reduced by { foo, bar }", () => {
            // arrange
            const a: Selection = { foo: {}, bar: true };
            const b: Selection = { foo: true, bar: {} };

            // act
            const reduced = reduceSelection(a, b);

            // assert
            expect(reduced).toBeNull();
        });
    });

    describe("partial reduction", () => {
        it("{ foo, bar } reduced by { foo } should be { bar }", () => {
            // arrange
            const a: Selection = { foo: true, bar: true };
            const b: Selection = { foo: true };

            // act
            const reduced = reduceSelection(a, b);

            // assert
            expect(reduced).toEqual({ bar: true });
        });

        it("{ foo: { bar, baz }, khaz: { mo } } reduced by { foo: { bar }, khaz: { mo, dan } } should be { foo: { baz } }", () => {
            // arrange
            const a: Selection = { foo: { bar: true, baz: true }, khaz: { mo: true } };
            const b: Selection = { foo: { bar: true }, khaz: { mo: true, dan: true } };

            // act
            const reduced = reduceSelection(a, b);

            // assert
            expect(reduced).toEqual({ foo: { baz: true } });
        });
    });

    describe("no reduction", () => {
        it("{ foo, bar } should not be reduced by { baz }", () => {
            // arrange
            const a: Selection = { foo: true, bar: true };
            const b: Selection = { baz: true };

            // act
            const reduced = reduceSelection(a, b);

            // assert
            expect(reduced).toBe(a);
        });
    });
});
{'fraction_non_alphanumeric': 0.16895568800207308, 'fraction_numerical': 0.0, 'mean_word_length': 1.7183098591549295, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4720308', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1084, 'n_words': 348}