From 63e9b49ebe7cbefcf30f04a305d9f627da9874d2 Mon Sep 17 00:00:00 2001 From: Isaiah Becker-Mayer Date: Thu, 7 Jul 2022 22:29:28 -0400 Subject: [PATCH] uncommenting tests --- src/observable/map/ObservableMap.ts | 256 ++++++++++++++-------------- 1 file changed, 128 insertions(+), 128 deletions(-) diff --git a/src/observable/map/ObservableMap.ts b/src/observable/map/ObservableMap.ts index 42d47c8d..7ee3d666 100644 --- a/src/observable/map/ObservableMap.ts +++ b/src/observable/map/ObservableMap.ts @@ -117,137 +117,137 @@ export class ObservableMap extends BaseObservableMap { } }; -// export function tests() { -// return { -// test_initial_values(assert) { -// const map = new ObservableMap([ -// ["a", 5], -// ["b", 10] -// ]); -// assert.equal(map.size, 2); -// assert.equal(map.get("a"), 5); -// assert.equal(map.get("b"), 10); -// }, +export function tests() { + return { + test_initial_values(assert) { + const map = new ObservableMap([ + ["a", 5], + ["b", 10] + ]); + assert.equal(map.size, 2); + assert.equal(map.get("a"), 5); + assert.equal(map.get("b"), 10); + }, -// test_add(assert) { -// let fired = 0; -// const map = new ObservableMap(); -// map.subscribe({ -// onAdd(key, value) { -// fired += 1; -// assert.equal(key, 1); -// assert.deepEqual(value, {value: 5}); -// }, -// onUpdate() {}, -// onRemove() {}, -// onReset() {} -// }); -// map.add(1, {value: 5}); -// assert.equal(map.size, 1); -// assert.equal(fired, 1); -// }, + test_add(assert) { + let fired = 0; + const map = new ObservableMap(); + map.subscribe({ + onAdd(key, value) { + fired += 1; + assert.equal(key, 1); + assert.deepEqual(value, {value: 5}); + }, + onUpdate() {}, + onRemove() {}, + onReset() {} + }); + map.add(1, {value: 5}); + assert.equal(map.size, 1); + assert.equal(fired, 1); + }, -// test_update(assert) { -// let fired = 0; -// const map = new ObservableMap(); -// const value = {number: 5}; -// map.add(1, value); -// map.subscribe({ -// onUpdate(key, value, params) { -// fired += 1; -// assert.equal(key, 1); -// assert.deepEqual(value, {number: 6}); -// assert.equal(params, "test"); -// }, -// onAdd() {}, -// onRemove() {}, -// onReset() {} -// }); -// value.number = 6; -// map.update(1, "test"); -// assert.equal(fired, 1); -// }, + test_update(assert) { + let fired = 0; + const map = new ObservableMap(); + const value = {number: 5}; + map.add(1, value); + map.subscribe({ + onUpdate(key, value, params) { + fired += 1; + assert.equal(key, 1); + assert.deepEqual(value, {number: 6}); + assert.equal(params, "test"); + }, + onAdd() {}, + onRemove() {}, + onReset() {} + }); + value.number = 6; + map.update(1, "test"); + assert.equal(fired, 1); + }, -// test_update_unknown(assert) { -// let fired = 0; -// const map = new ObservableMap(); -// map.subscribe({ -// onUpdate() { fired += 1; }, -// onAdd() {}, -// onRemove() {}, -// onReset() {} -// }); -// const result = map.update(1); -// assert.equal(fired, 0); -// assert.equal(result, false); -// }, + test_update_unknown(assert) { + let fired = 0; + const map = new ObservableMap(); + map.subscribe({ + onUpdate() { fired += 1; }, + onAdd() {}, + onRemove() {}, + onReset() {} + }); + const result = map.update(1); + assert.equal(fired, 0); + assert.equal(result, false); + }, -// test_set(assert) { -// let add_fired = 0, update_fired = 0; -// const map = new ObservableMap(); -// map.subscribe({ -// onAdd(key, value) { -// add_fired += 1; -// assert.equal(key, 1); -// assert.deepEqual(value, {value: 5}); -// }, -// onUpdate(key, value/*, params*/) { -// update_fired += 1; -// assert.equal(key, 1); -// assert.deepEqual(value, {value: 7}); -// }, -// onRemove() {}, -// onReset() {} -// }); -// // Add -// map.set(1, {value: 5}); -// assert.equal(map.size, 1); -// assert.equal(add_fired, 1); -// // Update -// map.set(1, {value: 7}); -// assert.equal(map.size, 1); -// assert.equal(update_fired, 1); -// }, + test_set(assert) { + let add_fired = 0, update_fired = 0; + const map = new ObservableMap(); + map.subscribe({ + onAdd(key, value) { + add_fired += 1; + assert.equal(key, 1); + assert.deepEqual(value, {value: 5}); + }, + onUpdate(key, value/*, params*/) { + update_fired += 1; + assert.equal(key, 1); + assert.deepEqual(value, {value: 7}); + }, + onRemove() {}, + onReset() {} + }); + // Add + map.set(1, {value: 5}); + assert.equal(map.size, 1); + assert.equal(add_fired, 1); + // Update + map.set(1, {value: 7}); + assert.equal(map.size, 1); + assert.equal(update_fired, 1); + }, -// test_remove(assert) { -// let fired = 0; -// const map = new ObservableMap(); -// const value = {value: 5}; -// map.add(1, value); -// map.subscribe({ -// onRemove(key, value) { -// fired += 1; -// assert.equal(key, 1); -// assert.deepEqual(value, {value: 5}); -// }, -// onAdd() {}, -// onUpdate() {}, -// onReset() {} -// }); -// map.remove(1); -// assert.equal(map.size, 0); -// assert.equal(fired, 1); -// }, + test_remove(assert) { + let fired = 0; + const map = new ObservableMap(); + const value = {value: 5}; + map.add(1, value); + map.subscribe({ + onRemove(key, value) { + fired += 1; + assert.equal(key, 1); + assert.deepEqual(value, {value: 5}); + }, + onAdd() {}, + onUpdate() {}, + onReset() {} + }); + map.remove(1); + assert.equal(map.size, 0); + assert.equal(fired, 1); + }, -// test_iterate(assert) { -// const results: any[] = []; -// const map = new ObservableMap(); -// map.add(1, {number: 5}); -// map.add(2, {number: 6}); -// map.add(3, {number: 7}); -// for (let e of map) { -// results.push(e); -// } -// assert.equal(results.length, 3); -// assert.equal(results.find(([key]) => key === 1)[1].number, 5); -// assert.equal(results.find(([key]) => key === 2)[1].number, 6); -// assert.equal(results.find(([key]) => key === 3)[1].number, 7); -// }, -// test_size(assert) { -// const map = new ObservableMap(); -// map.add(1, {number: 5}); -// map.add(2, {number: 6}); -// assert.equal(map.size, 2); -// }, -// } -// } + test_iterate(assert) { + const results: any[] = []; + const map = new ObservableMap(); + map.add(1, {number: 5}); + map.add(2, {number: 6}); + map.add(3, {number: 7}); + for (let e of map) { + results.push(e); + } + assert.equal(results.length, 3); + assert.equal(results.find(([key]) => key === 1)[1].number, 5); + assert.equal(results.find(([key]) => key === 2)[1].number, 6); + assert.equal(results.find(([key]) => key === 3)[1].number, 7); + }, + test_size(assert) { + const map = new ObservableMap(); + map.add(1, {number: 5}); + map.add(2, {number: 6}); + assert.equal(map.size, 2); + }, + } +}