From 57d7babf7128ba85b27f5103f6c96487abe6d9d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sat, 10 Feb 2024 17:37:05 +0100 Subject: [PATCH] Test ProductStateTransition Creation --- .../CreateProductTransitions.spec.ts | 51 +++++++++++++++++++ .../productGamesystems/ProductStateTrainer.ts | 5 ++ .../gamesystems/ProductGamesystem.ts | 19 ++++++- 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 e2e/game-model/gamesystems/productGamesystems/CreateProductTransitions.spec.ts diff --git a/e2e/game-model/gamesystems/productGamesystems/CreateProductTransitions.spec.ts b/e2e/game-model/gamesystems/productGamesystems/CreateProductTransitions.spec.ts new file mode 100644 index 0000000..fc7dcab --- /dev/null +++ b/e2e/game-model/gamesystems/productGamesystems/CreateProductTransitions.spec.ts @@ -0,0 +1,51 @@ +import { test, expect } from '@playwright/test'; +import {ProductStateTrainer} from "./ProductStateTrainer"; +import {ProductState} from "../../../../src/app/game-model/gamesystems/ProductState"; +import {SimpleGamesystem} from "../../../../src/app/game-model/gamesystems/SimpleGamesystem"; +test.describe('Test Create ProductTransitions', () => { + test("Test ProductTransition Creation with invalid inputs", async ()=> { + const gamesystem = ProductStateTrainer.givenFullProductGamesystemWithTwoStates(); + expect(gamesystem.createTransition(null, null)).toBeUndefined(); + expect(gamesystem.transitions.length).toEqual(3); + expect(gamesystem.createTransition(undefined, undefined)).toBeUndefined(); + expect(gamesystem.transitions.length).toEqual(3); + + expect(gamesystem.createTransition(undefined, gamesystem.states[0])).toBeUndefined(); + expect(gamesystem.transitions.length).toEqual(3); + expect(gamesystem.createTransition(null, gamesystem.states[0])).toBeUndefined(); + expect(gamesystem.transitions.length).toEqual(3); + + expect(gamesystem.createTransition(gamesystem.states[0], undefined)).toBeUndefined(); + expect(gamesystem.transitions.length).toEqual(3); + expect(gamesystem.createTransition(gamesystem.states[0], null)).toBeUndefined(); + expect(gamesystem.transitions.length).toEqual(3); + }) + + test("Test ProductTransitition Creation with duplicate Transition", async ()=> { + const gamesystem = ProductStateTrainer.givenFullProductGamesystemWithTwoStates(); + expect(gamesystem.createTransition(gamesystem.states[0], gamesystem.states[1])).toBeUndefined(); + }) + + test("Test ProductTransition Creation with foreign States", async () => { + const simpleGamesystems: SimpleGamesystem[] = [new SimpleGamesystem("Test", "Test"), new SimpleGamesystem("Test1", "Test2")]; + const simpleGamesystem2: SimpleGamesystem[] = [new SimpleGamesystem("Test3", "Test"), new SimpleGamesystem("Test4", "Test2")]; + const gamesystem = ProductStateTrainer.givenFullProductGamesystemWithTwoStates(); + const foreignProductState = new ProductState(simpleGamesystems); + const foreignEndProductState = new ProductState(simpleGamesystem2); + + expect(gamesystem.createTransition(foreignProductState, foreignEndProductState)).toBeUndefined(); + expect(gamesystem.transitions.length).toEqual(3); + }) + + test("Test creating SelfTransitions", async ()=> { + const gamesystem = ProductStateTrainer.givenFullProductGamesystemWithTwoStates(); + expect(gamesystem.createTransition(gamesystem.states[0], gamesystem.states[0])).toBeUndefined(); + expect(gamesystem.transitions.length).toEqual(3); + }) + + test("Test Valid Transition Creation", async () => { + const gamesystem = ProductStateTrainer.givenFullProductGamesystemWithTwoStates(); + expect(gamesystem.createTransition(gamesystem.states[1], gamesystem.states[2])).toBeDefined(); + expect(gamesystem.transitions.length).toEqual(4) + }) +}); diff --git a/e2e/game-model/gamesystems/productGamesystems/ProductStateTrainer.ts b/e2e/game-model/gamesystems/productGamesystems/ProductStateTrainer.ts index 9c55c46..90ef6a1 100644 --- a/e2e/game-model/gamesystems/productGamesystems/ProductStateTrainer.ts +++ b/e2e/game-model/gamesystems/productGamesystems/ProductStateTrainer.ts @@ -1,6 +1,7 @@ import {ProductGamesystem} from "../../../../src/app/game-model/gamesystems/ProductGamesystem"; import {SimpleGamesystem} from "../../../../src/app/game-model/gamesystems/SimpleGamesystem"; import {ProductState} from "../../../../src/app/game-model/gamesystems/ProductState"; +import {ProductTransition} from "../../../../src/app/game-model/gamesystems/ProductTransition"; export class ProductStateTrainer { static INNERSTATE_LETTER_1 = "A"; @@ -28,6 +29,10 @@ export class ProductStateTrainer { productGamesystem.states.push(new ProductState( [letter_2, number_1])); productGamesystem.states.push(new ProductState( [letter_2, number_2])); + productGamesystem.transitions.push(new ProductTransition(productGamesystem.states[0], productGamesystem.states[1])) + productGamesystem.transitions.push(new ProductTransition(productGamesystem.states[0], productGamesystem.states[2])) + productGamesystem.transitions.push(new ProductTransition(productGamesystem.states[0], productGamesystem.states[3])) + productGamesystem.innerGamesystems.push(letter_Gamesystem); productGamesystem.innerGamesystems.push(number_gamesystem); diff --git a/src/app/game-model/gamesystems/ProductGamesystem.ts b/src/app/game-model/gamesystems/ProductGamesystem.ts index 46db3d5..0c8c30c 100644 --- a/src/app/game-model/gamesystems/ProductGamesystem.ts +++ b/src/app/game-model/gamesystems/ProductGamesystem.ts @@ -6,6 +6,7 @@ import {Transition} from "./Transition"; import {SimpleState} from "./SimpleState"; import {SimpleGamesystem} from "./SimpleGamesystem"; import {GameModel} from "../GameModel"; +import {ProductStateTrainer} from "../../../../e2e/game-model/gamesystems/productGamesystems/ProductStateTrainer"; export class ProductGamesystem extends Gamesystem { @@ -44,7 +45,14 @@ export class ProductGamesystem extends Gamesystem + transition.startingState.equals(startingState) && transition.endingState.equals(endingState)) != undefined; + } + + private existsState(state: ProductState) { + return this.states.find(s => s.equals(state)) != undefined; + } }