Sha256: ae6e7b0bed088f61849dfca6a0f1829d5dac6adb667b3cdef24dad04b735eef1

Contents?: true

Size: 1.04 KB

Versions: 195

Compression:

Stored size: 1.04 KB

Contents

var test = require('tap').test
var LRU = require('../')

test('forEach', function (t) {
  var l = new LRU(5)
  for (var i = 0; i < 10; i ++) {
    l.set(i.toString(), i.toString(2))
  }

  var i = 9
  l.forEach(function (val, key, cache) {
    t.equal(cache, l)
    t.equal(key, i.toString())
    t.equal(val, i.toString(2))
    i -= 1
  })

  // get in order of most recently used
  l.get(6)
  l.get(8)

  var order = [ 8, 6, 9, 7, 5 ]
  var i = 0

  l.forEach(function (val, key, cache) {
    var j = order[i ++]
    t.equal(cache, l)
    t.equal(key, j.toString())
    t.equal(val, j.toString(2))
  })

  t.end()
})

test('keys() and values()', function (t) {
  var l = new LRU(5)
  for (var i = 0; i < 10; i ++) {
    l.set(i.toString(), i.toString(2))
  }

  t.similar(l.keys(), ['9', '8', '7', '6', '5'])
  t.similar(l.values(), ['1001', '1000', '111', '110', '101'])

  // get in order of most recently used
  l.get(6)
  l.get(8)

  t.similar(l.keys(), ['8', '6', '9', '7', '5'])
  t.similar(l.values(), ['1000', '110', '1001', '111', '101'])

  t.end()
})

Version data entries

195 entries across 120 versions & 9 rubygems

Version Path
exercism-analysis-0.1.1 vendor/javascript/node_modules/jshint/node_modules/minimatch/node_modules/lru-cache/test/foreach.js
hooch-0.4.2 jasmine/node_modules/karma/node_modules/useragent/node_modules/lru-cache/test/foreach.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/useragent/node_modules/lru-cache/test/foreach.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/useragent/node_modules/lru-cache/test/foreach.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/useragent/node_modules/lru-cache/test/foreach.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/useragent/node_modules/lru-cache/test/foreach.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/useragent/node_modules/lru-cache/test/foreach.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/useragent/node_modules/lru-cache/test/foreach.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/useragent/node_modules/lru-cache/test/foreach.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/useragent/node_modules/lru-cache/test/foreach.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/useragent/node_modules/lru-cache/test/foreach.js
smock-0.1.268 node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/readdirp/node_modules/minimatch/node_modules/lru-cache/test/foreach.js
smock-0.1.267 node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/readdirp/node_modules/minimatch/node_modules/lru-cache/test/foreach.js
smock-0.1.266 node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/readdirp/node_modules/minimatch/node_modules/lru-cache/test/foreach.js
smock-0.1.265 node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/readdirp/node_modules/minimatch/node_modules/lru-cache/test/foreach.js
smock-0.1.264 node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/readdirp/node_modules/minimatch/node_modules/lru-cache/test/foreach.js
smock-0.1.263 node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/readdirp/node_modules/minimatch/node_modules/lru-cache/test/foreach.js
smock-0.1.262 node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/readdirp/node_modules/minimatch/node_modules/lru-cache/test/foreach.js
smock-0.1.261 node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/readdirp/node_modules/minimatch/node_modules/lru-cache/test/foreach.js
smock-0.1.260 node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/readdirp/node_modules/minimatch/node_modules/lru-cache/test/foreach.js