Add resources tests

This commit is contained in:
2020-04-24 11:43:18 +03:00
parent fb4ac6424c
commit 6bd04ee6e2
5 changed files with 37 additions and 20 deletions

View File

@ -16,7 +16,7 @@ export class GatheringTimings {
this.crop = crop;
}
get common(): GatheringTime {
private get common(): GatheringTime {
const xs = [this.lumber, this.clay, this.iron, this.crop];
return xs.reduce((m, t) => (m === 'never' || t === 'never' ? 'never' : Math.max(m, t)), 0);
}

View File

@ -27,11 +27,11 @@ function calcNeedResources(
totalRequired: Resources,
storage: ResourceStorage
): Resources {
if (!current.gt(required)) {
if (current.lt(required)) {
return required.sub(current);
}
if (!current.gt(totalRequired)) {
if (current.lt(totalRequired)) {
return totalRequired.sub(current);
}

View File

@ -86,21 +86,13 @@ export class Resources implements ResourcesInterface {
}
lt(other: ResourcesInterface): boolean {
return this.lumber < other.lumber && this.clay < other.clay && this.iron < other.iron && this.crop < other.crop;
return this.lumber < other.lumber || this.clay < other.clay || this.iron < other.iron || this.crop < other.crop;
}
gt(other: ResourcesInterface): boolean {
return this.lumber > other.lumber && this.clay > other.clay && this.iron > other.iron && this.crop > other.crop;
}
lte(other: ResourcesInterface): boolean {
return !this.gt(other);
}
gte(other: ResourcesInterface): boolean {
return !this.lt(other);
}
min(other: ResourcesInterface): Resources {
return new Resources(
Math.min(this.lumber, other.lumber),