Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Comments] Add comments to generic-related tests #222

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 135 additions & 9 deletions test/behavior/blueprint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ describe("A new blueprint", () => {
});

it("can have ports created and removed dynamically", () => {
// Test setup:
// [ -> [S2S] ]

// bpS2S ports:
// In: string
// Out: string
const bpS2S = landscapeModel.findBlueprint("ba24c37f-2b04-44b4-97ad-fd931c9ab77b")!;

const bpNew = landscapeModel.createBlueprint({
Expand All @@ -83,27 +83,58 @@ describe("A new blueprint", () => {
const bpPortIn = bpNew.getPortIn()!;
const opPortIn = opNew.getPortIn()!;

// The blueprint should look like this now:
// +---------------+
// | +-----+ |
// | O S2S | |
// | | | |
// | +-----+ |
// +---------------+

// We expect these types:
expect(bpPortIn.getTypeIdentifier()).toBe(TypeIdentifier.Unspecified);
expect(opPortIn.getTypeIdentifier()).toBe(TypeIdentifier.String);

// Now, connect in-port of the operator with in-port of the blueprint
opPortIn.connect(bpPortIn, true);

// The blueprint should look like this now:
// +---------------+
// | +-----+ |
// O--->O S2S | |
// | | | |
// | +-----+ |
// +---------------+

// So we expect 1 entry in the generic in-port map of the blueprint:
expect(Array.from(bpPortIn.getMapSubs()).length).toEqual(1);

// Fetch this automatically created in-port of the blueprint:
const newPort = bpPortIn.getMapSubs().next().value;

// Test if the connections are as expected (see ASCII sketch above)
expect(newPort.isConnectedWith(opPortIn)).toBeTruthy();
expect(opPortIn.isConnectedWith(newPort)).toBeTruthy();

// Disconnect the port now:
newPort.disconnectTo(opPortIn);

// The blueprint should look like this now:
// +---------------+
// | +-----+ |
// | O S2S | |
// | | | |
// | +-----+ |
// +---------------+

// And test if the automatically created in-port has vanished:
expect(Array.from(bpPortIn.getMapSubs()).length).toEqual(0);
});

it("can have blueprint ports removed when deleting connected operator", () => {
// Test setup:
// [ -> [S2S] ]

// bpS2S ports:
// In: string
// Out: string
const bpS2S = landscapeModel.findBlueprint("ba24c37f-2b04-44b4-97ad-fd931c9ab77b")!;

const bpNew = landscapeModel.createBlueprint({
Expand All @@ -119,26 +150,64 @@ describe("A new blueprint", () => {
const bpPortIn = bpNew.getPortIn()!;
const opPortIn = opNew.getPortIn()!;

// The blueprint should look like this now:
// +---------------+
// | +-----+ |
// | O S2S | |
// | | | |
// | +-----+ |
// +---------------+

// Now, connect in-port of the operator with in-port of the blueprint
opPortIn.connect(bpPortIn, true);

// The blueprint should look like this now:
// +---------------+
// | +-----+ |
// O--->O S2S | |
// | | | |
// | +-----+ |
// +---------------+

// So we expect 1 entry in the generic in-port map of the blueprint:
expect(Array.from(bpPortIn.getMapSubs()).length).toEqual(1);

// Fetch this automatically created in-port of the blueprint:
const newPort = bpPortIn.getMapSubs().next().value;

// Test if the connections are as expected (see ASCII sketch above)
expect(newPort.isConnectedWith(opPortIn)).toBeTruthy();
expect(opPortIn.isConnectedWith(newPort)).toBeTruthy();

// Now we remove the operator entirely:
opNew.destroy();

// The blueprint should look like this now:
// +---------------+
// | |
// | |
// | |
// | |
// +---------------+

// The port should no longer be connected
expect(newPort.isConnected()).toBeFalsy();

// And test if the automatically created in-port has vanished:
expect(Array.from(bpPortIn.getMapSubs()).length).toEqual(0);

// newPort still exists (because it is referenced in this test), but should be disconnected from any operator
});

it("can have generic operator ports created and removed dynamically", () => {
// Test setup:
// [S2S] -> [G2G] -> [S2S]

// bpS2S ports:
// In: string
// Out: string
const bpS2S = landscapeModel.findBlueprint("ba24c37f-2b04-44b4-97ad-fd931c9ab77b")!;

// bpG2G ports:
// In: Generic("itemType")
// Out: Generic("itemType")
const bpG2G = landscapeModel.findBlueprint("dc1aa556-d62e-4e07-adbb-53dc317481b0")!;

const bpNew = landscapeModel.createBlueprint({
Expand All @@ -151,25 +220,82 @@ describe("A new blueprint", () => {
const gens = new GenericSpecifications(["itemType"]);
const opG2G = bpNew.createOperator("g2g", bpG2G, new PropertyAssignments([].values(), gens), gens);

// The blueprint should look like this now:
// +--------------------------+
// | +-----+ +-----+ |
// | O S2S O | G2G | |
// | | 1 | | | |
// | +-----+ +-----+ |
// +--------------------------+

// Connect out-port of S2S1 with in-port of the generic operator:
opS2S1.getPortOut()!.connect(opG2G.getPortIn()!, true);

// The blueprint should look like this now:
// +--------------------------+
// | +-----+ +-----+ |
// | O S2S O--->O G2G O |
// | | 1 | | | |
// | +-----+ +-----+ |
// +--------------------------+

// We expect the generic operator to have an entry at its in- and out-ports:
expect(Array.from(opG2G.getPortIn()!.getMapSubs()).length).toBe(1);
expect(Array.from(opG2G.getPortOut()!.getMapSubs()).length).toBe(1);

// Create a second S2S operator:
const opS2S2 = bpNew.createBlankOperator(bpS2S);

// The blueprint should look like this now:
// +-------------------------------------+
// | +-----+ +-----+ +-----+ |
// | O S2S O--->O G2G O O S2S O |
// | | 1 | | | | 2 | |
// | +-----+ +-----+ +-----+ |
// +-------------------------------------+

// Connect in-port of the newly created S2S2 operator with the out-port of the generic operator:
opS2S2.getPortIn()!.connect(opG2G.getPortOut()!.getMapSubs().next().value, true);

// The blueprint should look like this now:
// +-------------------------------------+
// | +-----+ +-----+ +-----+ |
// | O S2S O--->O G2G O--->O S2S O |
// | | 1 | | | | 2 | |
// | +-----+ +-----+ +-----+ |
// +-------------------------------------+

// The generic operator remains unchanged:
expect(Array.from(opG2G.getPortIn()!.getMapSubs()).length).toBe(1);
expect(Array.from(opG2G.getPortOut()!.getMapSubs()).length).toBe(1);

// Disconnect connection between S2S1 and the generic operator:
opS2S1.getPortOut()!.disconnectTo(opG2G.getPortIn()!.getMapSubs().next().value);

// The blueprint should look like this now:
// +-------------------------------------+
// | +-----+ +-----+ +-----+ |
// | O S2S O O G2G O--->O S2S O |
// | | 1 | | | | 2 | |
// | +-----+ +-----+ +-----+ |
// +-------------------------------------+

// The generic operator remains unchanged, because its out-port is still connected to S2S2:
expect(Array.from(opG2G.getPortIn()!.getMapSubs()).length).toBe(1);
expect(Array.from(opG2G.getPortOut()!.getMapSubs()).length).toBe(1);

// Now also disconnect the second connection:
opG2G.getPortOut()!.getMapSubs().next().value.disconnectTo(opS2S2.getPortIn()!);

// The blueprint should look like this now:
// +-------------------------------------+
// | +-----+ +-----+ +-----+ |
// | O S2S O | G2G | O S2S O |
// | | 1 | | | | 2 | |
// | +-----+ +-----+ +-----+ |
// +-------------------------------------+

// Now that G2G is no longer connected at all its ports should have vanished:
expect(Array.from(opG2G.getPortIn()!.getMapSubs()).length).toBe(0);
expect(Array.from(opG2G.getPortOut()!.getMapSubs()).length).toBe(0);
});
Expand Down
66 changes: 66 additions & 0 deletions test/behavior/port.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ describe("A port", () => {
});

it("can be generated and deleted automatically", () => {
// bpS2S ports:
// In: string
// Out: string
const bpS2S = landscapeModel.findBlueprint("ba24c37f-2b04-44b4-97ad-fd931c9ab77b")!;

// bpG2G ports:
// In: Generic("itemType")
// Out: Generic("itemType")
const bpG2G = landscapeModel.findBlueprint("dc1aa556-d62e-4e07-adbb-53dc317481b0")!;

const bpNew2 = landscapeModel.createBlueprint({
Expand All @@ -51,20 +58,79 @@ describe("A port", () => {
const opS2S2 = bpNew2.createBlankOperator(bpS2S);
const opG2G = bpNew2.createBlankOperator(bpG2G);

// Connect out-port of first S2S operator with generic in-port of the G2G operator
opS2S1.getPortOut()!.connect(opG2G.getPortIn()!, true);

// The blueprint should look like this now:
// +-------------------------------+
// | +---+ +---+ +---+ |
// | |S2S|--->|G2G| |S2S| |
// | | 1 | | | | 2 | |
// | +---+ +---+ +---+ |
// +-------------------------------+

// We expect the generic in-port to have a map now with one entry:
expect(Array.from(opG2G.getPortIn()!.getMapSubs()).length).toEqual(1);

// The out-port of the generic operator should have one entry as well which is fetched here:
const generatedPortOut = opG2G.getPortOut()!.getMapSubs().next().value;

// Now, connect out-port of S2S 1 with in-port of the generic operator again
opS2S1.getPortOut()!.connect(opG2G.getPortIn()!, true);

// The blueprint should look like this now:
// +-------------------------------+
// | +---+ +---+ +---+ |
// | |S2S|-+->|G2G| |S2S| |
// | | 1 | | | | | 2 | |
// | | | +->| | | | |
// | +---+ +---+ +---+ |
// +-------------------------------+

// So we expect two entries in the in-port map now:
expect(Array.from(opG2G.getPortIn()!.getMapSubs()).length).toEqual(2);

// Connect the out-port originating from the first connect with the in-port of the second S2S operator:
generatedPortOut.connect(opS2S2.getPortIn()!, true);

// The blueprint should look like this now:
// +-------------------------------+
// | +---+ +---+ +---+ |
// | |S2S|-+->|G2G|--->|S2S| |
// | | 1 | | | | | 2 | |
// | | | +->| | | | |
// | +---+ +---+ +---+ |
// +-------------------------------+

// Now, we disconnect all connections of the out-port of the first S2S operator
opS2S1.getPortOut()!.disconnectAll();

// The blueprint should look like this now:
// +-------------------------------+
// | +---+ +---+ +---+ |
// | |S2S| |G2G|--->|S2S| |
// | | 1 | | | | 2 | |
// | | | | | | | |
// | +---+ +---+ +---+ |
// +-------------------------------+

// So the generic map should only have 1 remaining port,
// the second should have been deleted because it has not been connected:
expect(Array.from(opG2G.getPortIn()!.getMapSubs()).length).toEqual(1);

// Now, also disonnect the remaining entry:
generatedPortOut.disconnectAll();

// The blueprint should look like this now:
// +-------------------------------+
// | +---+ +---+ +---+ |
// | |S2S| |G2G| |S2S| |
// | | 1 | | | | 2 | |
// | | | | | | | |
// | +---+ +---+ +---+ |
// +-------------------------------+

// So the map has zero entries now:
expect(Array.from(opG2G.getPortIn()!.getMapSubs()).length).toEqual(0);
});

Expand Down
Loading