Exemplo n.º 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();
        }
Exemplo n.º 2
0
        public void WithoutSignTest()
        {
            ScalarStub       original = new ScalarStub("value");
            ValueSpy <float> spy      = new ValueSpy <float>(original.WithoutSign);

            original.Update(-2);
            spy.WaitFrame();
            spy.AssertWasUpdatedTo(2.0f);
        }
Exemplo n.º 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();
        }
Exemplo n.º 4
0
        public void KeyReleasedTest()
        {
            ValueSpy <bool> spy = new ValueSpy <bool>(Key.Released(KeyCode.Space));

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

            spy.SimulateInput(i => i.GetKeyUp(KeyCode.Space).Returns(false));
            spy.AssertWasUpdatedTo(false);
        }
Exemplo n.º 5
0
        public async Task ChainedBind_ToggleValue(bool value)
        {
            var spy = new ValueSpy <bool>(value);

            var sut = AddComponent(
                ("Value", value),
                ("ValueChanged", EventCallback.Factory.Create <bool>(this, spy.SetValue)));

            await sut.Find("input").InputAsync(!value);

            spy.Value.ShouldBe(!value);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public async Task Value_DataBind(MDCTextFieldStyle variant, string value)
        {
            var spy = new ValueSpy <string>();

            var sut = AddComponent(
                ("Variant", variant),
                ("ValueChanged", EventCallback.Factory.Create <string>(this, spy.SetValue)));

            var inputNode = sut.ShouldHaveInputNode();

            inputNode.Attributes["value"].ShouldBeNull();

            await inputNode.InputAsync(value);

            sut.ShouldHaveInputNode().Attributes["value"].Value.ShouldBe(value);
            spy.Value.ShouldBe(value);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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));
        }
Exemplo n.º 12
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();
        }