Exemplo n.º 1
0
        public void SetXY_ForwardValue()
        {
            // Setup
            MockSerialDevice serialDevice = new MockSerialDevice("COM3", 9600);
            Wheelchair       chair        = Wheelchair.Instance(serialDevice);

            bool correctValues  = true;
            int  input          = 100;
            int  expectedOutput = 190;
            int  actualOutput   = -1;

            chair.Start();
            // act
            chair.SetX(0);
            chair.SetY(input);
            System.Threading.Thread.Sleep(150);
            actualOutput = chair.VoltY;
            chair.End();
            string message = "Expected: ";

            message += expectedOutput;
            message += ", Actual: ";
            message += actualOutput;
            chair.Dispose();
            Assert.AreEqual(expectedOutput, actualOutput, message);
        }
Exemplo n.º 2
0
        public void SetXY_ValidVoltages()
        {
            // Setup
            MockSerialDevice serialDevice  = new MockSerialDevice("COM3", 9600);
            Wheelchair       chair         = Wheelchair.Instance(serialDevice);
            bool             correctValues = true;

            int[] inputValues =
            {
                0,
                -100,
                100
            };
            int[] expectedValues = { 128, 66, 190 };
            chair.Start();
            // act
            for (int i = 0; i < 3; i++)
            {
                chair.SetX(inputValues[i]);
                chair.SetY(inputValues[i]);
                Thread.Sleep(150);
                if (chair.VoltX != expectedValues[i])
                {
                    correctValues = false;
                }
                if (chair.VoltY != expectedValues[i])
                {
                    correctValues = false;
                }
            }
            //chair.End();
            chair.Dispose();
            Assert.IsTrue(correctValues, "Voltages are not correct.");
        }
Exemplo n.º 3
0
        public void Start_InvalidPortName_ShouldThrowArgumentException()
        {
            MockSerialDevice serialDevice = new MockSerialDevice("Con3", 9600);
            Wheelchair       chair        = Wheelchair.Instance(serialDevice);

            chair.Start();
            chair.End();
            chair.Dispose();
            Assert.Fail("Invalid Port Name. Argument Exception was not thrown.");
        }
Exemplo n.º 4
0
        public void Start_InvalidComPort_ShouldThrowIOException()
        {
            MockSerialDevice serialDevice = new MockSerialDevice("COM7", 9600);
            Wheelchair       chair        = Wheelchair.Instance(serialDevice);

            chair.Start();
            chair.End();
            chair.Dispose();
            Assert.Fail("Invalid COM Port. IO Exception was not thrown.");
        }
Exemplo n.º 5
0
        public void Start_PortInUse_ShouldThrowUnauthorizedEx()
        {
            // Setup
            MockSerialDevice serialDevice = new MockSerialDevice("COM5", 9600);
            Wheelchair       chair        = Wheelchair.Instance(serialDevice);

            chair.Start();
            chair.End();
            chair.Dispose();
            Assert.Fail("Unauthorized Access Exception was not thrown.");
        }
Exemplo n.º 6
0
 public void Start_Serial_With_No_Name()
 {
     try
     {
         MockSerialDevice sd = new MockSerialDevice();
     }
     catch (Exception e)
     {
         Assert.Fail("Should not throw exception");
     }
 }
Exemplo n.º 7
0
        public void Start_InvalidBaudRate_ShouldThrowOutOfRange()
        {
            bool caught = false;

            try
            {
                MockSerialDevice serialDevice = new MockSerialDevice("COM3", 0);
                Wheelchair       chair        = Wheelchair.Instance(serialDevice);
            }
            catch (ArgumentOutOfRangeException e)
            {
                caught = true;
                Assert.AreEqual("BaudRate", e.ParamName);
            }
            if (!caught)
            {
                Assert.Fail("ArgumentOutOfRangeException was not thrown.");
            }
        }
Exemplo n.º 8
0
        public void SetSpeedAndDirection_Inputs()
        {
            //int[] directions = {0, 45, 90, 180, 270};
            Vector[]         directions    = { new Vector(0, 0), new Vector(0, 1), new Vector(1, 0), new Vector(0, -1), new Vector(-1, 0) };
            int[]            expected_x    = { 128, 172, 190, 128, 66 };
            int[]            expected_y    = { 190, 172, 128, 66, 128 };
            string           message       = "";
            bool             correctValues = true;
            MockSerialDevice serialDevice  = new MockSerialDevice("COM3", 9600);
            Wheelchair       chair         = Wheelchair.Instance(serialDevice);

            chair.Start();
            for (int i = 0; i < 5; i++)
            {
                chair.SetSpeedAndDirection(100, directions[i]);
                Thread.Sleep(100);
                if (chair.VoltX != expected_x[i])
                {
                    correctValues = false;
                    message      += "Direction[" + directions[i];
                    message      += "] was incorrect (X Voltage). Expected:";
                    message      += expected_x[i] + ", Actual:";
                    message      += chair.VoltX;
                    break;
                }
                if (chair.VoltY != expected_y[i])
                {
                    correctValues = false;
                    message      += "Direction[" + directions[i];
                    message      += "] was incorrect (Y Voltage). Expected:";
                    message      += expected_y[i] + ", Actual:";
                    message      += chair.VoltY;
                    break;
                }
            }
            chair.Dispose();
            Assert.IsTrue(correctValues, message);
        }