Check if conditions are contradicting each other
All checks were successful
E2E Testing / test (push) Successful in 1m38s
All checks were successful
E2E Testing / test (push) Successful in 1m38s
This commit is contained in:
parent
4a1f4e4c52
commit
75a4122641
@ -0,0 +1,43 @@
|
||||
|
||||
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";
|
||||
import {Conditional} from "@angular/compiler";
|
||||
test.describe('Test Contradicting Conditions', () => {
|
||||
|
||||
test("Test contradicting conditions", async () => {
|
||||
const condition = ConditionTrainer.withSimpleCondition();
|
||||
|
||||
let contradictingCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.maxValue + 10, condition.maxValue+200);
|
||||
expect(condition.isContradicting(contradictingCondition)).toBeTruthy();
|
||||
|
||||
contradictingCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-100, condition.minValue-50);
|
||||
expect(condition.isContradicting(contradictingCondition)).toBeTruthy();
|
||||
})
|
||||
|
||||
test("Test intersecting conditions", async () => {
|
||||
const condition = ConditionTrainer.withSimpleCondition();
|
||||
let otherCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-1, condition.minValue+1);
|
||||
expect(condition.isContradicting(otherCondition)).toBeFalsy();
|
||||
|
||||
otherCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.maxValue-1, condition.maxValue+1);
|
||||
expect(condition.isContradicting(otherCondition)).toBeFalsy();
|
||||
|
||||
otherCondition = ScriptAccountCondition.constructScriptAccountCondition(condition.scriptAccount, condition.minValue-1, condition.maxValue+1);
|
||||
expect(condition.isContradicting(otherCondition)).toBeFalsy();
|
||||
|
||||
expect(condition.isContradicting(condition)).toBeFalsy();
|
||||
})
|
||||
|
||||
test("Test contradicting conditions with different ScriptAccount", async () => {
|
||||
const condition = ConditionTrainer.withSimpleCondition();
|
||||
const otherCondition = ScriptAccountCondition.constructScriptAccountCondition(
|
||||
new ScriptAccount("Another test", ""), condition.minValue-20, condition.minValue-10);
|
||||
|
||||
expect(condition.isContradicting(otherCondition)).toBeFalsy();
|
||||
})
|
||||
|
||||
|
||||
});
|
14
e2e/game-model/gamesystems/conditions/ConditionTrainer.ts
Normal file
14
e2e/game-model/gamesystems/conditions/ConditionTrainer.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import {ScriptAccount} from "../../../../src/app/game-model/scriptAccounts/ScriptAccount";
|
||||
import {ScriptAccountCondition} from "../../../../src/app/game-model/gamesystems/conditions/ScriptAccountCondition";
|
||||
|
||||
export class ConditionTrainer {
|
||||
static withSimpleCondition(): ScriptAccountCondition {
|
||||
const scriptAccount = new ScriptAccount("Test", "");
|
||||
return ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, 0, 10);
|
||||
}
|
||||
|
||||
static withSimpleOtherCondition(): ScriptAccountCondition {
|
||||
const scriptAccount = new ScriptAccount("Another Test", "");
|
||||
return ScriptAccountCondition.constructScriptAccountCondition(scriptAccount, 0, 10);
|
||||
}
|
||||
}
|
@ -16,5 +16,14 @@ export class ScriptAccountCondition {
|
||||
return new ScriptAccountCondition(scriptAccount, minValue, maxValue)
|
||||
}
|
||||
|
||||
extendCondition(condition: ScriptAccountCondition) {
|
||||
|
||||
}
|
||||
|
||||
isContradicting(condition: ScriptAccountCondition) {
|
||||
return condition.scriptAccount === this.scriptAccount &&
|
||||
(this.maxValue < condition.minValue || this.minValue > condition.maxValue)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
import {State} from "../states/State";
|
||||
import {ScriptAccountAction} from "../actions/ScriptAccountAction";
|
||||
import {ScriptAccount} from "../../scriptAccounts/ScriptAccount";
|
||||
import {ScriptAccountCondition} from "../conditions/ScriptAccountCondition";
|
||||
|
||||
export abstract class Transition<S extends State<any>> {
|
||||
startingState: S
|
||||
endingState: S
|
||||
|
||||
scriptAccountActions: ScriptAccountAction[] = [];
|
||||
scriptAccountConditions: ScriptAccountCondition[] = [];
|
||||
|
||||
constructor(startingState: S, endingState: S) {
|
||||
this.startingState = startingState;
|
||||
@ -36,4 +38,16 @@ export abstract class Transition<S extends State<any>> {
|
||||
findScriptAccountActionByScriptAccount(scriptAccount: ScriptAccount) {
|
||||
return this.scriptAccountActions.find(sA => sA.scriptAccount.componentName === scriptAccount.componentName);
|
||||
}
|
||||
|
||||
addScriptAccountCondition(scriptAccountCondition: ScriptAccountCondition) {
|
||||
|
||||
}
|
||||
|
||||
removeScriptAccountCondition(scriptAccount: ScriptAccount) {
|
||||
|
||||
}
|
||||
|
||||
findScriptAccountConditionByScriptAccount(scriptAccount: ScriptAccount) {
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user