From d667a66b79c6ba246e3b1ff6ae750516cdb784c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sat, 17 Feb 2024 18:49:24 +0100 Subject: [PATCH] Expand Conditions --- .../conditions/ConditionExpansion.spec.ts | 44 +++++++++++++++++++ .../conditions/ConditionTrainer.ts | 5 +-- .../conditions/ScriptAccountCondition.ts | 5 ++- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 e2e/game-model/gamesystems/conditions/ConditionExpansion.spec.ts diff --git a/e2e/game-model/gamesystems/conditions/ConditionExpansion.spec.ts b/e2e/game-model/gamesystems/conditions/ConditionExpansion.spec.ts new file mode 100644 index 0000000..d2b859c --- /dev/null +++ b/e2e/game-model/gamesystems/conditions/ConditionExpansion.spec.ts @@ -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) + }) +}); diff --git a/e2e/game-model/gamesystems/conditions/ConditionTrainer.ts b/e2e/game-model/gamesystems/conditions/ConditionTrainer.ts index d08077f..ac7b947 100644 --- a/e2e/game-model/gamesystems/conditions/ConditionTrainer.ts +++ b/e2e/game-model/gamesystems/conditions/ConditionTrainer.ts @@ -7,8 +7,7 @@ export class ConditionTrainer { return ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, 0, 10); } - static withSimpleOtherCondition(): ScriptAccountCondition { - const scriptAccount = new ScriptAccount("Another Test", ""); - return ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, 0, 10); + static withContradictingCondition(condition: ScriptAccountCondition): ScriptAccountCondition { + return ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-20, condition.minValue-10); } } diff --git a/src/app/game-model/gamesystems/conditions/ScriptAccountCondition.ts b/src/app/game-model/gamesystems/conditions/ScriptAccountCondition.ts index 6d741be..9284c5a 100644 --- a/src/app/game-model/gamesystems/conditions/ScriptAccountCondition.ts +++ b/src/app/game-model/gamesystems/conditions/ScriptAccountCondition.ts @@ -17,7 +17,10 @@ export class 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) {