public void TestDifferentID() {
            Circuit circuit2 = new Circuit();
            Connection con20 = new Connection(); // GND
            Connection con21 = new Connection();
            Connection dummyConnection = new Connection();
            Connection dummyConnection2 = new Connection();
            Connection con22 = new Connection();

            Component battery2 = new Component(con20, con21, 0, 12);
            Component resistor21 = new Component(con20, con22, 2, 0);
            Component dummyComponent = new Component(dummyConnection, dummyConnection2, 0, 0);
            Component dummyComponent2 = new Component(dummyConnection, dummyConnection2, 0, 0);
            Component resistor22 = new Component(con21, con22, 2, 0);
            Component resistor23 = new Component(con21, con22, 2, 0);


            circuit2.AddComponent(battery2);
            circuit2.AddComponent(resistor21);
            circuit2.AddComponent(resistor22);
            circuit2.AddComponent(resistor23);

            CircuitCalculator circuitCalculator2 = new CircuitCalculator();
            circuitCalculator2.Calculate(circuit2);

            Assert.IsTrue(Math.Abs(con20.Volts - 0) < 0.0001);
            Assert.IsTrue(Math.Abs(con21.Volts - 12) < 0.0001);
            Assert.IsTrue(Math.Abs(con22.Volts - 8) < 0.0001);


            Assert.IsTrue(Math.Abs(battery2.Amps - 4) < 0.0001);
            Assert.IsTrue(Math.Abs(resistor21.Amps - 4) < 0.0001);
            Assert.IsTrue(Math.Abs(resistor22.Amps - 2) < 0.0001);
            Assert.IsTrue(Math.Abs(resistor23.Amps - 2) < 0.0001);
        }
        public void testStorage()
        {
            using (var db = new CircuitContext())
            {
                Circuit circuit = new Circuit();
                Connection con0 = new Connection(); // GND
                Connection con1 = new Connection();
                Connection con2 = new Connection();

                Component battery = new Component(con0, con1, 0, 12);
                Component resistor1 = new Component(con0, con2, 2, 0);
                Component resistor2 = new Component(con1, con2, 2, 0);
                Component resistor3 = new Component(con1, con2, 2, 0);


                circuit.AddComponent(battery);
                circuit.AddComponent(resistor1);
                circuit.AddComponent(resistor2);
                circuit.AddComponent(resistor3);

                db.Circuits.Add(circuit);



            }
        }
Exemplo n.º 3
0
        public void AddComponent(Component newComponent)
        {
            // add the new component to the list of components
            ListComponents.Add(newComponent);
            foreach (Connection connection in newComponent.Connections)
            {
                // add each of the connections in the new component into the listConnections set
                // make sure that there are no duplicates
                bool temp = false;
                foreach (Connection innerConnection in ListConnections)
                {
                    if (connection.Id == innerConnection.Id)
                    {
                        temp = true;
                    }
                }
                if (temp == false)
                {
                    ListConnections.Add(connection);
                }
                // also update each of the connections so that they have a reference to the component
                connection.Components.Add(newComponent);
            }

            // then update the connections
            // connections need to be updated
        }
Exemplo n.º 4
0
        public void CircuitModifyShouldHaveCorrectNumberOfComponentsAndConnections()
        {
            Circuit circuit = new Circuit();
            Connection con0 = new Connection(); // GND
            Connection con1 = new Connection();
            Connection con2 = new Connection();

            Component battery = new Component(con0, con1, 0, 24);
            Component resistor1 = new Component(con1, con2, 2, 0);
            Component resistor2 = new Component(con2, con0, 4, 0);

            circuit.AddComponent(battery);
            circuit.AddComponent(resistor1);
            circuit.AddComponent(resistor2);

            Assert.IsTrue(circuit.ListComponents.Count == 3);
            Assert.IsTrue(circuit.ListConnections.Count == 3);

            
            circuit.ModifyComponent(resistor1, con2, con0);
            circuit.ModifyComponent(resistor1, con0, con1);


            Assert.IsTrue(circuit.ListComponents.Count == 3);
            Assert.IsTrue(circuit.ListConnections.Count == 3);

   

        }
        public void TestForNoVoltageSourceConnections() {
            Circuit circuit = new Circuit();
            Connection con0 = new Connection(); // GND
            Connection con1 = new Connection();

            Component resistor1 = new Component(con0, con1, 2, 0);
            Component resistor2 = new Component(con1, con0, 2, 0);
            Component resistor3 = new Component(con1, con0, 2, 0);

            circuit.AddComponent(resistor1);
            circuit.AddComponent(resistor2);
            circuit.AddComponent(resistor3);

            CircuitCalculator circuitCalculator = new CircuitCalculator();
            circuitCalculator.Calculate(circuit);
        }
