-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a bonus test for connection that reflects bugs in the current l…
…ogic
- Loading branch information
Kagamihara Nadeshiko
committed
Oct 2, 2023
1 parent
607e524
commit c3bf9b9
Showing
1 changed file
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import {App, InPort, OutPort, Reactor} from "../src/core/internal"; | ||
|
||
// Readers might wonder why this test case exist; | ||
// This is mainly because in the past, we assume direct feedthrough is forbidden, and will not establish the connection if we try to do so. However, it is possible that such a thing happen without introducing any causality issue. | ||
describe("Direct feedthrough without causality issue", () => { | ||
class BigReactor extends App { | ||
public children: SmallReactor; | ||
|
||
constructor() { | ||
super(undefined, false, false); | ||
this.children = new SmallReactor(this); | ||
} | ||
} | ||
|
||
class SmallReactor extends Reactor { | ||
public inp: InPort<number>; | ||
public outp: OutPort<number>; | ||
|
||
constructor(parent: Reactor) { | ||
super(parent); | ||
this.inp = new InPort(this); | ||
this.outp = new OutPort(this); | ||
this.addMutation( | ||
[this.startup], | ||
[this.inp, this.outp], | ||
function (this, inp, outp) { | ||
it("test", () => { | ||
expect(this.getReactor().canConnect(inp, outp)).toBeFalsy(); | ||
}); | ||
} | ||
); | ||
} | ||
} | ||
|
||
const root = new BigReactor(); | ||
root._start(); | ||
}); | ||
|
||
describe("Causality loop that can't be detected by only checking local graph", () => { | ||
class FeedThrougher extends Reactor { | ||
public inp = new InPort(this); | ||
public outp = new OutPort(this); | ||
|
||
constructor(parent: Reactor) { | ||
super(parent); | ||
this.addReaction( | ||
[this.inp], | ||
[this.inp, this.writable(this.outp)], | ||
function (this, inp, outp) { | ||
// nop troll | ||
} | ||
); | ||
} | ||
} | ||
|
||
class Looper extends Reactor { | ||
public leftChild = new FeedThrougher(this); | ||
public rightChild = new FeedThrougher(this); | ||
|
||
public inp = new InPort(this); | ||
public outp = new OutPort(this); | ||
|
||
constructor(parent: Reactor) { | ||
super(parent); | ||
this.addMutation( | ||
[this.startup], | ||
[ | ||
this.inp.asConnectable(), | ||
this.outp.asConnectable(), | ||
this.leftChild.inp.asConnectable(), | ||
this.leftChild.outp.asConnectable(), | ||
this.rightChild.inp.asConnectable(), | ||
this.rightChild.outp.asConnectable() | ||
], | ||
function (this, inp, outp, inp_lc, outp_lc, inp_rc, outp_rc) { | ||
this.connect(inp, inp_lc); | ||
this.connect(outp_rc, outp); | ||
} | ||
); | ||
} | ||
} | ||
|
||
class TestApp extends App { | ||
public child = new Looper(this); | ||
|
||
constructor() { | ||
super(undefined, undefined, undefined, () => { | ||
console.log(this._getPrecedenceGraph().toMermaidString()); | ||
}); | ||
this._connect(this.child.outp, this.child.inp); | ||
it("dummy test", () => { | ||
expect( | ||
this.canConnect(this.child.leftChild.outp, this.child.rightChild.inp) | ||
).toBeTruthy(); | ||
}); | ||
} | ||
} | ||
|
||
const app = new TestApp(); | ||
app._start(); | ||
}); |