<commit_before>var assert = require('chai').assert
  , statem = require('./../lib/statem');

describe('statem', function () {

  describe('two states, one transition', function () {

    function checkit () {

      it('begins in state A', function () {
        assert.strictEqual(this.machine.state(), 'A');
      });

      describe('on poke', function () {

        beforeEach(function () {
          this.machine.send('poke');
        });

        it('transitions to state B', function () {
          assert.strictEqual(this.machine.state(), 'B');
        });

        describe('on a second poke', function () {

          beforeEach(function () {
            this.machine.send('poke');
          });

          it('transitions back to state A', function () {
            assert.strictEqual(this.machine.state(), 'A');
          });

        });

      });
    }

    describe('with state definition', function () {

      beforeEach(function () {
        this.definition = {
          initial: 'A'
        , states: {
            A: { poke: 'B' }
          , B: { poke: 'A' }
          }
        };
        this.machine = statem.machine(this.definition);
      });

      checkit();

    });

    describe('with event definition', function () {

      beforeEach(function () {
        this.definition = {
          initial: 'A'
        , events: {
            poke: { A: 'B', B: 'A' }
          }
        };
        this.machine = statem.machine(this.definition);
      });

      checkit();

    });

  });

});<commit_msg>Adds slightly more complex functional testing<commit_after>var assert = require('chai').assert
  , statem = require('./../lib/statem');

describe('statem', function () {

  describe('two states, one event', function () {

    function checkit () {

      it('begins in state A', function () {
        assert.strictEqual(this.machine.state(), 'A');
      });

      describe('on poke', function () {

        beforeEach(function () {
          this.machine.send('poke');
        });

        it('transitions to state B', function () {
          assert.strictEqual(this.machine.state(), 'B');
        });

        describe('on a second poke', function () {

          beforeEach(function () {
            this.machine.send('poke');
          });

          it('transitions back to state A', function () {
            assert.strictEqual(this.machine.state(), 'A');
          });

        });

      });
    }

    describe('with state definition', function () {

      beforeEach(function () {
        this.definition = {
          initial: 'A'
        , states: {
            A: { poke: 'B' }
          , B: { poke: 'A' }
          }
        };
        this.machine = statem.machine(this.definition);
      });

      checkit();

    });

    describe('with event definition', function () {

      beforeEach(function () {
        this.definition = {
          initial: 'A'
        , events: {
            poke: { A: 'B', B: 'A' }
          }
        };
        this.machine = statem.machine(this.definition);
      });

      checkit();

    });

  });

  describe('three states, two events', function () {

    function checkit() {

      it('begins in state A', function () {
        assert.strictEqual(this.machine.state(), 'A');
      });

      describe('on poke', function () {

        beforeEach(function () {
          this.machine.send('poke');
        });

        it('transitions to state B', function () {
          assert.strictEqual(this.machine.state(), 'B');
        });

      });

      describe('on poke|poke', function () {

        beforeEach(function () {
          this.machine.send('poke');
          this.machine.send('poke');
        });

        it('transitions to state B then C', function () {
          assert.strictEqual(this.machine.state(), 'C');
        });

      });

      describe('on poke|poke|poke', function () {

        beforeEach(function () {
          this.machine.send('poke');
          this.machine.send('poke');
          this.machine.send('poke');
        });

        it('transitions to state B then C then C', function () {
          assert.strictEqual(this.machine.state(), 'C');
        });

      });

      describe('on poke|poke|prod', function () {

        beforeEach(function () {
          this.machine.send('poke');
          this.machine.send('poke');
          this.machine.send('prod');
        });

        it('transitions to state B then C then B', function () {
          assert.strictEqual(this.machine.state(), 'B');
        });

      });

      describe('on poke|poke|prod|prod', function () {

        beforeEach(function () {
          this.machine.send('poke');
          this.machine.send('poke');
          this.machine.send('prod');
          this.machine.send('prod');
        });

        it('transitions to state B then C then B then A', function () {
          assert.strictEqual(this.machine.state(), 'A');
        });

      });

      describe('on prod', function () {

        beforeEach(function () {
          this.machine.send('prod');
        });

        it('remains in state A', function () {
          assert.strictEqual(this.machine.state(), 'A');
        });

      });

      describe('on prod|prod', function () {

        beforeEach(function () {
          this.machine.send('prod');
          this.machine.send('prod');
        });

        it('remains in state A', function () {
          assert.strictEqual(this.machine.state(), 'A');
        });

      });

      describe('on prod|poke', function () {

        beforeEach(function () {
          this.machine.send('prod');
          this.machine.send('poke');
        });

        it('transitions to state B', function () {
          assert.strictEqual(this.machine.state(), 'B');
        });

      });

      describe('on prod|poke|prod', function () {

        beforeEach(function () {
          this.machine.send('prod');
          this.machine.send('poke');
          this.machine.send('prod');
        });

        it('transitions to state B then A', function () {
          assert.strictEqual(this.machine.state(), 'A');
        });

      });

    }

    describe('with state definition', function () {

      beforeEach(function () {
        this.definition = {
          initial: 'A'
        , states: {
            A: { poke: 'B', prod: 'A' }
          , B: { poke: 'C', prod: 'A' }
          , C: { poke: 'C', prod: 'B' }
          }
        };
        this.machine = statem.machine(this.definition);
      });

      checkit();

    });

    describe('with event definition', function () {

      beforeEach(function () {
        this.definition = {
          initial: 'A'
        , events: {
            poke: { A: 'B', B: 'C', C: 'C' }
          , prod: { A: 'A', B: 'A', C: 'B' }
          }
        };
        this.machine = statem.machine(this.definition);
      });

      checkit();

    });

  });

});
{'fraction_non_alphanumeric': 0.17289313640312773, 'fraction_numerical': 0.0, 'mean_word_length': 1.7214342001576044, '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': '6013493', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1933, 'n_words': 376}