Exemplo n.º 6
0
 public void ModifyComponent(Component modifyComponent, Connection oldConnection, Connection newConnection)
 {
     if (oldConnection.Id == modifyComponent.Connections[0].Id)
     {
         // [0] is being replaced by the new one
         modifyComponent.Connections[0].Components.Remove(modifyComponent);
         newConnection.Components.Add(modifyComponent);
         modifyComponent.Connections[0] = newConnection;
     } 
     else if (oldConnection.Id == modifyComponent.Connections[1].Id)
     {
         // [1] is being replaced by the new one
         modifyComponent.Connections[1].Components.Remove(modifyComponent);
         newConnection.Components.Add(modifyComponent);
         modifyComponent.Connections[1] = newConnection;
     }
 }
Exemplo n.º 7
0
        public void RemoveComponent(Component removeComponent)
        {
            foreach (Connection connection in removeComponent.Connections)
            {
                // for each of the vertices in the component, remove its connection to the component;
                connection.Components.Remove(removeComponent);
                if (connection.Components.Count == 0)
                {
                    // connection removeComponent.Connections[i] has no components listed in it.
                    // remove this connection from _listConnections
                    // garbage collection will deal with the rest
                    ListConnections.Remove(connection);
                }
            }

            // remove the component from the list of components
            ListComponents.Remove(removeComponent);
            // then update the connections
            // connections need to be updated
        }
        public void TestCorrectCircuirs() {
            Circuit circuit1 = new Circuit();
            Connection con10 = new Connection(); // GND
            Connection con11 = new Connection();
            Connection con12 = new Connection();
            Connection con13 = new Connection();
            Connection con14 = new Connection();

            Component battery1 = new Component(con10, con11, 0, 24);
            Component resistor11 = new Component(con10, con12, 2, 0);
            Component resistor12 = new Component(con10, con12, 4, 0);
            Component resistor13 = new Component(con11, con13, 3, 0);
            Component resistor14 = new Component(con11, con14, 5, 0);
            Component resistor15 = new Component(con13, con14, 1, 0);
            Component resistor16 = new Component(con12, con13, 2, 0);

            circuit1.AddComponent(battery1);
            circuit1.AddComponent(resistor11);
            circuit1.AddComponent(resistor12);
            circuit1.AddComponent(resistor13);
            circuit1.AddComponent(resistor14);
            circuit1.AddComponent(resistor15);
            circuit1.AddComponent(resistor16);

            CircuitCalculator circuitCalculator1 = new CircuitCalculator();
            circuitCalculator1.Calculate(circuit1);

            Assert.IsTrue(Math.Abs(con10.Volts - 0) < 0.0001);
            Assert.IsTrue(Math.Abs(con11.Volts - 24) < 0.0001);
            Assert.IsTrue(Math.Abs(con12.Volts - 6) < 0.0001);
            Assert.IsTrue(Math.Abs(con13.Volts - 15) < 0.0001);
            Assert.IsTrue(Math.Abs(con14.Volts - 16.5) < 0.0001);

            Assert.IsTrue(Math.Abs(battery1.Amps - 4.5) < 0.0001);
            Assert.IsTrue(Math.Abs(resistor11.Amps - 3) < 0.0001);
            Assert.IsTrue(Math.Abs(resistor12.Amps - 1.5) < 0.0001);
            Assert.IsTrue(Math.Abs(resistor13.Amps - 3) < 0.0001);
            Assert.IsTrue(Math.Abs(resistor14.Amps - 1.5) < 0.0001);
            Assert.IsTrue(Math.Abs(resistor15.Amps - 1.5) < 0.0001);
            Assert.IsTrue(Math.Abs(resistor16.Amps - 4.5) < 0.0001);

            Circuit circuit2 = new Circuit();
            Connection con20 = new Connection(); // GND
            Connection con21 = new Connection();
            Connection con22 = new Connection();

            Component battery2 = new Component(con20, con21, 0, 12);
            Component resistor21 = new Component(con20, con22, 2, 0);
            Component resistor22 = new Component(con21, con22, 2, 0);
            Component resistor23 = new Component(con21, con22, 2, 0);


            circuit2.AddComponent(battery2);
            circuit2.AddComponent(resistor21);
            circuit2.AddComponent(resistor22);
            circuit2.AddComponent(resistor23);

            CircuitCalculator circuitCalculator2 = new CircuitCalculator();
            circuitCalculator2.Calculate(circuit2);

            Assert.IsTrue(Math.Abs(con20.Volts - 0) < 0.0001);
            Assert.IsTrue(Math.Abs(con21.Volts - 12) < 0.0001);
            Assert.IsTrue(Math.Abs(con22.Volts - 8) < 0.0001);


            Assert.IsTrue(Math.Abs(battery2.Amps - 4) < 0.0001);
            Assert.IsTrue(Math.Abs(resistor21.Amps - 4) < 0.0001);
            Assert.IsTrue(Math.Abs(resistor22.Amps - 2) < 0.0001);
            Assert.IsTrue(Math.Abs(resistor23.Amps - 2) < 0.0001);
        }
