Fix revaluation limit enforcement
This commit is contained in:
parent
83f9007401
commit
ff5edc64ac
|
@ -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]');
|
||||
|
|
Loading…
Reference in New Issue