issue-5-product-gamesystems #10
@ -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)
|
||||||
|
})
|
||||||
|
});
|
@ -1,6 +1,7 @@
|
|||||||
import {ProductGamesystem} from "../../../../src/app/game-model/gamesystems/ProductGamesystem";
|
import {ProductGamesystem} from "../../../../src/app/game-model/gamesystems/ProductGamesystem";
|
||||||
import {SimpleGamesystem} from "../../../../src/app/game-model/gamesystems/SimpleGamesystem";
|
import {SimpleGamesystem} from "../../../../src/app/game-model/gamesystems/SimpleGamesystem";
|
||||||
import {ProductState} from "../../../../src/app/game-model/gamesystems/ProductState";
|
import {ProductState} from "../../../../src/app/game-model/gamesystems/ProductState";
|
||||||
|
import {ProductTransition} from "../../../../src/app/game-model/gamesystems/ProductTransition";
|
||||||
|
|
||||||
export class ProductStateTrainer {
|
export class ProductStateTrainer {
|
||||||
static INNERSTATE_LETTER_1 = "A";
|
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_1]));
|
||||||
productGamesystem.states.push(new ProductState( [letter_2, number_2]));
|
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(letter_Gamesystem);
|
||||||
productGamesystem.innerGamesystems.push(number_gamesystem);
|
productGamesystem.innerGamesystems.push(number_gamesystem);
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import {Transition} from "./Transition";
|
|||||||
import {SimpleState} from "./SimpleState";
|
import {SimpleState} from "./SimpleState";
|
||||||
import {SimpleGamesystem} from "./SimpleGamesystem";
|
import {SimpleGamesystem} from "./SimpleGamesystem";
|
||||||
import {GameModel} from "../GameModel";
|
import {GameModel} from "../GameModel";
|
||||||
|
import {ProductStateTrainer} from "../../../../e2e/game-model/gamesystems/productGamesystems/ProductStateTrainer";
|
||||||
|
|
||||||
export class ProductGamesystem extends Gamesystem<ProductState, ProductTransition> {
|
export class ProductGamesystem extends Gamesystem<ProductState, ProductTransition> {
|
||||||
|
|
||||||
@ -44,9 +45,16 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
|
|||||||
}
|
}
|
||||||
|
|
||||||
createTransition(startingState: ProductState, endingState: ProductState): ProductTransition | undefined {
|
createTransition(startingState: ProductState, endingState: ProductState): ProductTransition | undefined {
|
||||||
|
if(startingState == undefined || endingState == undefined || this.existsTransition(startingState, endingState)
|
||||||
|
|| !this.existsState(startingState) || !this.existsState(endingState) || startingState.equals(endingState)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const productTransition = new ProductTransition(startingState, endingState);
|
||||||
|
this.transitions.push(productTransition);
|
||||||
|
return productTransition;
|
||||||
|
}
|
||||||
|
|
||||||
removeState(state: ProductState): boolean {
|
removeState(state: ProductState): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -80,4 +88,13 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
|
|||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private existsTransition(startingState: ProductState, endingState: ProductState) {
|
||||||
|
return this.transitions.find(transition =>
|
||||||
|
transition.startingState.equals(startingState) && transition.endingState.equals(endingState)) != undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
private existsState(state: ProductState) {
|
||||||
|
return this.states.find(s => s.equals(state)) != undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user