public void TestString2() { ParseString parser = new ParseString(); int accountNumer = parser.getAccountNumberFromString("123456789"); Assert.AreEqual(123456789, accountNumer); }
public void TestString1() { ParseString parser = new ParseString(); int accountNumer = parser.getAccountNumberFromString("111111111"); Assert.AreEqual(111111111, accountNumer); }
public void SortFoodsByPrice_Test() { // arrange Products[] products; Products[] price_foods; double product_0_expected_price = 0.315425; double product_1_expected_price = 0.6376; double product_2_expected_price = 0.7659; double product_3_expected_price = 0.93065; double product_4_expected_price = 1.06313; double delta = 0.001; // act products = ParseString.GetData(GetManufacturingString()); price_foods = new Products[products.Length]; ProductsSort.SortFoodsByPrice(products, ref price_foods); // assert Assert.AreEqual(product_0_expected_price, price_foods[0].Price, delta); Assert.AreEqual(product_1_expected_price, price_foods[1].Price, delta); Assert.AreEqual(product_2_expected_price, price_foods[2].Price, delta); Assert.AreEqual(product_3_expected_price, price_foods[3].Price, delta); Assert.AreEqual(product_4_expected_price, price_foods[4].Price, delta); }
protected override object EvaluationInternal(IDictionary <object, object> parameters) { _bytes = ParseString.HexString2Bytes(_string, _offset, _size); return(Runtime.GetStringForBytes(_bytes, _introducer == null ? _charset : Runtime.Substring(_introducer, 1))); }
public void GetData_Test() { // arrange Products[] products; //Длина массива int expected_length = 5; //Наименования string expected_product_0_ProductName = "Волотовской"; string expected_product_1_ProductName = "Русский"; string expected_product_2_ProductName = "Вкусная"; string expected_product_3_ProductName = "Грузинский"; string expected_product_4_ProductName = "Нарезной"; // act products = ParseString.GetData(GetManufacturingString()); // assert //Длина массива Assert.AreEqual(expected_length, products.Length); //Проверка наименования Assert.AreEqual(expected_product_0_ProductName, products[0].ProductName); Assert.AreEqual(expected_product_1_ProductName, products[1].ProductName); Assert.AreEqual(expected_product_2_ProductName, products[2].ProductName); Assert.AreEqual(expected_product_3_ProductName, products[3].ProductName); Assert.AreEqual(expected_product_4_ProductName, products[4].ProductName); }
public void SortFoodsByCalorieContent_Test() { // arrange Products[] products; Products[] сalorie_foods; double product_0_expected_сalorie = 646.599; double product_1_expected_сalorie = 859.13; double product_2_expected_сalorie = 1092; double product_3_expected_сalorie = 1556.6; double product_4_expected_сalorie = 1772.6; double delta = 0.001; // act products = ParseString.GetData(GetManufacturingString()); сalorie_foods = new Products[products.Length]; ProductsSort.SortFoodsByCalorieContent(products, ref сalorie_foods); // assert Assert.AreEqual(product_0_expected_сalorie, сalorie_foods[0].Calories, delta); Assert.AreEqual(product_1_expected_сalorie, сalorie_foods[1].Calories, delta); Assert.AreEqual(product_2_expected_сalorie, сalorie_foods[2].Calories, delta); Assert.AreEqual(product_3_expected_сalorie, сalorie_foods[3].Calories, delta); Assert.AreEqual(product_4_expected_сalorie, сalorie_foods[4].Calories, delta); }
public void StringHex() { Parser p = new Parser(StringToStream("<6465>")); ParseString o = p.ParseObject() as ParseString; Assert.NotNull(o); Assert.True(o.Value == "de"); }
public void StringLiteral() { Parser p = new Parser(StringToStream("(de)")); ParseString o = p.ParseObject() as ParseString; Assert.NotNull(o); Assert.True(o.Value == "de"); }
public void TestDigit1to9() { string fileName = @"C:\Users\Olivier\Documents\Visual Studio 2013\Projects\ConsoleApplication1\TestFile1to9.txt"; ParseString parser = new ParseString(); string accountString = parser.getAccountNumberFromFile(fileName); Assert.AreEqual("123456789", accountString); }
private static T ToValue <T>(string str, T defaultValue, ParseString <T> parseAction) { T value = defaultValue; if (string.IsNullOrEmpty(str) || !parseAction(str, out value)) { return(defaultValue); } return(value); }
private static void AssertParseFail <T>(ParseString <T> parser, string s) { AssertParseFailCore(parser, s); #if !NO_IO var parseReaderMtd = parser.Method.DeclaringType.GetMethod(parser.Method.Name, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static, binder: null, new[] { typeof(System.IO.TextReader), typeof(ParserContext) }, modifiers: null); var parseReaderFnc = (ParseReader <T>)Delegate.CreateDelegate(typeof(ParseReader <T>), parseReaderMtd); var parserWithReader = ParseWithReader(parseReaderFnc); AssertParseFailCore(parserWithReader, s); #endif }
public void StringLiteral() { Parser p = new Parser(StringToStream("1 0 obj\n(de)\nendobj")); ParseIndirectObject i = p.ParseIndirectObject() as ParseIndirectObject; Assert.NotNull(i); Assert.True(i.Id == 1); Assert.True(i.Gen == 0); Assert.NotNull(i.Object); ParseString o = i.Object as ParseString; Assert.NotNull(o); Assert.True(o.Value == "de"); }
private static void AssertParseFailCore <T>(ParseString <T> parser, string s) { foreach (var prefix in new[] { "", " ", ",", "[" }) { foreach (var suffix in new[] { "", " ", ",", "]" }) { var str = prefix + s + suffix; var i = prefix.Length; var b = i; var ctx = GetParserContext(); Assert.ThrowsException <Nuqleon.Json.Parser.ParseException>(() => parser(str, str.Length, ref i, ctx)); } } }
public void FindFoodsBigestThenValueIngredient_Test() { // arrange Products[] products; Products[] find_foods_bigest_then_value; string ingredient = "Сахар"; double ingredient_val = 0.005; string expected_product_name = "Нарезной"; // act products = ParseString.GetData(GetManufacturingString()); find_foods_bigest_then_value = new Products[products.Length]; ProductsSort.FindFoodsBigestThenValueIngredient(ingredient, ingredient_val, products, ref find_foods_bigest_then_value); // assert // Должен определиться Нарезной Assert.AreEqual(expected_product_name, find_foods_bigest_then_value[0].ProductName); }
private static void AssertParseCore <T>(ParseString <T> parser, string s, T expected) { foreach (var prefix in new[] { "", " ", ",", "[" }) { foreach (var suffix in new[] { "", " ", ",", "]" }) { var str = prefix + s + suffix; var i = prefix.Length; var b = i; var ctx = GetParserContext(); var res = parser(str, str.Length, ref i, ctx); Assert.AreEqual(expected, res); Assert.AreEqual(b + s.Length, i); } } }
public void FindFoodsByPriceAndByCalorieContent_Test() { // arrange Products[] products; Products[] find_foods_by_price_and_by_calorie; double expected_сalorie = 1092; double expected_price = 0.6376; string expected_product_name = "Грузинский"; double delta = 0.001; // act products = ParseString.GetData(GetManufacturingString()); find_foods_by_price_and_by_calorie = new Products[products.Length]; ProductsSort.FindFoodsByPriceAndByCalorieContent(expected_сalorie, expected_price, products, ref find_foods_by_price_and_by_calorie); // assert Assert.AreEqual(expected_сalorie, find_foods_by_price_and_by_calorie[0].Calories, delta); Assert.AreEqual(expected_price, find_foods_by_price_and_by_calorie[0].Price, delta); // Должен определиться Грузинский Assert.AreEqual(expected_product_name, find_foods_by_price_and_by_calorie[0].ProductName); }
public void GetPrice_Test() { // arrange Products[] products; //Цена double expected_product_0_price = 0.7659; //убираем дробную часть double expected_product_1_price = 0.9306; double expected_product_2_price = 0.3154; double expected_product_3_price = 0.6376; double expected_product_4_price = 1.0631; double delta = .001; // act products = ParseString.GetData(GetManufacturingString()); // assert //Проверка цены Assert.AreEqual(expected_product_0_price, products[0].Price, delta); Assert.AreEqual(expected_product_1_price, products[1].Price, delta); Assert.AreEqual(expected_product_2_price, products[2].Price, delta); Assert.AreEqual(expected_product_3_price, products[3].Price, delta); Assert.AreEqual(expected_product_4_price, products[4].Price, delta); }
public void FindFoodsNumberIngredientsGreaterThanTheValue_Test() { // arrange Products[] products; Products[] find_foods_number_ingredients_greater_than_the_value; int count = 0; int expected_quantity = 4; // act products = ParseString.GetData(GetManufacturingString()); find_foods_number_ingredients_greater_than_the_value = new Products[products.Length]; ProductsSort.FindFoodsNumberIngredientsGreaterThanTheValue(3, products, find_foods_number_ingredients_greater_than_the_value); foreach (var item in find_foods_number_ingredients_greater_than_the_value) { if (item != null) { count++; } } // assert Assert.AreEqual(expected_quantity, count); }
public async Task <IActionResult> UpdateBook(int bookId, [FromBody] SaveBookResource bookResource) { var book = await unitOfWork.Books.GetBook(bookId); var room = await unitOfWork.Rooms.Get(bookResource.RoomId); if (book == null || room == null) { return(NotFound()); } if (book.RoomId != bookResource.RoomId) { await ChangeRoom(book, room); } book.GuestNumber = bookResource.GuestNumber; book.RoomRate = bookResource.RoomRate; book.CheckOut = ParseString.ParseStringToDateTime(bookResource.CheckOut); await unitOfWork.CompleteAsync(); return(Ok(mapper.Map <Book, BookResource>(book))); }
static void Main(string[] args) { var pusher = new Pusher(pusherAppId, pusherAppKey, pusherAppSecret); TwitterAuth auth = new TwitterAuth(); SentimentAnalysis analyze = new SentimentAnalysis(); ParseString parser = new ParseString(); var filteredStream = Stream.CreateFilteredStream(); filteredStream.AddTrack("lol"); filteredStream.MatchingTweetReceived += (sender, arg) => { if (arg.Tweet.Coordinates != null) { string sentiment = analyze.Analyze(parser.Parse(arg.Tweet.Text)); MyTweet thisTweet = new TweetWithCoords(arg.Tweet.Text, sentiment, arg.Tweet.Coordinates.Latitude.ToString(), arg.Tweet.Coordinates.Longitude.ToString()); pusher.Trigger("tweetStream", "tweetEvent", new { message = thisTweet }); Console.WriteLine(arg.Tweet.Text); Console.WriteLine("coords: " + arg.Tweet.Coordinates.Latitude + ", " + arg.Tweet.Coordinates.Longitude); Console.WriteLine(sentiment); } else if (arg.Tweet.Place != null) { string sentiment = analyze.Analyze(parser.Parse(arg.Tweet.Text)); MyTweet thisTweet = new TweetWithPlace(arg.Tweet.Text, sentiment, arg.Tweet.Place.Name); pusher.Trigger("tweetStream", "tweetEventWithPlace", new { message = thisTweet }); Console.WriteLine(arg.Tweet.Text); Console.WriteLine("place: " + arg.Tweet.Place.Name); Console.WriteLine(sentiment); } }; while (true) { filteredStream.StartStreamMatchingAllConditions(); } }
public void GetCalories_Test() { // arrange Products[] products; //Калорийность double expected_product_0_calories = 1556.6; double expected_product_1_calories = 859.13; double expected_product_2_calories = 646.59; double expected_product_3_calories = 1092; double expected_product_4_calories = 1772.6; double delta = 0.01; // act products = ParseString.GetData(GetManufacturingString()); // assert //Проверка калорийности Assert.AreEqual(expected_product_0_calories, products[0].Calories, delta); Assert.AreEqual(expected_product_1_calories, products[1].Calories, delta); Assert.AreEqual(expected_product_2_calories, products[2].Calories, delta); Assert.AreEqual(expected_product_3_calories, products[3].Calories, delta); Assert.AreEqual(expected_product_4_calories, products[4].Calories, delta); }
public MappingProfiler() { CreateMap <Book, BookResource>() .ForMember(br => br.Guests, opt => opt .MapFrom(s => s.Guests.Select(x => new GuestResource { Id = x.Guest.Id, Cpf = x.Guest.Cpf, Nome = x.Guest.Nome, Fone = x.Guest.Fone, DtNascimento = x.Guest.DtNascimento, Email = x.Guest.Email, Endereco = new EnderecoResource { Uf = x.Guest.Uf, Cidade = x.Guest.Cidade, Logradouro = x.Guest.Logradouro, Bairro = x.Guest.Bairro, Numero = x.Guest.Numero, Cep = x.Guest.Cep, Prefixo = x.Guest.Prefixo } }))); CreateMap <SaveBookResource, Book>() .ForMember(sbr => sbr.Guests, opt => opt.Ignore()) .ForMember(sbr => sbr.CheckIn, opt => opt.Ignore()) .ForMember(sbr => sbr.CheckOut, opt => opt.Ignore()) .ForMember(sbr => sbr.Id, opt => opt.Ignore()) .AfterMap((sbr, b) => { // Remove unselected roomBeds var guets = b.Guests.Where(f => !sbr.Guests.Any(x => x == f.GuestId)).ToList(); foreach (var f in guets) { b.Guests.Remove(f); } // Add new RoomBeds var addedGuets = sbr.Guests.Where(x => !b.Guests.Any(f => f.GuestId == x)).Select(x => new GuestBook { GuestId = x }).ToList(); foreach (var f in addedGuets) { b.Guests.Add(f); } b.CheckIn = DateTime.Now; b.TotalBill = sbr.RoomRate; if (String.IsNullOrEmpty(sbr.CheckOut)) { b.CheckOut = DateTime.Now.AddDays(1); } else { b.CheckOut = ParseString.ParseStringToDateTime(sbr.CheckOut); } }); CreateMap <Guest, GuestResource>() .ForMember(gr => gr.Endereco, opt => opt .MapFrom(g => new EnderecoResource { Uf = g.Uf, Cidade = g.Cidade, Logradouro = g.Logradouro, Bairro = g.Bairro, Numero = g.Numero, Cep = g.Cep, Prefixo = g.Prefixo })); CreateMap <GuestResource, Guest>() .ForMember(g => g.Uf, opt => opt.MapFrom(gr => gr.Endereco.Uf)) .ForMember(g => g.Cidade, opt => opt.MapFrom(gr => gr.Endereco.Cidade)) .ForMember(g => g.Logradouro, opt => opt.MapFrom(gr => gr.Endereco.Logradouro)) .ForMember(g => g.Bairro, opt => opt.MapFrom(gr => gr.Endereco.Bairro)) .ForMember(g => g.Numero, opt => opt.MapFrom(gr => gr.Endereco.Numero)) .ForMember(g => g.Cep, opt => opt.MapFrom(gr => gr.Endereco.Cep)) .ForMember(g => g.Prefixo, opt => opt.MapFrom(gr => gr.Endereco.Prefixo)); CreateMap <Bed, KeyValuePairResource>() .ForMember(r => r.Name, opt => opt.MapFrom(v => v.Description));;; CreateMap <RoomState, KeyValuePairResource>() .ForMember(r => r.Name, opt => opt.MapFrom(v => v.State)); CreateMap <RoomType, KeyValuePairResource>() .ForMember(r => r.Name, opt => opt.MapFrom(v => v.Description));; CreateMap <SaveRoomResource, Room>() .ForMember(r => r.Id, opt => opt.Ignore()) .ForMember(r => r.Beds, opt => opt.Ignore()) .AfterMap((rr, r) => { // Remove unselected roomBeds var roomBeds = r.Beds.Where(f => !rr.Beds.Any(x => x.BedId == f.BedId)).ToList(); foreach (var f in roomBeds) { r.Beds.Remove(f); } // Add new RoomBeds var addedRoomBeds = rr.Beds.Where(x => !r.Beds.Any(f => f.BedId == x.BedId)).Select(x => new RoomBed { BedId = x.BedId, NumberBeds = x.NumberBeds }).ToList(); foreach (var f in addedRoomBeds) { f.RoomId = r.Id; r.Beds.Add(f); } }); CreateMap <Room, RoomResource>() .ForMember(rr => rr.RoomType, opt => opt .MapFrom(r => new KeyValuePairResource { Id = r.RoomType.Id, Name = r.RoomType.Description })) .ForMember(rr => rr.RoomState, opt => opt .MapFrom(r => new KeyValuePairResource { Id = r.RoomState.Id, Name = r.RoomState.State })) .ForMember(rr => rr.Beds, opt => opt .MapFrom(r => r.Beds .Select(rb => new RoomBedResource { BedId = rb.Bed.Id, Name = rb.Bed.Description, NumberBeds = rb.NumberBeds }))) .ForMember(rr => rr.CurrentBook, opt => opt.MapFrom(r => new BookResource { Id = r.CurrentBook.Id, CheckIn = r.CurrentBook.CheckIn, CheckOut = r.CurrentBook.CheckOut, Room = null, GuestNumber = r.CurrentBook.GuestNumber, RoomRate = r.CurrentBook.RoomRate, TotalBill = r.CurrentBook.TotalBill, Guests = r.CurrentBook.Guests .Select(x => new GuestResource { Id = x.Guest.Id, Cpf = x.Guest.Cpf, Nome = x.Guest.Nome, Fone = x.Guest.Fone, DtNascimento = x.Guest.DtNascimento, Email = x.Guest.Email, Endereco = null }).ToList() })); }