static void Main(string[] args) { Console.WriteLine(FabriqueCircuit.Help()); Console.WriteLine("--------------------------------------------------------------------------------------------------------"); try { Console.WriteLine("Entrez un circuit (code couleur ou valeur décimale)"); IComposant c = FabriqueCircuit.FromString(Console.ReadLine()); Console.WriteLine("Entrez une tension (en volt)"); c.MettreSousTension(Double.Parse(Console.ReadLine())); Console.WriteLine(c); Console.WriteLine(c.Dessiner()); } catch (CircuitOuvertException) { Console.WriteLine("Circuit ouvert"); } catch (ArgumentException iae) { Console.WriteLine(iae.Message); } catch (Exception) { Console.WriteLine("La chaîne entrée n'est pas un circuit valide"); } Console.Read(); }
public void FromStringTest1() { String description = "(NNVNA [NNJNA (NBNNA NNRNA)] NNGNA)"; IComposant c = FabriqueCircuit.FromString(description); c.MettreSousTension(9); Assert.AreEqual(16, c.CalculerResistance(), 0.1); Assert.AreEqual(0.5625, c.GetCourrant(), 0.001); Assert.AreEqual(9, c.GetTension(), 0.1); c = FabriqueCircuit.FromString("([BNNNA RVNNA] [OVNNA//RNNNA])"); c.MettreSousTension(9); Assert.AreEqual(198.70, c.CalculerResistance(), 0.1); Assert.AreEqual(0.04529, c.GetCourrant(), 0.001); Assert.AreEqual(9, c.GetTension(), 0.1); c = FabriqueCircuit.FromString("([([([([NbNo (NRNo BNNo)] NGNo) NbNo] NNJNA) NGNA] NJNA) NNGNo]-NNbNA)"); c.MettreSousTension(9); Assert.AreEqual(10, c.CalculerResistance(), 0.1); Assert.AreEqual(0.9, c.GetCourrant(), 0.01); Assert.AreEqual(9, c.GetTension(), 0.1); }
public void FromStringTest() { string description = "(5,00 [4 (10 2,0)] 8,0)"; IComposant c = FabriqueCircuit.FromString(description); c.MettreSousTension(9); Assert.AreEqual(16, c.CalculerResistance(), 0.1); Assert.AreEqual(0.5625, c.GetCourrant(), 0.001); Assert.AreEqual(9, c.GetTension(), 0.1); c = FabriqueCircuit.FromString("([100 250] [350//200,25])"); c.MettreSousTension(9); Assert.AreEqual(198.802, c.CalculerResistance(), 0.1); Assert.AreEqual(0.04529, c.GetCourrant(), 0.001); Assert.AreEqual(9, c.GetTension(), 0.1); c = FabriqueCircuit.FromString("([([([([6 (2 10)] 8) 6] 4) 8] 4) 8]-6)"); c.MettreSousTension(9); Assert.AreEqual(10, c.CalculerResistance(), 0.1); Assert.AreEqual(0.9, c.GetCourrant(), 0.01); Assert.AreEqual(9, c.GetTension(), 0.1); }