<commit_before>jest.dontMock("../index");

var atom = require('../index');

describe("atom", function(){
    describe("'deref'", function(){
        it("returns the current value of the atom", function(){
            var value = 42,
                at = atom.atom(value);

            expect(at.deref()).toBe(value, "The atom should have the value which it was created with");
        });
    });

    describe("'reset'", function(){
        it("changes the current value of the atom", function(){
            var oldValue = 42,
                newValue = 43,
                at = atom.atom(oldValue);

            expect(at.reset(newValue)).toBe(newValue, "The reset method should return the new value of the atom");
            expect(at.deref()).toBe(newValue, "The atom should have the value which was given when calling reset");
        });
    });

    describe("'swap'", function(){
        it("applies the function to the current value updating it", function(){
            var oldValue = 42,
                inc = function(x) { return x + 1; },
                expectedNewValue = 43,
                at = atom.atom(oldValue);

            expect(at.swap(inc)).toBe(expectedNewValue, "The swap method should return the new value of the atom");
            expect(at.deref()).toBe(expectedNewValue, "The atom should have the value resulting of applying the function given to swap");
        });
    });

    describe("validation", function(){
        // TODO
    });
<commit_msg>validation tests<commit_after>jest.dontMock("../index");

var atom = require('../index');

describe("atom", function(){
    describe("'deref'", function(){
        it("returns the current value of the atom", function(){
            var value = 42,
                at = atom.atom(value);

            expect(at.deref()).toBe(value, "The atom should have the value which it was created with");
        });
    });

    describe("'reset'", function(){
        it("changes the current value of the atom", function(){
            var oldValue = 42,
                newValue = 43,
                at = atom.atom(oldValue);

            expect(at.reset(newValue)).toBe(newValue, "The reset method should return the new value of the atom");
            expect(at.deref()).toBe(newValue, "The atom should have the value which was given when calling reset");
        });
    });

    describe("'swap'", function(){
        it("applies the function to the current value updating it", function(){
            var oldValue = 42,
                inc = function(x) { return x + 1; },
                expectedNewValue = 43,
                at = atom.atom(oldValue);

            expect(at.swap(inc)).toBe(expectedNewValue, "The swap method should return the new value of the atom");
            expect(at.deref()).toBe(expectedNewValue, "The atom should have the value resulting of applying the function given to swap");
        });
    });

    describe("validation", function(){
        it("trying to create an atom with an invalid value is not allowed", function(){
            var invalidValue = 43,
                validator = function(v) { return v === 42; };

            expect(function(){
                atom.atom(invalidValue, {validator: validator});
            }).toThrow();
            expect(function(){
                atom.atom(42, {validator: validator});
            }).not.toThrow();
        });

        it("trying to swap to a invalid value is not allowed", function(){
            var inc = function(x) { return x + 1; },
                validator = function(v) { return v === 42; },
                at = atom.atom(42, {validator: validator});

            expect(function(){
                at.swap(inc);
            }).toThrow();
            expect(function(){
                at.swap(function(x) { return x; });
            }).not.toThrow();
        });

        it("trying to reset a invalid value is not allowed", function(){
            var validator = function(v) { return v === 42; },
                at = atom.atom(42, {validator: validator});

            expect(function(){
                at.reset(43);
            }).toThrow();
            expect(function(){
                at.reset(42);
            }).not.toThrow();
        });
    });

{'fraction_non_alphanumeric': 0.13754121526142252, 'fraction_numerical': 0.009656146961846444, 'mean_word_length': 1.959581881533101, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '475387', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1062, 'n_words': 349}