import MultiWeakMap from '../MultiWeakMap'

describe('MultiWeakMap', () => {
  it('retrieves a previously set value', () => {
    const obj1 = {x: 1}
    const obj2 = {x: 2}

    const map = new MultiWeakMap(2)
    map.set([obj1, obj2], 4)
    expect(map.has([obj1, obj2])).to.be.true()
    expect(map.get([obj1, obj2])).to.eq(4)
  })

  it('is sensitive to key ordering', () => {
    const obj1 = {x: 1}
    const obj2 = {x: 2}

    const map = new MultiWeakMap(2)
    map.set([obj1, obj2], 4)
    expect(map.has([obj2, obj1])).to.be.false()
    expect(map.get([obj2, obj1])).to.be.undefined()
  })

  it('expects the numKeys to be a positive integer', () => {
    expect(() => new MultiWeakMap('hello')).to.throw()
    expect(() => new MultiWeakMap(0)).to.throw()
  })

  it('returns undefined when empty', () => {
    const obj1 = {x: 1}
    const obj2 = {x: 2}

    const map = new MultiWeakMap(2)
    expect(map.has([obj1, obj2])).to.be.false()
    expect(map.get([obj1, obj2])).to.be.undefined()
  })
})
