Add resources tests
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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),
|
||||
|
Reference in New Issue
Block a user