<commit_before>jest.autoMockOff();
let IM = require('immutable');
let Heap = require('../../../src/heaps/Heap');

describe("Heap Operations", ()=>{
  describe("Basic Instantiation: ", ()=>{
    let newHeap;
    newHeap = new Heap();
    it("instantiates a min-heap", ()=>{
      expect(newHeap.isMaxHeap).toBe(false);
    })
    it("instantiates empty", ()=>{
      expect(newHeap.size).toBe(0);
    })
  })

  describe("Basic: ", ()=>{
    let newHeap = new Heap();
    newHeap = newHeap.push(1).push(0).push(3);
    let newHeap2 = new Heap();
    newHeap2 = newHeap2.push(1).push(2).push(3).push(4).push(5).push(0);
    it("Pushes/Inserts", ()=>{
      expect(newHeap.size).toBe(3);
    })
    it("Peeks", ()=>{
      expect(newHeap.peek()).toBe(0);
      expect(newHeap2.peek()).toBe(0);
    })
    it("Pops/Extracts", ()=>{
      expect(newHeap.pop().size).toBe(2);
      expect(newHeap.pop().peek()).toBe(1);
      expect(newHeap.size).toBe(3);
    })
    it("Replaces", ()=>{
      expect(newHeap.replace(0).size).toBe(3);
      expect(newHeap.replace(0).peek()).toBe(0);

    })
  })

  xdescribe("Creation: ", ()=>{
    describe("Constructor", ()=>{
      it("can create a max-heap", ()=>{})
      it("accepts an array", ()=>{})
      it("accepts a heap", ()=>{})
      it("", ()=>{})
    })
    describe("heapifies", ()=>{})
    describe("Merges", ()=>{})
    describe("Melds", ()=>{})

  })

  xdescribe("Inspection: ", ()=>{
    it("Checks Size", ()=>{})
    it("Checks isEmpty", ()=>{})
    
  })
  
  xdescribe("Internal: ", ()=>{
    it("Deletes Node", ()=>{})
    it("inc/dec key", ()=>{})
    it("performs an integrity check", ()=>{})
    it("can push into a large 1000+ heap without errors", ()=>{})
    it("sift up", ()=>{})
    it("sift down", ()=>{})
  })

})<commit_msg>Complete Unit Tests for Heap (previous commit message was wrong file)<commit_after>jest.autoMockOff();
let IM = require('immutable');
let Heap = require('../../../src/heaps/Heap');

describe("Heap Operations", ()=>{
  describe("Instantiation: ", ()=>{
    let newHeap;
    newHeap = new Heap();
    it("instantiates a min-heap", ()=>{
      expect(newHeap.isMaxHeap).toBe(false);
    })
    it("can create a max-heap", ()=>{
      let maxHeap = new Heap(undefined,true);
      expect(maxHeap.isMaxHeap).toBe(true);
    })
    it("instantiates empty, checks size", ()=>{
      expect(newHeap.size).toBe(0);
    })
    it("instantiates with a comparator", ()=>{
      let compare = ()=>0;
      let compareHeap = new Heap(undefined, undefined, compare);
      expect(compareHeap.comparator).toEqual(compare);
    })
  })

  describe("Basic Instance Methods: ", ()=>{
    let newHeap = new Heap();
    newHeap = newHeap.push(1).push(0).push(3);
    let newHeap2 = new Heap();
    newHeap2 = newHeap2.push(1).push(2).push(3).push(4).push(5).push(0);
    it("Pushes/Inserts", ()=>{
      expect(newHeap.size).toBe(3);
    })
    it("Peeks", ()=>{
      expect(newHeap.peek()).toBe(0);
      expect(newHeap2.peek()).toBe(0);
    })
    it("Pops/Extracts", ()=>{
      expect(newHeap.pop().size).toBe(2);
      expect(newHeap.pop().peek()).toBe(1);
      expect(newHeap.size).toBe(3);
    })
    it("Replaces", ()=>{
      expect(newHeap.replace(0).size).toBe(3);
      expect(newHeap.replace(0).peek()).toBe(0);
    })
  })

  describe("Creation & Operations: ", ()=>{
    let numbers25 = [];
    let numbers50 = [];
    for (var i = 25; i >0; i--){
      numbers25.push(i);
    }
    for (var i = 50; i >25; i--){
      numbers50.push(i);
    }
    describe("BuildHeap", ()=>{
      it("builds max heaps from an array", ()=>{
        let heap = new Heap(numbers25, true);
        expect(heap.size).toBe(25);
        expect(heap.peek()).toBe(25);
        expect(heap.pop().pop().peek()).toBe(23);
      })
      it("builds min heaps from an array", ()=>{
        let heap = new Heap(numbers25);
        expect(heap.size).toBe(25);
        expect(heap.peek()).toBe(1);
        expect(heap.pop().pop().peek()).toBe(3);
      })
      it("accepts heaps", ()=>{
        let heap1 = new Heap(numbers25);
        let heap2 = new Heap(heap1);
        expect(heap.size).toBe(25);
        expect(heap.peek()).toBe(25);
        expect(heap.pop().pop().peek()).toBe(23);

      })
    })
    describe("Merge", ()=>{
      it("merges with other heaps", ()=>{
        let heap1 = new Heap(numbers25);
        let heap2 = new Heap(numbers50);
        let heap3 = heap2.merge(heap1);
        expect(heap3.peek()).toBe(1);
        expect(heap3.size).toBe(50);
      })
    })
    describe("HeapSort", ()=>{
        it('sorts an array of numbers', ()=>{
          let tenNumbers = [1,2,3,4,5,6,7,8,9,10].sort(()=>{
            return .5 - Math.random();
          });
          let newHeap = new Heap(tenNumbers);
          //heapsort should return the array
          let sortedArray = newHeap.heapsort();
          for (var i = 0; i<10; i++){
            expect(sortedArray[i]).toBe(i+1);
          }          
        })
    })
  })

})
{'fraction_non_alphanumeric': 0.2280806870381466, 'fraction_numerical': 0.02456560814859197, 'mean_word_length': 2.652808169219548, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 55, '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': '2619079', 'n_tokens_mistral': 1804, 'n_tokens_neox': 1816, 'n_words': 287}