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

Remove Present and replace with unknown; remove Args and Trigger and use TS Tuple #168

Merged
merged 13 commits into from
Jul 1, 2023
14 changes: 6 additions & 8 deletions __tests__/ActionTrigger.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type {Sched} from "../src/core/internal";
import {
App,
Triggers,
Args,
Origin,
TimeValue,
Reactor,
Expand All @@ -25,8 +23,8 @@ export class ActionTrigger extends Reactor {
super(parent);
// Reaction priorities matter here. The overridden reaction must go first.
this.addReaction(
new Triggers(this.t1),
new Args(this.schedulable(this.a1)),
[this.t1],
[this.schedulable(this.a1)],
/**
* Schedule the incorrect payload for action a1.
*/
Expand All @@ -39,8 +37,8 @@ export class ActionTrigger extends Reactor {
);

this.addReaction(
new Triggers(this.t1),
new Args(this.schedulable(this.a1), this.a2),
[this.t1],
[this.schedulable(this.a1), this.a2],
/**
* Schedule the correct payload for action a1.
*/
Expand All @@ -53,8 +51,8 @@ export class ActionTrigger extends Reactor {
);

this.addReaction(
new Triggers(this.a1),
new Args(this.a1, this.a2),
[this.a1],
[this.a1, this.a2],
/**
* If the action payload is correct, test is successful. Otherwise it fails.
* Since a2 was not scheduled it should return null on a call to get() and
Expand Down
17 changes: 5 additions & 12 deletions __tests__/Adder.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import type {IOPort, Present} from "../src/core/internal";
import {
App,
Reactor,
Args,
Triggers,
InPort,
OutPort
} from "../src/core/internal";
import type {IOPort} from "../src/core/internal";
import {App, Reactor, InPort, OutPort} from "../src/core/internal";

export class Adder extends Reactor {
in1 = new InPort<number>(this);
Expand All @@ -19,8 +12,8 @@ export class Adder extends Reactor {
super(parent);

this.addReaction(
new Triggers(this.in1, this.in2),
new Args(this.in1, this.in2, this.writable(this.out)),
[this.in1, this.in2],
[this.in1, this.in2, this.writable(this.out)],
function (this, in1, in2, out) {
// Type assertions allow coercion of null to 0.
out.set((in1.get() as number) + (in2.get() as number));
Expand All @@ -36,7 +29,7 @@ class MyAdder extends Adder {
}
}

public getProxy(port: IOPort<Present>) {
public getProxy(port: IOPort<unknown>) {
return this.writable(port);
}
}
Expand Down
28 changes: 7 additions & 21 deletions __tests__/CausalityGraph.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
import {
Reactor,
App,
Triggers,
Args,
Timer,
OutPort,
InPort,
TimeUnit,
TimeValue,
Origin,
Log,
LogLevel,
Action
} from "../src/core/internal";
import {Reactor, App, OutPort, InPort} from "../src/core/internal";

/* Set a port in startup to get thing going */
class Starter extends Reactor {
Expand All @@ -23,8 +9,8 @@ class Starter extends Reactor {
constructor(parent: Reactor | null) {
super(parent);
this.addReaction(
new Triggers(this.in),
new Args(this.in, this.writable(this.out)),
[this.in],
[this.in, this.writable(this.out)],
function (this, __in, __out) {
__out.set(4);
}
Expand All @@ -40,8 +26,8 @@ class R1 extends Reactor {
constructor(parent: Reactor | null) {
super(parent);
this.addReaction(
new Triggers(this.in),
new Args(this.in, this.writable(this.out)),
[this.in],
[this.in, this.writable(this.out)],
function (this, __in, __out) {
const tmp = __in.get();
let out = 0;
Expand All @@ -64,8 +50,8 @@ class R2 extends Reactor {
constructor(parent: Reactor | null) {
super(parent);
this.addReaction(
new Triggers(this.in),
new Args(this.in, this.writable(this.out)),
[this.in],
[this.in, this.writable(this.out)],
function (this, __in, __out) {
const tmp = __in.get();
const out = 0;
Expand Down
18 changes: 8 additions & 10 deletions __tests__/Clock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
Action,
Timer,
App,
Triggers,
Args,
TimeValue,
TimeUnit,
Origin
Expand Down Expand Up @@ -40,8 +38,8 @@ export class Clock extends App {
constructor(timeout: TimeValue, success: () => void, fail: () => void) {
super(timeout, false, false, success, fail);
this.addReaction(
new Triggers(this.t1),
new Args(this.schedulable(this.a1)),
[this.t1],
[this.schedulable(this.a1)],
/**
* Print tick and schedule a1
*/
Expand All @@ -51,8 +49,8 @@ export class Clock extends App {
}
);
this.addReaction(
new Triggers(this.t2),
new Args(this.schedulable(this.a2)),
[this.t2],
[this.schedulable(this.a2)],
/**
* Print tock and schedule a2.
*/
Expand All @@ -65,8 +63,8 @@ export class Clock extends App {
// simultaneosly by both timers, "Cuckoo" should only
// print once.
this.addReaction(
new Triggers(this.t1, this.t2),
new Args(this.schedulable(this.a3)),
[this.t1, this.t2],
[this.schedulable(this.a3)],
/**
* Print cuckoo and schedule a3.
*/
Expand All @@ -76,8 +74,8 @@ export class Clock extends App {
}
);
this.addReaction(
new Triggers(this.a1, this.a2, this.a3),
new Args(this.a1, this.a2, this.a3),
[this.a1, this.a2, this.a3],
[this.a1, this.a2, this.a3],
/**
* If all the actions are available at logical time 5 seconds from start, the test is successful.
*/
Expand Down
30 changes: 7 additions & 23 deletions __tests__/InvalidMutations.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
import {
Reactor,
State,
Bank,
App,
Triggers,
Args,
Timer,
OutPort,
InPort,
TimeUnit,
TimeValue,
Origin,
Log,
LogLevel,
Action
} from "../src/core/internal";
import {Reactor, App, OutPort, InPort} from "../src/core/internal";

class Starter extends Reactor {
public out = new OutPort<number>(this);

constructor(parent: Reactor | null) {
super(parent);
this.addReaction(
new Triggers(this.startup),
new Args(this.writable(this.out)),
[this.startup],
[this.writable(this.out)],
function (this, __out) {
__out.set(4);
}
Expand All @@ -43,16 +27,16 @@ class R1 extends Reactor {
constructor(parent: Reactor | null) {
super(parent);
this.addReaction(
new Triggers(this.in1),
new Args(this.in1, this.writable(this.out1)),
[this.in1],
[this.in1, this.writable(this.out1)],
function (this, __in, __out) {
__out.set(4);
}
);

this.addMutation(
new Triggers(this.in1),
new Args(this.in1, this.in2, this.out1, this.out2),
[this.in1],
[this.in1, this.in2, this.out1, this.out2],
function (this, __in1, __in2, __out1, __out2) {
test("expect error on creating creating direct feed through", () => {
expect(() => {
Expand Down
13 changes: 3 additions & 10 deletions __tests__/OutputEvent.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
App,
Reactor,
Parameter,
Args,
Triggers,
TimeValue
} from "../src/core/internal";
import {App, Reactor, Parameter, TimeValue} from "../src/core/internal";
import {SingleEvent} from "../src/share/SingleEvent";

/**
Expand All @@ -18,8 +11,8 @@ export class OutputResponder extends Reactor {
constructor(__parent__: Reactor) {
super(__parent__);
this.addReaction(
new Triggers(this.se.o),
new Args(),
[this.se.o],
[],
/**
* If this reaction is triggered by an output event from the contained reactor,
* succeed the test.
Expand Down
41 changes: 14 additions & 27 deletions __tests__/OutputGet.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import {
App,
Timer,
Write,
Triggers,
Args,
OutPort,
TimeValue,
Log
} from "../src/core/internal";
import {App, Timer, OutPort, TimeValue, Log} from "../src/core/internal";

class OutputGetTest extends App {
o: OutPort<number> = new OutPort<number>(this);
Expand All @@ -22,24 +13,20 @@ class OutputGetTest extends App {
) {
super(timeout, true, false, success, failure);
Log.global.debug(">>>>>>>>----" + this.util);
this.addReaction(
new Triggers(this.t),
new Args(this.writable(this.o)),
function (this, o) {
Log.global.debug(">>>>>>>>>>being triggered>>>>>>>>>>>");
if (o.get() != null) {
throw new Error(
"Calling get on an output before it has been set does not return null"
);
}
o.set(5);
if (o.get() !== 5) {
throw new Error(
"Calling get on an output after it has been set does not return the set value"
);
}
this.addReaction([this.t], [this.writable(this.o)], function (this, o) {
Log.global.debug(">>>>>>>>>>being triggered>>>>>>>>>>>");
if (o.get() != null) {
throw new Error(
"Calling get on an output before it has been set does not return null"
);
}
);
o.set(5);
if (o.get() !== 5) {
throw new Error(
"Calling get on an output after it has been set does not return the set value"
);
}
});
}
}

Expand Down
28 changes: 7 additions & 21 deletions __tests__/SimpleMutation.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
import {
Reactor,
App,
Triggers,
Args,
Timer,
OutPort,
InPort,
TimeUnit,
TimeValue,
Origin,
Log,
LogLevel,
Action
} from "../src/core/internal";
import {Reactor, App, OutPort, InPort} from "../src/core/internal";

/* Set a port in startup to get thing going */
class Starter extends Reactor {
Expand All @@ -21,8 +7,8 @@ class Starter extends Reactor {
constructor(parent: Reactor | null) {
super(parent);
this.addReaction(
new Triggers(this.startup),
new Args(this.writable(this.out)),
[this.startup],
[this.writable(this.out)],
function (this, __out) {
__out.set(4);
}
Expand All @@ -38,8 +24,8 @@ class R1 extends Reactor {
constructor(parent: Reactor | null) {
super(parent);
this.addReaction(
new Triggers(this.in),
new Args(this.in, this.writable(this.out)),
[this.in],
[this.in, this.writable(this.out)],
function (this, __in, __out) {
__out.set(4);
}
Expand All @@ -55,8 +41,8 @@ class R2 extends Reactor {
constructor(parent: Reactor | null) {
super(parent);
this.addMutation(
new Triggers(this.in),
new Args(this.in, this.out),
[this.in],
[this.in, this.out],
function (this, __in, __out) {
test("expect error to be thrown", () => {
expect(() => {
Expand Down
Loading