コード例 #1
0
        public void AndTest()
        {
            TriggerStub  triggerA = new TriggerStub("A");
            TriggerStub  triggerB = new TriggerStub("B");
            TriggerInput combined = triggerA.And(triggerB);

            Assert.That(combined.ToString(), Is.EqualTo("A+B"));
            ValueSpy <bool> spy = new ValueSpy <bool>(combined);

            triggerA.Update(true);
            spy.WaitFrame();
            spy.AssertNothingHappened();

            triggerA.Update(false);
            triggerB.Update(true);
            spy.WaitFrame();
            spy.AssertNothingHappened();

            triggerA.Update(true);
            spy.WaitFrame();
            spy.AssertWasUpdatedTo(true);

            triggerA.Update(false);
            spy.WaitFrame();
            spy.AssertWasUpdatedTo(false);

            triggerB.Update(false);
            spy.WaitFrame();
            spy.AssertNothingHappened();
        }
コード例 #2
0
        public void ValueOverTest()
        {
            ScalarStub      value = new ScalarStub();
            ValueSpy <bool> spy   = new ValueSpy <bool>(value.IsOver(2.0f));

            spy.WaitFrame();
            spy.AssertNothingHappened();

            value.Update(2.5f);
            spy.WaitFrame();
            spy.AssertWasUpdatedTo(true);

            spy.WaitFrame();
            spy.AssertNothingHappened();

            value.Update(1.5f);
            spy.WaitFrame();
            spy.AssertWasUpdatedTo(false);
        }
コード例 #3
0
        public void RawAxisTest()
        {
            ValueSpy <float> spy = new ValueSpy <float>(ValueOf.RawAxis("Horizontal"));

            spy.SimulateInput(i => i.GetAxisRaw("Horizontal").Returns(2.0f));
            spy.AssertWasUpdatedTo(2.0f);

            spy.WaitFrame();
            spy.AssertNothingHappened();
        }
コード例 #4
0
        public void AsScalarTest()
        {
            TriggerStub      trigger = new TriggerStub();
            ValueSpy <float> spy     = new ValueSpy <float>(trigger.AsScalar);

            spy.WaitFrame();
            spy.AssertNothingHappened();

            trigger.Update(true);
            spy.WaitFrame();
            spy.AssertWasUpdatedTo(1);

            spy.WaitFrame();
            spy.AssertNothingHappened();

            trigger.Update(false);
            spy.WaitFrame();
            spy.AssertWasUpdatedTo(0);
        }
コード例 #5
0
        public void OperatorMinusTest()
        {
            ScalarStub       a   = new ScalarStub("a");
            ScalarStub       b   = new ScalarStub("b");
            ValueSpy <float> spy = new ValueSpy <float>(a - b);

            spy.WaitFrame();
            spy.AssertNothingHappened();

            a.Update(3);
            spy.WaitFrame();
            spy.AssertWasUpdatedTo(3);

            spy.WaitFrame();
            spy.AssertNothingHappened();

            b.Update(2);
            spy.WaitFrame();
            spy.AssertWasUpdatedTo(1);
        }
コード例 #6
0
        public void CombineScalarsToVectorTest()
        {
            ScalarStub         x   = new ScalarStub("x");
            ScalarStub         y   = new ScalarStub("y");
            ValueSpy <Vector2> spy = new ValueSpy <Vector2>(Combine.ScalarsToVector(x, y));

            spy.WaitFrame();
            spy.AssertNothingHappened();

            x.Update(0.5f);
            spy.WaitFrame();
            spy.AssertWasUpdatedTo(new Vector2(0.5f, 0));

            spy.WaitFrame();
            spy.AssertNothingHappened();

            y.Update(-1);
            spy.WaitFrame();
            spy.AssertWasUpdatedTo(new Vector2(0.5f, -1));
        }
コード例 #7
0
        public void KeyHeldTest()
        {
            ValueSpy <bool> spy = new ValueSpy <bool>(Key.Held(KeyCode.Space));

            spy.SimulateInput(i => i.GetKey(KeyCode.Space).Returns(true));
            spy.AssertWasUpdatedTo(true);

            spy.WaitFrame();
            spy.AssertNothingHappened();

            spy.SimulateInput(i => i.GetKey(KeyCode.Space).Returns(false));
            spy.AssertWasUpdatedTo(false);
        }
コード例 #8
0
        public void CombineTriggersToAxisTest()
        {
            TriggerStub      positive = new TriggerStub("positive");
            TriggerStub      negative = new TriggerStub("negative");
            ValueSpy <float> spy      = new ValueSpy <float>(Combine.TriggersToAxis(positive, negative));

            spy.WaitFrame();
            spy.AssertNothingHappened();

            positive.Update(true);
            spy.WaitFrame();
            spy.AssertWasUpdatedTo(1);

            negative.Update(true);
            spy.WaitFrame();
            spy.AssertWasUpdatedTo(0);

            positive.Update(false);
            spy.WaitFrame();
            spy.AssertWasUpdatedTo(-1);

            spy.WaitFrame();
            spy.AssertNothingHappened();
        }