public void IsValid_Invalid_List_Is_Too_Short_And_Valid_Confidence_Should_Not_Pass() { // arrange var testList = "a"; float?testConfidence = 70.1f; // act PipelineResultModel result = pipeline.IsValid(testList, testConfidence); // assert Assert.IsNotNull(result); Assert.IsTrue(result is PipelineResultModel); Assert.IsFalse(result.isSuccessful); }
public void IsValid_Valid_List_And_Invalid_Confidence_Is_Too_Low_Should_Not_Pass() { // arrange var testList = "{}909 ..-_* this is another test string"; float?testConfidence = 70.00f; // act PipelineResultModel result = pipeline.IsValid(testList, testConfidence); // assert Assert.IsNotNull(result); Assert.IsTrue(result is PipelineResultModel); Assert.IsFalse(result.isSuccessful); }
public void Execute_Should_Not_Pass() { // arrange var input = "*"; var expected = "List of ingredients must be longer than 1 character."; // act PipelineResultModel result = pipeline.Execute(ref input, null, null); // assert Assert.IsNotNull(result); Assert.IsFalse(result.isSuccessful); Assert.AreEqual(expected, result.result); // reset PipelineReset(); }
public void Clean_PrimaryCleanPipeline_Should_Pass() { // arrange float?meanConfidence = 80.0f; var facade = new DataCleanFacade(DataCleanEnum.ListPrimary, meanConfidence); var testCases = new IngredientListHelperCollection.Execute(); // act foreach (var testCase in testCases.IngredientLists) { var expected = (PipelineResultModel)testCase.Expected; PipelineResultModel result = facade.Clean(ref testCase.Input); // assert Assert.IsNotNull(result); Assert.AreEqual(result.isSuccessful, expected.isSuccessful); Assert.AreEqual(result.result, expected.result); } }
public void Execute_Should_Pass() { // arrange var collection = new SecondaryCleanPipelineCollection.Execute(); // act foreach (TestingModel testCase in collection.IngredientLists) { var input = (string)testCase.Input; PipelineResultModel result = pipeline.Execute(ref input, null, null); List <string> expected = (List <string>)((PipelineResultModel)testCase.Expected).result; // assert Assert.IsNotNull(result); Assert.AreEqual(expected.Count, ((List <string>)result.result).Count); foreach (int i in Enumerable.Range(0, expected.Count)) { Assert.AreEqual(expected[i], ((List <string>)result.result)[i]); } PipelineReset(); } }
/// <summary> /// Cleans initial ingredient list text extraction /// </summary> /// <typeparam name="T"> For the primary cleaning pipeline, must be string </typeparam> /// <param name="input"> Ingredient list extracted from photo using Tesseract </param> /// <param name="type"> Type of data cleaning; Is ignored in pipeline </param> /// <returns> A PipelineResult object indicating if the method completed successfully and its result </returns> public PipelineResultModel Execute <T>(ref T input, DataCleanEnum?type, float?meanConfidence) { var list = input.ToString(); PipelineResultModel result; try { list = Remove(list); result = IsValid(list, meanConfidence); if (result.isSuccessful) { result.result = list.ToLower(); } } catch (Exception e) { result = new PipelineResultModel(); result.isSuccessful = false; result.result = e.Message; } return(result); }
public void CheckIngredients_Belvita_Vegan_Should_Pass() { // arrange var input = new PipelineResultModel() { isSuccessful = true, meanConfidence = 0, result = new List <string>() { "whole grain wheat flour", "wheat flour", "niacin", "reduced iron", "folic acid", "sugar", "canola oil", "whole grain rolled oats", "whole grain rye flour", "baking soda", "disodium pyrophosphate", "salt", "soy lecithin", "datem", "natural flavor", "niacinamide", "thiamin mononitrate (vitamin b1)", "riboflavin (vitamin b2)", "ferric orthophosphate (iron)", "pyridoxine hydrochloride (vitamin b6)" } }; var expectedCategories = new List <IngredientClassificationEnum>() { IngredientClassificationEnum.Vegan, IngredientClassificationEnum.Vegan, IngredientClassificationEnum.Unclassified, IngredientClassificationEnum.Unclassified, IngredientClassificationEnum.Unclassified, IngredientClassificationEnum.Vegan, IngredientClassificationEnum.Unclassified, IngredientClassificationEnum.Vegan, IngredientClassificationEnum.Vegan, IngredientClassificationEnum.Unclassified, IngredientClassificationEnum.Unclassified, IngredientClassificationEnum.Unclassified, IngredientClassificationEnum.Vegan, IngredientClassificationEnum.Unclassified, IngredientClassificationEnum.Vegan, IngredientClassificationEnum.Unclassified, IngredientClassificationEnum.Unclassified, IngredientClassificationEnum.Unclassified, IngredientClassificationEnum.Unclassified, IngredientClassificationEnum.Unclassified, }; // act var result = backend.CheckIngredients(input.result, new ProductModel() { IsSuccessful = true }); // assert Assert.IsNotNull(result); Assert.IsTrue(result.IsSuccessful); Assert.AreEqual(expectedCategories.Count, result.Ingredients.Count); foreach (int i in Enumerable.Range(0, 20)) { Assert.AreEqual(expectedCategories[i], result.Ingredients[i].Classification); } Assert.AreEqual(IngredientClassificationEnum.MaybeVegan, result.ProductCategory); }