public void GenerateAnswersQuestionEmptyTest() { var contract = new DataContract(); contract.AddQuestion(new Question()); var answers = _answerGenerator.GenerateAnswers(contract); Assert.IsNull(answers); }
/// <summary> /// This method will parse the inputs and validates it. /// </summary> /// <param name="inputs">Inputs from Caller.</param> /// <returns>DataContract.</returns> public DataContract ParseInputs(string[] inputs) { if (inputs == null || inputs.Length == 0 || inputs.All(input => string.IsNullOrEmpty(input))) { throw new EmptyInputException(Constants.EmptyInputLines); } var parsedData = new DataContract(); foreach (var input in inputs.Where(i => !string.IsNullOrEmpty(i))) { // First of all separate the line with space var words = input.Split(Constants.Space); // if there are 3 words, then it is Symbol for Roman chars. // Just store it in romanSymbolic if (words.Length == 3) { var symbolForRoman = FetchSymbolForRoman(words); if (symbolForRoman != null) { parsedData.AddRomanSymbolsValues(symbolForRoman.Symbol, symbolForRoman.RomanSequence); } continue; } // if sentence ends with question mark then it is a question. // Just add it to question list. if (input.EndsWith(Constants.QuestionMark, StringComparison.InvariantCultureIgnoreCase)) { var question = FetchQuestion(input); if (question != null) { parsedData.AddQuestion(question); } continue; } // if sentence ends with "Credits" then it presents the value of metal. // Just add it to metal values. if (input.EndsWith(Constants.Credits, StringComparison.InvariantCultureIgnoreCase)) { Metal metal = FetchMetal(input, parsedData.RomanSymbolsValues); if (metal != null) { parsedData.AddMetalValues(metal.MetalName, metal.Value); } } } return(parsedData); }
public void ParseInputsValidTest() { var inputs = new string[] { "itt is I", "vtt is V", "xtt is X", "ltt is L", "ctt is C", "dtt is D", "mtt is M", "xtt Metal is 100 Credits", "mtt itt TestMetal is 10010 Credits", "AnotherTestMetal is 20 Credits", "how much is mtt mtt mtt ctt mtt dtt dtt dtt ctt dtt ctt ctt ctt xtt ctt ltt ltt ltt xtt ltt xtt xtt xtt itt xtt vtt vtt vtt itt vtt itt itt itt ?", "how many Credits is xtt ltt vtt itt Metal ?", "how many Credits is ctt ctt ctt xtt ctt xtt ltt TestMetal ?", }; var expected = new DataContract(); expected.AddRomanSymbolsValues("itt", "I"); expected.AddRomanSymbolsValues("vtt", "V"); expected.AddRomanSymbolsValues("xtt", "X"); expected.AddRomanSymbolsValues("ltt", "L"); expected.AddRomanSymbolsValues("ctt", "C"); expected.AddRomanSymbolsValues("dtt", "D"); expected.AddRomanSymbolsValues("mtt", "M"); expected.AddMetalValues("Metal", 10.0F); expected.AddMetalValues("TestMetal", 10.0F); expected.AddMetalValues("AnotherTestMetal", 20.0F); var question1 = new Question { PuzzlePart = "mtt mtt mtt ctt mtt dtt dtt dtt ctt dtt ctt ctt ctt xtt ctt ltt ltt ltt xtt ltt xtt xtt xtt itt xtt vtt vtt vtt itt vtt itt itt itt", Type = QuestionType.RomanToCredit }; var question2 = new Question { PuzzlePart = "xtt ltt vtt itt Metal", Type = QuestionType.RomanMetalToCredit }; var question3 = new Question { PuzzlePart = "ctt ctt ctt xtt ctt xtt ltt TestMetal", Type = QuestionType.RomanMetalToCredit }; expected.AddQuestion(question1); expected.AddQuestion(question2); expected.AddQuestion(question3); var actual = _inputParser.ParseInputs(inputs); Assert.IsNotNull(actual); Assert.IsNotNull(actual.RomanSymbolsValues); Assert.IsNotNull(actual.MetalValues); Assert.IsNotNull(actual.Questions); Assert.AreEqual(expected.RomanSymbolsValues.Count, actual.RomanSymbolsValues.Count); Assert.AreEqual(expected.MetalValues.Count, actual.MetalValues.Count); Assert.AreEqual(expected.Questions.Count, actual.Questions.Count); foreach (var item in expected.RomanSymbolsValues) { Assert.IsTrue(actual.RomanSymbolsValues.ContainsKey(item.Key)); Assert.AreEqual(actual.RomanSymbolsValues[item.Key], item.Value); } foreach (var item in expected.MetalValues) { Assert.IsTrue(actual.MetalValues.ContainsKey(item.Key)); Assert.AreEqual(actual.MetalValues[item.Key], item.Value); } }
public void GenerateAnswersTest() { var input = new DataContract(); input.AddRomanSymbolsValues("itt", "I"); input.AddRomanSymbolsValues("vtt", "V"); input.AddRomanSymbolsValues("xtt", "X"); input.AddRomanSymbolsValues("ltt", "L"); input.AddRomanSymbolsValues("ctt", "C"); input.AddRomanSymbolsValues("dtt", "D"); input.AddRomanSymbolsValues("mtt", "M"); input.AddMetalValues("Metal", 10.0F); input.AddMetalValues("TestMetal", 10.0F); input.AddMetalValues("AnotherTestMetal", 20.0F); var question1 = new Question { PuzzlePart = "mtt mtt mtt ctt mtt dtt dtt dtt ctt dtt ctt ctt ctt xtt ctt ltt ltt ltt xtt ltt xtt xtt xtt itt xtt vtt vtt vtt itt vtt itt itt itt", Type = QuestionType.RomanToCredit }; var question2 = new Question { PuzzlePart = "xtt ltt vtt itt Metal", Type = QuestionType.RomanMetalToCredit }; var question3 = new Question { PuzzlePart = "ctt ctt ctt xtt ctt xtt ltt TestMetal", Type = QuestionType.RomanMetalToCredit }; var question4 = new Question { PuzzlePart = "AnotherTestMetal", Type = QuestionType.RomanMetalToCredit }; input.AddQuestion(question1); input.AddQuestion(question2); input.AddQuestion(question3); input.AddQuestion(question4); var expected = new List <string> { "mtt mtt mtt ctt mtt dtt dtt dtt ctt dtt ctt ctt ctt xtt ctt ltt ltt ltt xtt ltt xtt xtt xtt itt xtt vtt vtt vtt itt vtt itt itt itt is 6441", "xtt ltt vtt itt Metal is 460 Credits", "ctt ctt ctt xtt ctt xtt ltt TestMetal is 4300 Credits", "AnotherTestMetal is 20 Credits" }; var actual = _answerGenerator.GenerateAnswers(input); Assert.IsNotNull(actual); Assert.AreEqual(expected.Count, actual.Count); foreach (var ans in expected) { Assert.IsTrue(actual.Contains(ans)); } }