Skip to content

Commit a912bf2

Browse files
authored
Merge pull request #3 from sourcemeta/fix-nesting-bug
Fix largest level calculation
2 parents 68d4ba7 + 9e447c9 commit a912bf2

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

README.markdown

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ time.
8181

8282
- **Flat**: A JSON document is in this category if the height of the document
8383
multiplied by the non-root level with the largest byte-size when taking
84-
textual, numeric and boolean values into account is less than 10.
84+
textual, numeric and boolean values into account is less than 10. If two
85+
levels have the byte size, the highest level is taken into account.
8586

8687
- **Nested**: A JSON document is in this category if it is considered
8788
*structural* and its height is greater than or equal to 5, or if the height
8889
of the document multiplied by the non-root level with the largest byte-size
8990
when taking textual, numeric and boolean values into account is greater than
90-
or equal to 10.
91+
or equal to 10. If two levels have the byte size, the highest level is taken
92+
into account.
9193

9294
Usage (JavaScript)
9395
------------------

js/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ module.exports = (value) => {
6161
// Nesting characteristics
6262
const largestLevel = analysis.levels.slice(1).map((level, index) => {
6363
return { index: index + 1, ...level }
64+
}).sort((left, right) => {
65+
return right.index - left.index
6466
}).sort((left, right) => {
6567
return right.size - left.size
6668
})[0]
69+
6770
if (textualWeight === 0 && numericWeight === 0 && booleanWeight === 0 && analysis.height >= 5) {
6871
qualifiers.push('nested')
6972
} else if (analysis.height * largestLevel.index >= 10) {

test/js/index.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,36 @@ tap.test('should categorize the survey test object', (test) => {
5454
test.end()
5555
})
5656

57+
tap.test('should categorize a tier 1 numeric non-redundant nested document', (test) => {
58+
const document = {
59+
version: 2.1,
60+
workflows: {
61+
test: {
62+
jobs: [
63+
{
64+
m1: {
65+
matrix: {
66+
parameters: {
67+
a: [1, 2, 3]
68+
}
69+
}
70+
}
71+
}
72+
]
73+
}
74+
}
75+
}
76+
77+
test.strictSame(taxonomy(document), [
78+
'tier 1',
79+
'numeric',
80+
'non-redundant',
81+
'nested'
82+
])
83+
84+
test.end()
85+
})
86+
5787
tap.test('should categorize an empty object', (test) => {
5888
const document = {}
5989

0 commit comments

Comments
 (0)