-
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.
Merge branch 'master' into schedule-properly
- Loading branch information
Showing
11 changed files
with
1,082 additions
and
498 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,90 @@ | ||
import { Reactor, App, Triggers, Args, Timer, OutPort, InPort, TimeUnit, TimeValue, Origin, Log, LogLevel, Action } from '../src/core/internal'; | ||
|
||
/* Set a port in startup to get thing going */ | ||
class Starter extends Reactor { | ||
public in = new InPort<number>(this); | ||
public out = new OutPort<number>(this); | ||
|
||
constructor(parent: Reactor|null) { | ||
super(parent); | ||
this.addReaction( | ||
new Triggers(this.in), | ||
new Args(this.in, this.writable(this.out)), | ||
function(this, __in, __out) { | ||
__out.set(4); | ||
|
||
} | ||
); | ||
} | ||
} | ||
|
||
class R1 extends Reactor { | ||
public in = new InPort<number>(this); | ||
public out = new OutPort<number>(this); | ||
|
||
constructor(parent: Reactor|null) { | ||
super(parent); | ||
this.addReaction( | ||
new Triggers(this.in), | ||
new Args(this.in, this.writable(this.out)), | ||
function(this, __in, __out) { | ||
let tmp = __in.get() | ||
let out:number = 0 | ||
if (tmp) { | ||
out = tmp - 1; | ||
} | ||
if (out) { | ||
__out.set(out) | ||
} | ||
} | ||
) | ||
} | ||
} | ||
|
||
class R2 extends Reactor { | ||
public in = new InPort<number>(this); | ||
public out = new OutPort<number>(this); | ||
|
||
constructor(parent: Reactor|null) { | ||
super(parent); | ||
this.addReaction( | ||
new Triggers(this.in), | ||
new Args(this.in, this.writable(this.out)), | ||
function(this, __in, __out) { | ||
let tmp = __in.get() | ||
let out:number = 0; | ||
if(tmp && tmp == 0) { | ||
this.util.requestStop | ||
} else { | ||
if (tmp) { | ||
__out.set(tmp - 1) | ||
} | ||
} | ||
} | ||
) | ||
} | ||
} | ||
|
||
class testApp extends App { | ||
start: Starter | ||
reactor1: R1; | ||
reactor2: R2; | ||
|
||
constructor () { | ||
super(); | ||
this.start = new Starter(this); | ||
this.reactor1 = new R1(this); | ||
this.reactor2 = new R2(this); | ||
this._connect(this.start.out, this.reactor1.in) | ||
this._connect(this.reactor1.out, this.reactor2.in) | ||
// this tests the accuracy of the CausalityGraph used in the connect function | ||
test('test if adding cyclic dependency is caught', () => { | ||
expect(() => { | ||
this._connect(this.reactor2.out, this.start.in) | ||
}).toThrowError("New connection introduces cycle.") | ||
}) | ||
} | ||
} | ||
|
||
var app = new testApp() | ||
app._start() |
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,80 @@ | ||
import { Reactor, State, Bank, App, Triggers, Args, Timer, OutPort, InPort, TimeUnit, TimeValue, Origin, Log, LogLevel, Action } 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)), | ||
function(this, __out) { | ||
__out.set(4); | ||
|
||
} | ||
); | ||
} | ||
|
||
} | ||
|
||
class R1 extends Reactor { | ||
public in1 = new InPort<number>(this); | ||
public in2 = new InPort<number>(this); | ||
public out1 = new OutPort<number>(this); | ||
public out2 = new OutPort<number>(this); | ||
|
||
constructor(parent: Reactor|null) { | ||
super(parent); | ||
this.addReaction( | ||
new Triggers(this.in1), | ||
new Args(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), | ||
function(this, __in1, __in2, __out1, __out2) { | ||
test('expect error on creating creating direct feed through', () => { | ||
expect(() => { | ||
this.connect(__in2, __out2) | ||
}).toThrowError("New connection introduces direct feed through.") | ||
}) | ||
test('expect error when creating connection outside container', () => { | ||
expect(() => { | ||
this.connect(__out2, __in2) | ||
}).toThrowError("New connection is outside of container.") | ||
}) | ||
let R2 = new R1(this.getReactor()) | ||
test('expect error on mutation creating race condition on an output port', () => { | ||
expect(() => { | ||
this.connect(R2.out1, __out1) | ||
}).toThrowError("Destination port is already occupied.") | ||
}) | ||
test('expect error on spawning and creating loop within a reactor', () => { | ||
expect(() => { | ||
this.connect(R2.out1, R2.in1) | ||
}).toThrowError("New connection introduces cycle.") | ||
}) | ||
} | ||
) | ||
} | ||
|
||
} | ||
|
||
class testApp extends App { | ||
start: Starter | ||
reactor1: R1; | ||
|
||
constructor () { | ||
super(); | ||
this.start = new Starter(this); | ||
this.reactor1 = new R1(this); | ||
this._connect(this.start.out, this.reactor1.in1) | ||
} | ||
} | ||
|
||
var app = new testApp() | ||
app._start() |
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,78 @@ | ||
import { Reactor, App, Triggers, Args, Timer, OutPort, InPort, TimeUnit, TimeValue, Origin, Log, LogLevel, Action } from '../src/core/internal'; | ||
|
||
/* Set a port in startup to get thing going */ | ||
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)), | ||
function(this, __out) { | ||
__out.set(4); | ||
|
||
} | ||
); | ||
} | ||
|
||
} | ||
|
||
class R1 extends Reactor { | ||
public in = new InPort<number>(this); | ||
public out = new OutPort<number>(this); | ||
|
||
constructor(parent: Reactor|null) { | ||
super(parent); | ||
this.addReaction( | ||
new Triggers(this.in), | ||
new Args(this.in, this.writable(this.out)), | ||
function(this, __in, __out) { | ||
__out.set(4) | ||
} | ||
) | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
class R2 extends Reactor { | ||
public in = new InPort<number>(this); | ||
public out = new OutPort<number>(this); | ||
|
||
constructor(parent: Reactor|null) { | ||
super(parent); | ||
this.addMutation( | ||
new Triggers(this.in), | ||
new Args(this.in, this.out), | ||
function(this, __in, __out) { | ||
test('expect error to be thrown', () => { | ||
expect(() => { | ||
this.connect(__out, __in) | ||
}).toThrowError("New connection is outside of container.") | ||
}) | ||
} | ||
) | ||
} | ||
|
||
} | ||
|
||
|
||
class testApp extends App { | ||
start: Starter | ||
reactor1: R1; | ||
reactor2: R2; | ||
|
||
constructor () { | ||
super(); | ||
this.start = new Starter(this); | ||
this.reactor1 = new R1(this); | ||
this.reactor2 = new R2(this); | ||
this._connect(this.start.out, this.reactor1.in) | ||
this._connect(this.reactor1.out, this.reactor2.in) | ||
} | ||
} | ||
|
||
var app = new testApp() | ||
app._start() |
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
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,69 @@ | ||
import { Reactor, State, Bank, App, Triggers, Args, Timer, OutPort, InPort, TimeUnit, TimeValue, Origin, Log, LogLevel, Action } 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)), | ||
function(this, __out) { | ||
__out.set(4); | ||
|
||
} | ||
); | ||
} | ||
|
||
} | ||
|
||
class R1 extends Reactor { | ||
public in1 = new InPort<number>(this); | ||
public in2 = new InPort<number>(this); | ||
public out1 = new OutPort<number>(this); | ||
public out2 = new OutPort<number>(this); | ||
|
||
constructor(parent: Reactor|null) { | ||
super(parent); | ||
this.addReaction( | ||
new Triggers(this.in1), | ||
new Args(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.out2), | ||
function(this, __in1, __in2, __out2) { | ||
let R2 = new R1(this.getReactor()) | ||
test('expect that disconnecting an existing connection will not result in an error being thrown', () => { | ||
expect(() => { | ||
this.connect(R2.out2, R2.in2) | ||
this.disconnect(R2.out2, R2.in2) | ||
this.connect(R2.out2, R2.in2) | ||
this.disconnect(R2.out2) | ||
this.connect(R2.out2, R2.in2) | ||
}).not.toThrow(); | ||
}) | ||
} | ||
) | ||
} | ||
|
||
} | ||
|
||
class testApp extends App { | ||
start: Starter | ||
reactor1: R1; | ||
|
||
constructor () { | ||
super(); | ||
this.start = new Starter(this); | ||
this.reactor1 = new R1(this); | ||
this._connect(this.start.out, this.reactor1.in1) | ||
} | ||
} | ||
|
||
var app = new testApp() | ||
app._start() |
Oops, something went wrong.