示例#1
0
    public void Reduced()
    {
        var cd     = new CompositeDisposable();
        var engine = new SinglethreadEngine();
        var tick   = engine.MultiOp <float>(
            reducer: (a, b) => a + b
            );
        var dummy = engine.El(10);

        float computerReduced = 0;
        float readerReduced   = 0;

        engine.Computer(cd,
                        new object[] { tick, dummy },
                        () => computerReduced = tick.Reduced
                        );
        engine.Reader(cd,
                      new object[] { tick },
                      () => readerReduced = tick.Reduced
                      );

        tick.Fire(1f);
        tick.Fire(0.8f);
        engine.Update();
        Assert.AreEqual(1.8f, readerReduced, 0.0001f);
        Assert.AreEqual(1.8f, computerReduced, 0.0001f);

        tick.Fire(0.3f);
        engine.Update();
        Assert.AreEqual(0.3f, readerReduced, 0.0001f);

        dummy.Write(12);
        engine.Update();
        Assert.AreEqual(0f, computerReduced);
    }
示例#2
0
    public void Writership()
    {
        var engine = new SinglethreadEngine();
        var dummy  = engine.El(0);

        Action a1 = () => dummy.Write(3);
        Action a2 = () => dummy.Write(4);

        Assert.Throws <InvalidOperationException>(() =>
        {
            a1();
            engine.Update();
            a2();
        });
    }