Create ScriptAccountConditions
All checks were successful
E2E Testing / test (push) Successful in 1m31s

This commit is contained in:
Sebastian Böckelmann 2024-02-17 18:15:36 +01:00
parent b5e3b8ee53
commit 4a1f4e4c52
2 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,55 @@
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");
test.describe('Test Create Gamesystems', () => {
test("Test creation with null/undefined parameters", async () => {
let result = ScriptAccountCondition.constructScriptAccountCondition(null, 1, 2);
expect(result).toBeUndefined()
result = ScriptAccountCondition.constructScriptAccountCondition(undefined, 1, 2);
expect(result).toBeUndefined();
result = ScriptAccountCondition.constructScriptAccountCondition(new ScriptAccount("Test", ""), null, 2);
expect(result).toBeUndefined();
result = ScriptAccountCondition.constructScriptAccountCondition(new ScriptAccount("Test", ""), undefined, 2);
expect(result).toBeUndefined();
result = ScriptAccountCondition.constructScriptAccountCondition(new ScriptAccount("Test", ""), 1, undefined);
expect(result).toBeUndefined();
result = ScriptAccountCondition.constructScriptAccountCondition(new ScriptAccount("Test", ""),1, null);
expect(result).toBeUndefined();
})
test("Test Creation with swapped Min Max Parameter", async () => {
let result = ScriptAccountCondition.constructScriptAccountCondition(new ScriptAccount("Test", ""), 2, 1);
expect(result).toBeUndefined();
})
test("Test Correct Condition Creation", async () => {
const scriptAccount = new ScriptAccount("Test", "");
let result = ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, 1, 2);
expect(result).toBeDefined();
expect(result!.scriptAccount).toEqual(scriptAccount)
expect(result!.minValue).toEqual(1);
expect(result!.maxValue).toEqual(2)
result = ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, -10, 2);
expect(result).toBeDefined();
expect(result!.scriptAccount).toEqual(scriptAccount)
expect(result!.minValue).toEqual(-10);
expect(result!.maxValue).toEqual(2)
result = ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, -20, -10);
expect(result).toBeDefined();
expect(result!.scriptAccount).toEqual(scriptAccount)
expect(result!.minValue).toEqual(-20);
expect(result!.maxValue).toEqual(-10)
})
});

View File

@ -0,0 +1,20 @@
import {ScriptAccount} from "../../scriptAccounts/ScriptAccount";
export class ScriptAccountCondition {
scriptAccount: ScriptAccount
minValue: number
maxValue: number
private constructor(scriptAccount: ScriptAccount, minValue: number, maxValue: number) {
this.scriptAccount = scriptAccount;
this.minValue = minValue;
this.maxValue = maxValue;
}
static constructScriptAccountCondition(scriptAccount: ScriptAccount, minValue: number, maxValue: number) {
if(scriptAccount == undefined || minValue == undefined || maxValue == undefined || minValue > maxValue) return undefined
return new ScriptAccountCondition(scriptAccount, minValue, maxValue)
}
}