Example #1
0
        public void TestDirect()
        {
            AutoResetEvent autoResetEvent = new AutoResetEvent(false);
            bool result = false;

            // Create elements / build the graph
            LogicEmitter source = new LogicEmitter();
            source.AttachOutput(new LogicActionInvoker(value =>
                                                       	{
                                                       		result = value;
                                                       		autoResetEvent.Set();
                                                       	}));

            // Start processing
            source.StartProcessing();

            // Test initial state
            Assert.IsFalse(result);

            // Emit an test
            source.EmitTrue(); autoResetEvent.WaitOne();
            Assert.IsTrue(result);

            // Emit and test
            source.EmitTrue(); autoResetEvent.WaitOne();
            Assert.IsTrue(result);

            // Emit and test
            source.EmitFalse(); autoResetEvent.WaitOne();
            Assert.IsFalse(result);

            // Emit and test
            source.EmitFalse(); autoResetEvent.WaitOne();
            Assert.IsFalse(result);

            // Emit and test
            source.EmitTrue(); autoResetEvent.WaitOne();
            Assert.IsTrue(result);

            // Emit and test
            source.EmitFalse(); autoResetEvent.WaitOne();
            Assert.IsFalse(result);

            // Emit and test
            source.EmitFalse(); autoResetEvent.WaitOne();
            Assert.IsFalse(result);

            // Emit and test
            source.EmitTrue(); autoResetEvent.WaitOne();
            Assert.IsTrue(result);
        }
Example #2
0
        public void TestAnd()
        {
            AutoResetEvent autoResetEvent = new AutoResetEvent(false);
            bool result = false;

            // Create the elements
            var source1 = new LogicEmitter();
            var source2 = new LogicEmitter();
            var gate = new AndGate();
            var sink = new LogicActionInvoker(value =>
                                                  {
                                                      result = value;
                                                      autoResetEvent.Set();
                                                  });

            // Build the graph
            source1.AttachOutput(gate.Input1);
            source2.AttachOutput(gate.Input2);
            gate.AttachOutput(sink);

            // Start processing
            source1.StartProcessing();
            source2.StartProcessing();
            gate.StartProcessing();

            // Test initial state
            Assert.IsFalse(result);
            const int timeout = Timeout.Infinite;

            // Emit and test
            source1.EmitTrue(); source2.EmitTrue();
            Assert.IsTrue(autoResetEvent.WaitOne(timeout), "Timeout");
            Assert.IsTrue(result);

            // Emit and test
            source1.EmitTrue(); source2.EmitFalse();
            Assert.IsTrue(autoResetEvent.WaitOne(timeout), "Timeout");
            Assert.IsFalse(result);

            // Emit and test
            source1.EmitFalse(); source2.EmitTrue();
            Assert.IsTrue(autoResetEvent.WaitOne(timeout), "Timeout");
            Assert.IsFalse(result);

            // Emit and test
            source1.EmitFalse(); source2.EmitFalse();
            Assert.IsTrue(autoResetEvent.WaitOne(timeout), "Timeout");
            Assert.IsFalse(result);
        }
Example #3
0
        public void TestNegation()
        {
            AutoResetEvent autoResetEvent = new AutoResetEvent(false);
            bool result = false;

            // Create elements
            var source = new LogicEmitter();
            var filter = new NotGate();
            var sink = new LogicActionInvoker(value =>
                                                             	{
                                                             		result = value;
                                                             		autoResetEvent.Set(); // wait for processing to finish
                                                                });

            // Build the graph
            source.AttachOutput(filter);
            filter.AttachOutput(sink);

            // Start processing
            source.StartProcessing();

            // Test initial state
            Assert.IsFalse(result);

            // Emit and test
            source.EmitTrue(); autoResetEvent.WaitOne();
            Assert.IsFalse(result);

            // Emit and test
            source.EmitTrue(); autoResetEvent.WaitOne();
            Assert.IsFalse(result);

            // Emit and test
            source.EmitFalse(); autoResetEvent.WaitOne();
            Assert.IsTrue(result);

            // Emit and test
            source.EmitFalse(); autoResetEvent.WaitOne();
            Assert.IsTrue(result);

            // Emit and test
            source.EmitTrue(); autoResetEvent.WaitOne();
            Assert.IsFalse(result);

            // Emit and test
            source.EmitFalse(); autoResetEvent.WaitOne();
            Assert.IsTrue(result);

            // Emit and test
            source.EmitFalse(); autoResetEvent.WaitOne();
            Assert.IsTrue(result);

            // Emit and test
            source.EmitTrue(); autoResetEvent.WaitOne();
            Assert.IsFalse(result);
        }