public void TestResistorFromFactoryMethod() { Resistor resistor = ResistorFactory.fourBands(); ((Band)resistor.Bands[0]).Color = ResistorColor.Green; ((Band)resistor.Bands[1]).Color = ResistorColor.Black; ((MultiplierBand)resistor.Bands[2]).Color = ResistorMultiplier.Black; ((ToleranceBand)resistor.Bands[3]).Color = ResistorTolerance.Gold; Assert.AreEqual(50, resistor.Value); }
public void TestResistorFromFactoryWithParamMethod() { Band firstBand = new Band(); Band secondBand = new Band(); MultiplierBand thirdBand = new MultiplierBand(); ToleranceBand fourthBand = new ToleranceBand(); Resistor resistor = ResistorFactory.fourBands(firstBand, secondBand, thirdBand, fourthBand); ((Band)resistor.Bands[0]).Color = ResistorColor.Orange; ((Band)resistor.Bands[1]).Color = ResistorColor.Brown; ((MultiplierBand)resistor.Bands[2]).Color = ResistorMultiplier.Black; ((ToleranceBand)resistor.Bands[3]).Color = ResistorTolerance.Gold; Assert.AreEqual(31, resistor.Value); }
private void ConvertButton_Click(object sender, RoutedEventArgs e) { if(NumOfBands.SelectedItem != null) { ResultBox.Visibility = Visibility.Visible; ResultBoxStatus.Visibility = Visibility.Hidden; int numOfBands = Convert.ToInt32(((ComboBoxItem)NumOfBands.SelectedItem).Content); int BandNumber = 0; double[] Bands = new double[numOfBands]; // Loop through resistor band colour ComboBoxes and read into array foreach (ComboBox child in ResistorBands.Children) { if (child.Visibility == Visibility.Visible) { try { Bands[BandNumber] = resColours[Convert.ToString(child.SelectedValue)]; } catch(KeyNotFoundException) { ResultBoxStatus.Text = "Please select a colour for each resistor band."; ResultBoxStatus.Visibility = Visibility.Visible; return; } } BandNumber++; } ResistorFactory rf = new ResistorFactory(); Resistor resistor = rf.CreateResistor(numOfBands); resistor.CalculateValues(Bands); ResultBox.DataContext = resistor; } else { ResultBoxStatus.Visibility = Visibility.Visible; ResultBox.Visibility = Visibility.Hidden; } }