Skip to content

Commit 5622a8d

Browse files
committed
fix: rank validation
1 parent cfb7c2d commit 5622a8d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/sampleTree.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ function createSampleTree(nodes: SampleTreeNode[]) {
7777
}
7878

7979
if (parent) {
80-
if (parent.rank >= node.rank) {
81-
throw new Error(
82-
`Parent "${parent.sample.sample}" has rank ${parent.rank} >= ${node.sample.sample}'s rank ${node.rank}`
83-
);
84-
}
85-
8680
node.parent = parent;
8781
parent.children.push(node);
8882
}
@@ -105,6 +99,12 @@ function fixMissingRanks(sampleTree: SampleTreeNode) {
10599
throw new Error("Rank must be defined for the root node.");
106100
}
107101
node.rank = node.parent.rank + 1;
102+
} else {
103+
if (node.parent && node.rank <= node.parent.rank) {
104+
throw new Error(
105+
`Node "${node.sample.sample}" has rank ${node.rank} <= its parent's rank ${node.parent.rank}`
106+
);
107+
}
108108
}
109109
}
110110
}

0 commit comments

Comments
 (0)