Skip to content

Commit

Permalink
fix: rank validation
Browse files Browse the repository at this point in the history
  • Loading branch information
tuner committed Jan 14, 2025
1 parent cfb7c2d commit 5622a8d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/sampleTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ function createSampleTree(nodes: SampleTreeNode[]) {
}

if (parent) {
if (parent.rank >= node.rank) {
throw new Error(
`Parent "${parent.sample.sample}" has rank ${parent.rank} >= ${node.sample.sample}'s rank ${node.rank}`
);
}

node.parent = parent;
parent.children.push(node);
}
Expand All @@ -105,6 +99,12 @@ function fixMissingRanks(sampleTree: SampleTreeNode) {
throw new Error("Rank must be defined for the root node.");
}
node.rank = node.parent.rank + 1;
} else {
if (node.parent && node.rank <= node.parent.rank) {
throw new Error(
`Node "${node.sample.sample}" has rank ${node.rank} <= its parent's rank ${node.parent.rank}`
);
}
}
}
}
Expand Down

0 comments on commit 5622a8d

Please sign in to comment.