<commit_before>const expect = require('chai').expect;

let Stack;
let stack;

try {
  Stack = require('../Stack.js');
  stack = new Stack();
} catch (e) {
  throw 'Stack could not be tested due to faulty import, likely ' +
  'from incorrect file path or non-constructor import';
}

describe('Stack', () => {
  beforeEach(() => {
    stack = new Stack();
  });

  describe('#isEmpty()', () => {
    it('should detect if stack is empty', () => {
      expect(stack.isEmpty()).to.equal(true);
      stack.push(0)
      expect(stack.isEmpty()).to.equal(false);
    });
  });

  describe('#isFull()', () => {
    it('should detect if stack is full', () => {
      const cappedStack = new Stack(1);
      expect(cappedStack.isFull()).to.equal(false);
      cappedStack.push(0);
      expect(cappedStack.isFull()).to.equal(true);
    });
  });

  describe('#peek()', () => {
    it('should return value at top of stack', () => {
      stack.push(0);
      expect(stack.peek()).to.equal(0);
    });

    it('should return undefined for empty stack', () => {
      expect(stack.peek()).to.equal(undefined);
    });
  });

  describe('#push()', () => {
    it('should increase size of stack by 1', () => {
      expect(stack.storage.length).to.equal(0);
      stack.push(0);
      expect(stack.storage.length).to.equal(1);
    });

    it('should append input to top of stack', () => {
      stack.push(0);
      stack.push(1);
      expect(stack.storage[stack.storage.length - 1]).to.equal(1);
    });

    it('should return new stack length', () => {
      expect(stack.push(0)).to.equal(1);
    });

    it('should not insert item if stack is at capacity', () => {
      const cappedStack = new Stack(0);
      stack.push('never pushed');
      expect(cappedStack.storage.length).to.equal(0);
    });
  });

  describe('#pop()', () => {
    it('should decrease size of stack by 1', () => {
      stack.push(0);
      expect(stack.storage.length).to.equal(1);
      stack.pop();
      expect(stack.storage.length).to.equal(0);
    });

    it('should remove value from top of stack', () => {
      stack.push(0);
      stack.push(1);
      stack.pop();
      expect(stack.storage[stack.storage.length - 1]).to.equal(0);
    });

    it('should return removed value', () => {
      stack.push(0);
      expect(stack.pop()).to.equal(0);
    });
  });

  describe('#size()', () => {
    it('should return number of elements in stack', () => {
      expect(stack.size()).to.equal(0);
      stack.push(0);
      expect(stack.size()).to.equal(1);
    });
  });
});<commit_msg>refactor tests to AAA pattern<commit_after>const expect = require('chai').expect;

let Stack;
let stack;

try {
  Stack = require('../Stack.js');
  stack = new Stack();
} catch (e) {
  throw 'Stack could not be tested due to faulty import, likely ' +
  'from incorrect file path or non-constructor import';
}

// Follows AAA (Arrange -> Act -> Assert) unit testing pattern
describe('Stack', () => {
  beforeEach(() => {
    stack = new Stack();
  });

  describe('#isEmpty()', () => {
    it('should return true if stack is empty', () => {
      expect(stack.isEmpty()).to.equal(true);
    });

    it('should return false if stack contains values', () => {
      stack.push(0)

      expect(stack.isEmpty()).to.equal(false);
    });
  });

  describe('#isFull()', () => {
    it('should return false if stack has not reached capacity', () => {
      const cappedStack = new Stack(1);

      expect(cappedStack.isFull()).to.equal(false);
    });

    it('should return true if stack has reached capacity', () => {
      const cappedStack = new Stack(1);

      cappedStack.push(0);

      expect(cappedStack.isFull()).to.equal(true);
    });
  });

  describe('#peek()', () => {
    it('should return value at top of stack', () => {
      stack.push(0);

      expect(stack.peek()).to.equal(0);
    });

    it('should return undefined for empty stack', () => {
      expect(stack.peek()).to.equal(undefined);
    });
  });

  describe('#push()', () => {
    it('should increase size of stack by 1', () => {
      stack.push(0);

      expect(stack.storage.length).to.equal(1);
    });

    it('should append input to top of stack', () => {
      stack.push(0);
      stack.push(1);

      expect(stack.storage[stack.storage.length - 1]).to.equal(1);
    });

    it('should return new stack length', () => {
      expect(stack.push(0)).to.equal(1);
    });

    it('should not insert item if stack is at capacity', () => {
      const cappedStack = new Stack(0);

      stack.push('never pushed');

      expect(cappedStack.storage.length).to.equal(0);
    });
  });

  describe('#pop()', () => {
    it('should decrease size of stack by 1', () => {
      stack.push(0);
      stack.push(1);

      stack.pop();

      expect(stack.storage.length).to.equal(1);
    });

    it('should remove last item pushed to stack', () => {
      stack.push(0);
      stack.push(1);

      stack.pop();

      expect(stack.storage[stack.storage.length - 1]).to.equal(0);
    });

    it('should return removed value', () => {
      stack.push(0);

      expect(stack.pop()).to.equal(0);
    });
  });

  describe('#size()', () => {
    it('should return 0 if stack is empty', () => {
      expect(stack.size()).to.equal(0);
    });

    it('should return 1 if stack contains one item', () => {
      stack.push(0);

      expect(stack.size()).to.equal(1);
    });
  });
});
{'fraction_non_alphanumeric': 0.20357735570717314, 'fraction_numerical': 0.011432786280656464, 'mean_word_length': 2.6847826086956523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 48, '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': '710256', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1698, 'n_words': 370}