Fix revaluation limit enforcement

This commit is contained in:
Ladd Hoffman 2023-01-12 09:03:54 -06:00
parent 83f9007401
commit ff5edc64ac
1 changed files with 4 additions and 4 deletions

View File

@ -14,10 +14,10 @@ class Post extends Actor {
this.value = 0;
this.citations = postContent.citations;
this.title = postContent.title;
this.totalCitationWeight = this.citations.reduce((total, { weight }) => total += weight, 0);
if (this.totalCitationWeight > params.revaluationLimit) {
throw new Error('Post total citation weight exceeds revaluation limit '
+ `(${this.totalCitationWeight} > ${params.revaluationLimit})`);
const revaluationTotal = this.citations.reduce((total, { weight }) => total += Math.abs(weight), 0);
if (revaluationTotal > params.revaluationLimit) {
throw new Error('Post revaluation total exceeds revaluation limit '
+ `(${revaluationTotal} > ${params.revaluationLimit})`);
}
if (this.citations.some(({ weight }) => Math.abs(weight) > 1)) {
throw new Error('Each citation weight must be in the range [-1, 1]');