private void Romanize_Click(object sender, EventArgs e) { if (int.TryParse(intIn.Text, out intVal)) { try { outBox.Text = Numerals.Romanize(intVal); } catch (ArgumentOutOfRangeException) { outBox.Text = @"No negativity here!"; } catch (ArgumentException) { outBox.Text = @"Too big!"; } } else { if (intIn.Text.ToLower().Equals("marco")) { outBox.Text = @"Polo!"; } else if (intIn.Text.ToLower().Equals("caesar")) { outBox.Text = @"Hail Caesar!"; } else { outBox.Text = @"Integers please."; } } }
public void LowNumeralsAsStringTest() { string[] words = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; for (uint i = 0; i <= 9; i++) { Assert.AreEqual(words[i], Numerals.LowAsString(i)); } }
public void HighNumeralsAsStringTest() { string[] words = { "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" }; for (uint i = 0; i <= 7; i++) { Assert.AreEqual(words[i], Numerals.HighAsString(i)); } }
public void If_I_Enter_a_44_then_I_should_get_a_XLIV_back() { //Arrange var number = "44"; var convertNumber = int.Parse(number); var numeral = new Numerals(); //Act var result = numeral.ConvertNumber(convertNumber); //Assert Assert.AreEqual("XLIV", result); }
public void If_I_Enter_a_3999_then_I_should_get_a_MMMCMXCIX_back() { //Arrange var number = "3999"; var convertNumber = int.Parse(number); var numeral = new Numerals(); //Act var result = numeral.ConvertNumber(convertNumber); //Assert Assert.AreEqual("MMMCMXCIX", result); }
public void If_I_Enter_a_1023_then_I_should_get_a_MXXIII_back() { //Arrange var number = "1023"; var convertNumber = int.Parse(number); var numeral = new Numerals(); //Act var result = numeral.ConvertNumber(convertNumber); //Assert Assert.AreEqual("MXXIII", result); }
public void If_I_Enter_a_891_then_I_should_get_a_DCCCXCI_back() { //Arrange var number = "891"; var convertNumber = int.Parse(number); var numeral = new Numerals(); //Act var result = numeral.ConvertNumber(convertNumber); //Assert Assert.AreEqual("DCCCXCI", result); }
public Numerals GetNumerals(char searchChar) { Numerals key = Numerals.NONE; foreach (var pair in SetNumeralPairs()) { if (pair.Value == searchChar) { key = pair.Key; break; } } return(key); }
public string Parse(int number) { var result = ""; var numerals = new Numerals(); var _number = number.ToString(); while (number > 0) { if (number >= 1000) { var numThousies = number.ToString(); var daIndex = int.Parse(numThousies[0].ToString()); result += numerals.RomanThousands[daIndex]; number -= daIndex * 1000; continue; } if (number >= 100) { var numHundies = number.ToString(); var daIndex = int.Parse(numHundies[0].ToString()); result += numerals.RomanHundreds[daIndex]; number -= daIndex * 100; continue; } if (number > 10) { var numTensies = number.ToString(); var daIndex = int.Parse(numTensies[0].ToString()); result += numerals.RomanTens[daIndex]; number -= daIndex * 10; continue; } if (number <= 10) { result += numerals.RomanOnes[number]; number = 0; continue; } } return(result); }
public static int GetAllowedRepetitions(this Numerals numeral) { switch (numeral) { case Numerals.V: case Numerals.L: case Numerals.D: return(1); case Numerals.I: case Numerals.X: case Numerals.C: case Numerals.M: return(3); default: return(0); } }
private void Deromanize_Click(object sender, EventArgs e) { bool error = false; int input = -1; try { input = Numerals.Deromanize(intOut.Text); } catch (InvalidOperationException) { outBox.Text = @"Invalid numeral!"; error = true; } catch (ArgumentException) { outBox.Text = @"Valid numerals only!"; error = true; } if (!error) { outBox.Text = input.ToString(); } }