Test triple ProductGamesystem generation
Some checks failed
E2E Testing / test (push) Failing after 1m22s

This commit is contained in:
Sebastian Böckelmann 2024-02-11 18:41:01 +01:00
parent 311b7ee7bb
commit e2cfe97b61
3 changed files with 29 additions and 6 deletions

View File

@ -23,5 +23,12 @@ test.describe('Test Create ProductStates', () => {
expect(gamesystem.transitions.length).toEqual(5); expect(gamesystem.transitions.length).toEqual(5);
}) })
test("Test simple triple Product State", async () => {
const gamesystem = ProductSystemGenerationTrainer.givenTrippleProductSystem();
gamesystem.generateFromChildsystems();
expect(gamesystem.states.length).toEqual(8);
expect(gamesystem.transitions.length).toEqual(19)
})
}); });

View File

@ -6,12 +6,16 @@ export class ProductSystemGenerationTrainer {
static PRODUCTGAMESYSTEMNAME = "ProductGamesystem"; static PRODUCTGAMESYSTEMNAME = "ProductGamesystem";
static CHILDGAMESYSTEMNAME_LEFT = "Left Child System"; static CHILDGAMESYSTEMNAME_LEFT = "Left Child System";
static CHILDGAMESYSTEMNAME_RIGHT = "Right Child System"; static CHILDGAMESYSTEMNAME_RIGHT = "Right Child System";
static CHILDGAMESYSTEMNAME_MIDDLE = "Middle Child System";
static LEFTCHILDSYSTEM_A_NODE_NAME = "A"; static LEFTCHILDSYSTEM_A_NODE_NAME = "A";
static LEFTCHILDSYSTEM_B_NODE_NAME = "B"; static LEFTCHILDSYSTEM_B_NODE_NAME = "B";
static RIGHTCHILDSYSTEM_A_NODE_NAME = "1"; static RIGHTCHILDSYSTEM_A_NODE_NAME = "1";
static RIGHTCHILDSYSTEM_B_NODE_NAME = "2"; static RIGHTCHILDSYSTEM_B_NODE_NAME = "2";
static MIDDLECHILDSYSTEM_A_NODE_NAME = "Sun";
static MIDDLECHILDSYSTEM_B_NODE_NAME = "Rain";
static givenSimplestProductSystem() { static givenSimplestProductSystem() {
const productsystem = new ProductGamesystem(ProductSystemGenerationTrainer.PRODUCTGAMESYSTEMNAME); const productsystem = new ProductGamesystem(ProductSystemGenerationTrainer.PRODUCTGAMESYSTEMNAME);
const left_childsystem = new SimpleGamesystem(ProductSystemGenerationTrainer.CHILDGAMESYSTEMNAME_LEFT); const left_childsystem = new SimpleGamesystem(ProductSystemGenerationTrainer.CHILDGAMESYSTEMNAME_LEFT);
@ -26,4 +30,14 @@ export class ProductSystemGenerationTrainer {
return productsystem; return productsystem;
} }
static givenTrippleProductSystem() {
const gamesystem = this.givenSimplestProductSystem();
const middle_childsystem = new SimpleGamesystem(this.CHILDGAMESYSTEMNAME_MIDDLE);
middle_childsystem.createTransition(middle_childsystem.createState(ProductSystemGenerationTrainer.MIDDLECHILDSYSTEM_A_NODE_NAME, "")!,
middle_childsystem.createState(ProductSystemGenerationTrainer.MIDDLECHILDSYSTEM_B_NODE_NAME, "")!);
gamesystem.addChildGamesystem(middle_childsystem);
return gamesystem;
}
} }

View File

@ -65,18 +65,21 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
generateFromChildsystems() { generateFromChildsystems() {
//Assume that childsystems that are productsystems are already generated //Assume that childsystems that are productsystems are already generated
let gamesystem: ProductGamesystem = ProductGamesystem.generateFromChildsystems(this.innerGamesystems[0], this.innerGamesystems[1], false); const integratedSystems: Gamesystem<any, any>[] = [this.innerGamesystems[0], this.innerGamesystems[1]];
let gamesystem: ProductGamesystem = ProductGamesystem.generateFromChildsystems(this.innerGamesystems[0], this.innerGamesystems[1], false, integratedSystems);
for(let i=2; i<this.innerGamesystems.length; i++) { for(let i=2; i<this.innerGamesystems.length; i++) {
gamesystem = ProductGamesystem.generateFromChildsystems(gamesystem, this.innerGamesystems[i], true); integratedSystems.push(this.innerGamesystems[i]);
gamesystem = ProductGamesystem.generateFromChildsystems(gamesystem, this.innerGamesystems[i], true, integratedSystems);
} }
this.states = gamesystem.states; this.states = gamesystem.states;
this.transitions = gamesystem.transitions; this.transitions = gamesystem.transitions;
} }
static generateFromChildsystems(leftSystem: Gamesystem<any, any>, rightSystem: Gamesystem<any, any>, left_temp: boolean) { static generateFromChildsystems(leftSystem: Gamesystem<any, any>, rightSystem: Gamesystem<any, any>, left_temp: boolean, integratedSystems: Gamesystem<any, any>[]) {
const productGamesystem = new ProductGamesystem("Temporary Gamesystem"); const productGamesystem = new ProductGamesystem("Temporary Gamesystem");
productGamesystem.addChildGamesystem(leftSystem); integratedSystems.forEach(integratedSystem => productGamesystem.addChildGamesystem(integratedSystem));
productGamesystem.addChildGamesystem(rightSystem);
leftSystem.states.forEach(leftState => { leftSystem.states.forEach(leftState => {
rightSystem.states.forEach(rightState => { rightSystem.states.forEach(rightState => {
for(let i=0; i<leftState.outgoingTransitions.length; i++) { for(let i=0; i<leftState.outgoingTransitions.length; i++) {
@ -106,7 +109,6 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
const transition = productGamesystem.createTransition(startingState, endingState); const transition = productGamesystem.createTransition(startingState, endingState);
} }
} }
}) })
}) })
return productGamesystem; return productGamesystem;