|
| 1 | +-- |
| 2 | +-- Created by IntelliJ IDEA. |
| 3 | +-- User: chen0 |
| 4 | +-- Date: 26/6/2017 |
| 5 | +-- Time: 12:03 PM |
| 6 | +-- To change this template use File | Settings | File Templates. |
| 7 | +-- |
| 8 | + |
| 9 | +describe('hashmap', function() |
| 10 | + describe('hashmap()', function() |
| 11 | + it('should put and get and remove correctly', function() |
| 12 | + local hashmap = require('data.hashmap') |
| 13 | + local hash_func = function(x) return x % 1000 end |
| 14 | + local s = hashmap.create(hash_func) |
| 15 | + s:put(100, 2) |
| 16 | + s:put(200, 4) |
| 17 | + s:put(450, 2) |
| 18 | + assert.equal(s:get(100), 2) |
| 19 | + assert.equal(s:get(200), 4) |
| 20 | + assert.equal(s:get(450), 2) |
| 21 | + assert.equal(s:get(99), nil) |
| 22 | + assert.equal(s:containsKey(99), false) |
| 23 | + assert.equal(s:containsKey(100), true) |
| 24 | + assert.equal(s:size(), 3) |
| 25 | + assert.equal(s:isEmpty(), false) |
| 26 | + assert.equal(s:remove(100), 2) |
| 27 | + assert.equal(s:containsKey(100), false) |
| 28 | + assert.equal(s:size(), 2) |
| 29 | + s:remove(200) |
| 30 | + s:remove(450) |
| 31 | + assert.equal(s:isEmpty(), true) |
| 32 | + end) |
| 33 | + end) |
| 34 | +end) |
| 35 | + |
0 commit comments