Expand Conditions
All checks were successful
E2E Testing / test (push) Successful in 1m32s

This commit is contained in:
Sebastian Böckelmann 2024-02-17 18:49:24 +01:00
parent 75a4122641
commit d667a66b79
3 changed files with 50 additions and 4 deletions

View File

@ -0,0 +1,44 @@
import { test, expect } from '@playwright/test';
import {ScriptAccountCondition} from "../../../../src/app/game-model/gamesystems/conditions/ScriptAccountCondition";
import {ScriptAccount} from "../../../../src/app/game-model/scriptAccounts/ScriptAccount";
import exp = require("node:constants");
import {ConditionTrainer} from "./ConditionTrainer";
test.describe('Test Expand Conditions', () => {
test("Test expansion with contradiccting Conditions", async () => {
const condition = ConditionTrainer.withSimpleCondition();
const otherCondition = ConditionTrainer.withContradictingCondition(condition);
condition.extendCondition(otherCondition)
expect(condition.minValue).toEqual(ConditionTrainer.withSimpleCondition().minValue);
expect(condition.maxValue).toEqual(ConditionTrainer.withSimpleCondition().maxValue);
})
test("Test lower expansion of Conditions", async () => {
const condition = ConditionTrainer.withSimpleCondition();
const otherCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-10, condition.minValue+10)
condition.extendCondition(otherCondition);
expect(condition.minValue).toEqual(ConditionTrainer.withSimpleCondition().minValue-10)
expect(condition.maxValue).toEqual(ConditionTrainer.withSimpleCondition().maxValue);
})
test("Test higher expansion of conditions", async () => {
const condition = ConditionTrainer.withSimpleCondition();
const otherCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.maxValue-10, condition.maxValue+10)
condition.extendCondition(otherCondition)
expect(condition.minValue).toEqual(ConditionTrainer.withSimpleCondition().minValue)
expect(condition.maxValue).toEqual(ConditionTrainer.withSimpleCondition().maxValue+10)
})
test("Test higher and lower Expansion of Conditions", async () => {
const condition = ConditionTrainer.withSimpleCondition();
const otherCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-10, condition.maxValue+10);
condition.extendCondition(otherCondition);
expect(condition.minValue).toEqual(ConditionTrainer.withSimpleCondition().minValue-10)
expect(condition.maxValue).toEqual(ConditionTrainer.withSimpleCondition().maxValue+10)
})
});

View File

@ -7,8 +7,7 @@ export class ConditionTrainer {
return ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, 0, 10); return ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, 0, 10);
} }
static withSimpleOtherCondition(): ScriptAccountCondition { static withContradictingCondition(condition: ScriptAccountCondition): ScriptAccountCondition {
const scriptAccount = new ScriptAccount("Another Test", ""); return ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-20, condition.minValue-10);
return ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, 0, 10);
} }
} }

View File

@ -17,7 +17,10 @@ export class ScriptAccountCondition {
} }
extendCondition(condition: ScriptAccountCondition) { extendCondition(condition: ScriptAccountCondition) {
if(!this.isContradicting(condition)) {
this.minValue = Math.min(this.minValue, condition.minValue);
this.maxValue = Math.max(this.maxValue, condition.maxValue);
}
} }
isContradicting(condition: ScriptAccountCondition) { isContradicting(condition: ScriptAccountCondition) {