This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
generated from mrbrianevans/react-website-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculates number of primitives in an object (leaf nodes) Signed-off-by: Brian Evans <[email protected]>
- Loading branch information
1 parent
278f32c
commit 10837b0
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { objectSize } from '../../../../lib/common/ArrayUtils' | ||
import * as Assert from 'assert' | ||
|
||
describe('calculate the size of an object in number of primitives', function () { | ||
it('should get the size of a simple object', function () { | ||
const obj = { | ||
action: 'delete', | ||
date: new Date().getTime() | ||
} | ||
const output = objectSize(obj) | ||
Assert.equal(output, 2) | ||
}) | ||
it('should get the size of an object with 5 primitives', function () { | ||
const obj = { | ||
action: 'delete', | ||
date: { year: 2020, month: 10 }, | ||
permission: true, | ||
role: 'Admin' | ||
} | ||
const output = objectSize(obj) | ||
Assert.equal(output, 5) | ||
}) | ||
it('should get the size of an object with 6 primitives including null', function () { | ||
const obj = { | ||
action: 'delete', | ||
date: { year: 2020, month: 10 }, | ||
permission: true, | ||
role: 'Admin', | ||
violation: null | ||
} | ||
const output = objectSize(obj) | ||
Assert.equal(output, 6) | ||
}) | ||
it('should get the size of an object with 6 primitives in an array', function () { | ||
const obj = { | ||
actions: ['create', 'delete', 'update', 'replace', 'rename', 'edit'] | ||
} | ||
const output = objectSize(obj) | ||
Assert.equal(output, 6) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters