Skip to content

Commit

Permalink
Added mutation tests, unsure if they are correct
Browse files Browse the repository at this point in the history
  • Loading branch information
axmmisaka committed Oct 19, 2023
1 parent bd2290b commit bdfd1a3
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions __tests__/mutations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,101 @@ describe("Test the result from refactor-canconnect: referencing ConnectablePort
tapp._start();
});
});

/*
+-----------+ +------------------------+
| Useless | | +--------------+ |
| Reactor |------>--->| Mutation 1 | |
| | | +--------------+ |
+-----------+ | Mutation | |
| Holder \ |
| +--------v-----+ |
| | Mutation 2 | |
| +--------------+ |
+------------------------+
*/

describe("Mutation phase 1: a mutation should not be able to make connection that directly lays on their upstream", () => {
class MutationHolder extends Reactor {
public inport: InPort<number>;
public mut1inport: InPort<number>;
public mut2inport: InPort<number>;
public trigger: InPort<boolean>;

constructor(parent: Reactor) {
super(parent);

this.inport = new InPort(this);
this.mut1inport = new InPort(this);
this.mut2inport = new InPort(this);
this.trigger = new InPort(this);

// M1
this.addMutation(
[this.trigger, this.mut1inport],
[
this.inport.asConnectable(),
this.mut1inport.asConnectable(),
this.mut2inport.asConnectable()
],
function (this, inp, m1, m2) {
expect(() => {
this.connect(inp, m1);
}).toThrow();
expect(() => {
this.connect(inp, m2);
}).toReturn();
}
);

// M2
this.addMutation(
[this.trigger, this.mut2inport],
[
this.inport.asConnectable(),
this.mut1inport.asConnectable(),
this.mut2inport.asConnectable()
],
function (this, inp, m1, m2) {
expect(() => {
this.connect(inp, m1);
}).toThrow();
expect(() => {
this.connect(inp, m2);
}).toThrow();
}
);
}
}

class TestApp extends App {
public child = new MutationHolder(this);
public trigger = new OutPort<boolean>(this);

constructor(done: () => void) {
super(undefined, undefined, undefined, () => {
done();
});

this.addMutation(
[this.startup],
[this.trigger.asConnectable(), this.child.trigger.asConnectable()],
function (this, myTrigger, childTrigger) {
this.connect(myTrigger, childTrigger);
}
);
this.addReaction(
[this.startup],
[this.writable(this.trigger)],
function (this, trigger) {
trigger.set(true);
}
);
}
}

test("test mutation", (done) => {
const tapp = new TestApp(done);
tapp._start();
});
});

0 comments on commit bdfd1a3

Please sign in to comment.