Exemplo n.º 9
0
        public void RunTest()
        {
          Circuit circuit = new Circuit();

          Connection con0 = new Connection();
          Connection con1 = new Connection();
          Connection con2 = new Connection();
          Connection con3 = new Connection();

          Component battery1 = new Component(con0, con1, 0, 5);
          Component battery2 = new Component(con2, con3, 0, 5);
          Component resistor1 = new Component(con0, con1, 10, 0);
          Component resistor2 = new Component(con2, con3, 10, 0);

          circuit.AddComponent(battery1);
          circuit.AddComponent(battery2);
          circuit.AddComponent(resistor1);
          circuit.AddComponent(resistor2);

      //Connection con0 = new Connection(); // GND
      //Connection con1 = new Connection();
      //Connection con2 = new Connection();
      //Connection con3 = new Connection();
      //Connection con4 = new Connection();
      //Connection con5 = new Connection();

      //Component battery1 = new Component(con0, con1, 0, 24);
      //Component battery2 = new Component(con3, con5, 0, 12);

      //Component resistor1 = new Component(con0, con2, 2,0);
      //Component resistor2 = new Component(con0, con2, 4, 0);
      //Component resistor3 = new Component(con1, con3, 3, 0);
      //Component resistor4 = new Component(con1, con4, 5, 0);
      //Component resistor5 = new Component(con4, con5, 1, 0);
      //Component resistor6 = new Component(con2, con3, 2, 0);



      //circuit.AddComponent(battery1);
      //circuit.AddComponent(battery2);

      //circuit.AddComponent(resistor1);
      //circuit.AddComponent(resistor2);
      //circuit.AddComponent(resistor3);
      //circuit.AddComponent(resistor4);
      //circuit.AddComponent(resistor5);
      //circuit.AddComponent(resistor6);


      // OLD TEST CIRCUIT:
      //Circuit circuit = new Circuit();
      //Connection con0 = new Connection(); // GND
      //Connection con1 = new Connection();
      //Connection con2 = new Connection();

      //Component battery = new Component(con0, con1, 0, 12);
      //Component resistor1 = new Component(con0, con2, 2, 0);
      //Component resistor2 = new Component(con1, con2, 2, 0);
      //Component resistor3 = new Component(con1, con2, 2, 0);


      //circuit.AddComponent(battery);
      //circuit.AddComponent(resistor1);
      //circuit.AddComponent(resistor2);
      //circuit.AddComponent(resistor3);

      CircuitCalculator circuitCalculator = new CircuitCalculator();
            circuitCalculator.Calculate(circuit);


            Matrix matrixA = new Matrix(3,3);
            matrixA.elements = new double[3,3] { {1,2,3}, {4,5,6}, {7,8,0}};
            Matrix matrixZ = new Matrix(3,1);
            matrixZ.elements = new double[3, 1] {{ 1}, { 2}, { 3}};

            Matrix newMatrx = Matrix.SolveMatrix(matrixA, matrixZ);

            Circuit circuit2 = new Circuit(); // empty line so i can put a breakpoint here lol
        }