From 61de2e81927e8b8a473f937e485bcdf3084a3503 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sun, 2 Feb 2020 23:04:28 -0800 Subject: [PATCH] dict: Remove is_empty method. Signed-off-by: Anders Kaseorg --- frontend_tests/node_tests/dict.js | 9 ++------- frontend_tests/node_tests/fold_dict.js | 6 ++---- frontend_tests/node_tests/int_dict.js | 9 ++------- static/js/dict.ts | 4 ---- static/js/fold_dict.ts | 4 ---- static/js/int_dict.ts | 4 ---- static/js/topic_data.js | 2 +- 7 files changed, 7 insertions(+), 31 deletions(-) diff --git a/frontend_tests/node_tests/dict.js b/frontend_tests/node_tests/dict.js index 7510919656..695429f04c 100644 --- a/frontend_tests/node_tests/dict.js +++ b/frontend_tests/node_tests/dict.js @@ -4,13 +4,13 @@ const Dict = zrequire('dict').Dict; run_test('basic', () => { const d = new Dict(); - assert(d.is_empty()); + assert.equal(d.size, 0); assert.deepEqual(d.keys(), []); d.set('foo', 'bar'); assert.equal(d.get('foo'), 'bar'); - assert(!d.is_empty()); + assert.notEqual(d.size, 0); d.set('foo', 'baz'); assert.equal(d.get('foo'), 'baz'); @@ -113,15 +113,12 @@ run_test('each', () => { run_test('num_items', () => { const d = new Dict(); assert.equal(d.size, 0); - assert(d.is_empty()); d.set('foo', 1); assert.equal(d.size, 1); - assert(!d.is_empty()); d.set('foo', 2); assert.equal(d.size, 1); - assert(!d.is_empty()); d.set('bar', 1); assert.equal(d.size, 2); @@ -162,13 +159,11 @@ run_test('clear', () => { populate(); assert.equal(d.size, 2); - assert(!d.is_empty()); d.clear(); assert.equal(d.get('foo'), undefined); assert.equal(d.get('bar'), undefined); assert.equal(d.size, 0); - assert(d.is_empty()); // make sure it still works after clearing populate(); diff --git a/frontend_tests/node_tests/fold_dict.js b/frontend_tests/node_tests/fold_dict.js index 8874a034c9..2764c5b87e 100644 --- a/frontend_tests/node_tests/fold_dict.js +++ b/frontend_tests/node_tests/fold_dict.js @@ -4,13 +4,13 @@ set_global('blueslip', global.make_zblueslip()); run_test('basic', () => { const d = new FoldDict(); - assert(d.is_empty()); + assert.equal(d.size, 0); assert.deepEqual(d.keys(), []); d.set('foo', 'bar'); assert.equal(d.get('foo'), 'bar'); - assert(!d.is_empty()); + assert.notEqual(d.size, 0); d.set('foo', 'baz'); assert.equal(d.get('foo'), 'baz'); @@ -71,13 +71,11 @@ run_test('clear', () => { populate(); assert.equal(d.size, 2); - assert(!d.is_empty()); d.clear(); assert.equal(d.get('fOO'), undefined); assert.equal(d.get('bAR'), undefined); assert.equal(d.size, 0); - assert(d.is_empty()); // make sure it still works after clearing populate(); diff --git a/frontend_tests/node_tests/int_dict.js b/frontend_tests/node_tests/int_dict.js index 164679fca9..a0e678e7e4 100644 --- a/frontend_tests/node_tests/int_dict.js +++ b/frontend_tests/node_tests/int_dict.js @@ -4,13 +4,13 @@ const IntDict = zrequire('int_dict').IntDict; run_test('basic', () => { const d = new IntDict(); - assert(d.is_empty()); + assert.equal(d.size, 0); assert.deepEqual(d.keys(), []); d.set(101, 'bar'); assert.equal(d.get(101), 'bar'); - assert(!d.is_empty()); + assert.notEqual(d.size, 0); d.set(101, 'baz'); assert.equal(d.get(101), 'baz'); @@ -131,15 +131,12 @@ run_test('non integers', () => { run_test('num_items', () => { const d = new IntDict(); assert.equal(d.size, 0); - assert(d.is_empty()); d.set(101, 1); assert.equal(d.size, 1); - assert(!d.is_empty()); d.set(101, 2); assert.equal(d.size, 1); - assert(!d.is_empty()); d.set(102, 1); assert.equal(d.size, 2); @@ -159,13 +156,11 @@ run_test('clear', () => { populate(); assert.equal(d.size, 2); - assert(!d.is_empty()); d.clear(); assert.equal(d.get(101), undefined); assert.equal(d.get(102), undefined); assert.equal(d.size, 0); - assert(d.is_empty()); // make sure it still works after clearing populate(); diff --git a/static/js/dict.ts b/static/js/dict.ts index 25971242ef..512bc9292f 100644 --- a/static/js/dict.ts +++ b/static/js/dict.ts @@ -34,10 +34,6 @@ export class Dict { return this._items.size; } - is_empty(): boolean { - return this._items.size === 0; - } - each(f: (v: V, k?: string) => void): void { this._items.forEach(f); } diff --git a/static/js/fold_dict.ts b/static/js/fold_dict.ts index ad57d41988..a3841bedf2 100644 --- a/static/js/fold_dict.ts +++ b/static/js/fold_dict.ts @@ -54,10 +54,6 @@ export class FoldDict { return this._items.size; } - is_empty(): boolean { - return this._items.size === 0; - } - each(f: (v: V, k?: string) => void): void { this._items.forEach(({k, v}) => f(v, k)); } diff --git a/static/js/int_dict.ts b/static/js/int_dict.ts index 0cc6061be3..632902e954 100644 --- a/static/js/int_dict.ts +++ b/static/js/int_dict.ts @@ -66,10 +66,6 @@ export class IntDict { return this._map.size; } - is_empty(): boolean { - return this._map.size === 0; - } - each(f: (v: V, k?: number) => void): void { this._map.forEach(f); } diff --git a/static/js/topic_data.js b/static/js/topic_data.js index 4d9a5ae636..9a60ea1110 100644 --- a/static/js/topic_data.js +++ b/static/js/topic_data.js @@ -56,7 +56,7 @@ exports.topic_history = function (stream_id) { const self = {}; self.has_topics = function () { - return !topics.is_empty(); + return topics.size !== 0; }; self.add_or_update = function (opts) {