public static void Main() { int[] arr = new int[] { 3, -1, 15, 4, 17, 2, 33, 0 }; Console.WriteLine("arr = [{0}]", string.Join(", ", arr)); SortingMethods.SelectionSort(arr); Console.WriteLine("sorted = [{0}]", string.Join(", ", arr)); // Test sorting empty array // SelectionSort(new int[0]); // Test sorting single element array // SelectionSort(new int[1]); var currentValue = SearchMethods.BinarySearch(arr, -1000); Console.WriteLine(currentValue); currentValue = SearchMethods.BinarySearch(arr, 0); Console.WriteLine(currentValue); currentValue = SearchMethods.BinarySearch(arr, 17); Console.WriteLine(currentValue); currentValue = SearchMethods.BinarySearch(arr, 10); Console.WriteLine(currentValue); currentValue = SearchMethods.BinarySearch(arr, 1000); Console.WriteLine(currentValue); }
public static IEnumerable <T> Search <T>(this IEnumerable <T> list, PredicateString <T> predicate, SearchMethods method, params string[] searchstring) { string[] search = searchstring; for (int i = 0; i < search.Length; i++) { search[i] = search[i].ToLower(); } if (search.Length == 0) { foreach (T element in list) { yield return(element); } } else { foreach (T element in list) { if (CompareElement(element, predicate, method, search)) { yield return(element); } } } }
static void Main(string[] args) { int[] array; Random rand = new Random(); Console.Write("Enter length of array: "); int length = int.Parse(Console.ReadLine()); array = new int[length]; for (int i = 0; i < length; i++) { array[i] = rand.Next(100); } Array.Sort(array); for (int i = 0; i < length; i++) { Console.Write(array[i] + " "); } Console.WriteLine(); int indexToFind = rand.Next(length); int index = SearchMethods.BinarySearch(array, array[indexToFind]); Console.WriteLine(array[indexToFind] + " " + array[index] + " " + indexToFind + " " + index); Console.ReadKey(); }
public void TestCase649AddReviewTest(IProductReview review) { Application.Get().Browser.OpenUrl(URL); HomePage homePage; Assert.DoesNotThrow(() => { homePage = new HomePage(); }, "Step 1 Failed: Not home page"); List <ProductItem> searchPage = new SearchMethods() .Search(review.GetProductName()) .GetListProduct(); Assert.True(searchPage.Any(), "Step 3 Failed: No search results"); ProductPageLogic productPage = searchPage .FirstOrDefault(x => x.GetTextFromProductName() == review.GetProductName()) .ClickProductName(); Assert.True(productPage.ProductPage.IsProductPageOf(review), $"Step 4 Failed: Not {review.GetProductName()} product page"); ProductPageReviewLogic productReviewPage = productPage.ProductPage.ClickWriteReviewLink(); Assert.True(productReviewPage.ProductPageReview.IsReviewPage(), "Step 5 Failed: Not reviews page"); SuccessfullyAddedReviewPage addedReview = productReviewPage.InputValidReviewAndClickOnAddReviewButton(review); Assert.AreEqual(addedReview.GetTextFromSuccessAllert(), REVIEW_ADDED_ALERT_TEXT, "Step 6 Failed: " + REVIEW_ADDED_ALERT_TEXT + " message not appeared"); TestCase649 = true; }
public void TestCase704VerifyInvalidTextMessage(IProductReview validReview, IProductReview invalidReview) { Application.Get().Browser.OpenUrl(URL); HomePage homePage; Assert.DoesNotThrow(() => { homePage = new HomePage(); }, "Step 1 Failed: Not home page"); List <ProductItem> searchPage = new SearchMethods() .Search(validReview.GetProductName()) .GetListProduct(); Assert.True(searchPage.Any(), "Step 3 Failed: No search results"); ProductPageLogic productPage = searchPage .FirstOrDefault(x => x.GetTextFromProductName() == validReview.GetProductName()) .ClickProductName(); Assert.True(productPage.ProductPage.IsProductPageOf(validReview), $"Step 4 Failed: Not {validReview.GetProductName()} product page"); ProductPageReviewLogic productReviewPage = productPage.ProductPage.ClickWriteReviewLink(); Assert.True(productReviewPage.ProductPageReview.IsReviewPage(), "Step 5 Failed: Not reviews page"); UnsuccessfullyAddedReviewPage emptyReviewTextAlertPage = productReviewPage.InputReviewWithInvalidReviewTextAndClickOnAddReviewButton(validReview, invalidReview); Assert.AreEqual(emptyReviewTextAlertPage.GetTextFromWarningAlert(), INVALID_REVIEW_TEXT_ALERT_TEXT, "Step 7 Failed: " + INVALID_REVIEW_TEXT_ALERT_TEXT + " message not appeared"); }
private static bool CompareElement <T>(T track, PredicateString <T> pre, SearchMethods method, string[] searchstring) { switch (method) { case SearchMethods.ContainsAny: for (int i = 0; i < searchstring.Length; i++) { if (pre(track, searchstring[i])) { return(true); } } return(false); case SearchMethods.ContainsAll: for (int i = 0; i < searchstring.Length; i++) { if (!pre(track, searchstring[i])) { return(false); } } return(true); default: throw new InvalidOperationException("Unknown search method."); } }
public void SuccessAlertMessageIsDisplayedAfterAdding() { SearchMethods search = new SearchMethods(); bool result = search.Search(inputProduct.GetName()).AddAppropriateItemToWishList(inputProduct.GetName()).isSuccessMessageDisplayed(); Assert.IsTrue(result, "Success message is not displayed"); }
public void ProductComparison_AddProductFromSearchPage_SuccessfulMessageDisplayed(string product, string conparisonMessage) { SearchPage searchPage = new SearchMethods().Search(product) .AddAppropriateProductToComparison(product); Assert.AreEqual(conparisonMessage, searchPage.successAlertMessageText(), "An invalid comparison message on Search page is displayed."); }
public InjectionData(Type type, MemberInfo memberInfo, object[] injectionKeys, SearchMethods strategy, bool isOptional) { this.type = type; this.MemberInfo = memberInfo; this.InjectionKeys = injectionKeys; this.searchMethod = strategy; this.isOptional = isOptional; }
public void ProductComparison_AddProductFromProductPage_SuccessfulMessageDisplayed(string product, string conparisonMessage) { SearchPage searchPage = new SearchMethods().Search(product); SuccessfullyAddedProductForComparisonPage productPage = searchPage .OpenAppropriateProductPage(product) .ClickOnCompareProductButton(); Assert.AreEqual(conparisonMessage, productPage.GetTextFromCompareProductsPageMessage(), "An invalid comparison message on Product page is displayed."); }
public void ProductComparison_ClickingTwoTimesCompareButton_OneProductAdded(string product) { SearchPage searchPage = new SearchMethods().Search(product); ProductComparisonPage comparePage = searchPage .AddAppropriateProductToComparison(product) .OpenAppropriateProductPage(product) .ClickOnCompareProductButton() .ClickOnCompareProductsPageLink(); Assert.AreEqual(product, comparePage.GetLastProductNameText(), "The selected product was not added to the comparison table."); Assert.True(comparePage.CountColumns() == 1, "One product is added to the comparison table several times."); }
public void WishListWorks_AddingIphone_IsAdded() { TopBar topBar = new TopBar(); bool IsEmptyBeforeAdding = topBar.WishListButtonClick().IsEmpty(); SearchMethods search = new SearchMethods(); search.Search(inputProduct.GetName()).AddAppropriateItemToWishList(inputProduct.GetName()); bool IsEmptyAfterAdding = topBar.WishListButtonClick().IsEmpty(); Assert.AreNotEqual(IsEmptyBeforeAdding, IsEmptyAfterAdding, "Expected element is not added to wishlist"); addedToWishList = true; }
private async void GetMoreResults() { if (cleanupRunning || tasks.Count > 0) { return; } if (ctn == null) { ctn = new CancellationTokenSource(); } Random r = new Random(); SearchMethods meth = Settings.Instance.Searches[r.Next(0, Settings.Instance.Searches.Count - 1)]; int id = meth.SubId > 0 ? meth.SubId : meth.Id; Settings.Instance.LastFetch = DateTime.Now; List <Wallpaper> wallpapers = await WallpaperAbyssApiV2.WallpaperAbyss.QueryAsync(meth.Method, InfoLevels.Basic, 30, meth.Width, meth.Height, meth.SizeOp, id, meth.SearchTerm, meth.SortBy); if (wallpapers.Count == 0) { //label1.Text = WallpaperAbyssApiV2.WallpaperAbyss.LastResult; return; } string path0 = Settings.Instance.CacheDirectory + "\\" + wallpapers[0].id + Path.GetExtension(wallpapers[0].url_image); wallpapers[0].Image.Save(path0); Settings.Instance.AddCachedResults(wallpapers[0], path0); wallpapers.RemoveAt(0); foreach (Wallpaper paper in wallpapers) { Task taskA = new Task(() => { try { string path = Settings.Instance.CacheDirectory + "\\" + paper.id + Path.GetExtension(paper.url_image); paper.Image.Save(path); Settings.Instance.AddCachedResults(paper, path); } catch (Exception) { } }, ctn.Token); // Start the task. taskA.Start(); tasks.Add(taskA); } changesMade = true; }
private void ButtonSearch_Click(object sender, EventArgs e) { string keyword = FetchSearchKeyword(); if (barsIsTop) { ListMethods.LoadBars(SearchMethods.SearchForBars(barManager.barDictionary, keyword), this); } else { ListMethods.LoadDrinks(SearchMethods.SearchForDrinks(drinkManager.drinkDictionary, keyword), this); } }
public void CheckChangeProductPriceCurrency(string productName) { //Act SearchMethods searchmethods = new SearchMethods(); SearchPage search = searchmethods.Search(productName); cm.ChooseEuro(); string actualResult = cm.GetCurrencyFromProductItem(search); string expectedResult = cm.CurrentCurrencyFromMain; //Assert Assert.AreEqual(expectedResult, actualResult); }
public bool EditCar(Car car, int id, string make, string model, string registration, Fuel fuelType, DateTime lastService, string comments) { //Check for duplicate ID if (SearchMethods.SearchCar(this.company, car.ID, id) != null) { MessageBox.Show(string.Format("The car ID number {0} aleady exists", id)); return(false); } //Update company and refresh listbox car.UpdateInfo(id, make, model, registration, fuelType, lastService, comments); return(true); }
public void ProductComparison_TwoDifferentProducts_AddedToComparisonTable (string Desktop, string FirstDesktop, string SecondDesktop) { SearchPage searchPage = new SearchMethods().Search(Desktop); ProductComparisonPage comparePage = searchPage .AddAppropriateProductToComparison(FirstDesktop) .AddAppropriateProductToComparison(SecondDesktop) .ClickSuccessAlertMessageLink(); Assert.AreEqual(FirstDesktop, comparePage.GetFirstProductNameText(), "The selected product was not added to the comparison table."); Assert.AreEqual(SecondDesktop, comparePage.GetLastProductNameText(), "The selected product was not added to the comparison table."); Assert.True(comparePage.CountColumns() == 2, "All or one of products isn't added to the comparison table."); }
public void ProductComparison_AddedPreviouslyProduct_RemovedFromComparison(string product, string conparisonNoProductsMessage) { SearchPage searchPage = new SearchMethods().Search(product); EmptyProductComparisonPageWithMessage comparePage = searchPage .AddAppropriateProductToComparison(product) .OpenAppropriateProductPage(product) .ClickOnCompareProductButton() .ClickOnCompareProductsPageLink() .ClickRemoveFirstProduct(); Assert.True(comparePage.CountColumns() == 0, "A comparison table with at least one column " + "is present on the page after the product is removed."); Assert.AreEqual(conparisonNoProductsMessage, comparePage.GetNoProductsToCompareLabelText(), "An invalid comparison message is displayed."); }
public void ProductComparison_AddTwoDifferemntProducts_SuccessfulRemoveMessageDisplayed (string Desktop, string FirstDesktop, string SecondDesktop, string conparisonRemoveMessage) { SearchPage searchPage = new SearchMethods().Search(Desktop); ProductComparisonPageWithMessage comparePage = searchPage .AddAppropriateProductToComparison(FirstDesktop) .AddAppropriateProductToComparison(SecondDesktop) .ClickSuccessAlertMessageLink() .ClickRemoveLastProduct(); Assert.AreEqual(conparisonRemoveMessage, comparePage.GetSuccessMessageText(), "An invalid comparison message on Product page is displayed."); Assert.True(comparePage.CountColumns() == 1, "A comparison table with at least two columns " + "is present on the page after second product is removed."); }
public bool AddCar(int id, string make, string model, string registration, Fuel fuelType, DateTime lastService, string comments) { //Check for duplicate ID if (SearchMethods.SearchCar(this.company, id) != null) { MessageBox.Show(string.Format("The car ID number {0} aleady exists", id)); return(false); } //Add to list and update listbox this.company.Cars.Add(new Car(id, make, model, registration, fuelType, lastService, comments)); this.bindCarsToList(this.company.Cars); return(true); }
protected static FR_L5TR_GT_1748 Execute(DbConnection Connection, DbTransaction Transaction, P_L5TR_GT_1748 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_L5TR_GT_1748(); returnValue.Result = new L5TR_GT_1748(); int IsBilled = Parameter.SearchParameters.s_isBilled == true ? 1 : 0; int IsPerformed = Parameter.SearchParameters.s_isPerformed == true ? 1 : 0; int IsSheduled = Parameter.SearchParameters.s_isScheduled == true ? 1 : 0; returnValue.Result.page_size = Parameter.NumberOfElementsPerPage; returnValue.Result.current_page = Parameter.PageClicked; P_L5TR_GTDC_1426 count_param = new P_L5TR_GTDC_1426(); count_param.S_Practice = SearchMethods.getPracticeParameter(Parameter.SearchParameters.s_practice); count_param.statusParameters = SearchMethods.getStatusParameter(IsBilled, IsPerformed, IsSheduled, Parameter.SearchParameters.s_treatmentFrom, Parameter.SearchParameters.s_treatmentTo); count_param.s_Patient = SearchMethods.getPatientParameter(Parameter.SearchParameters.s_patientFirstName, Parameter.SearchParameters.s_patientLastName); count_param.s_HealthInsurance = SearchMethods.getPracticeParameter(Parameter.SearchParameters.s_healtInsurance); var recordCount = cls_Get_TreatmentlDataCount.Invoke(Connection, Transaction, count_param, securityTicket).Result.total_record_count; returnValue.Result.total_record_count = recordCount; returnValue.Result.total_page_count = (recordCount + Parameter.NumberOfElementsPerPage - 1) / Parameter.NumberOfElementsPerPage; var startRowIndex = (Parameter.PageClicked - 1) * Parameter.NumberOfElementsPerPage; returnValue.Result.start_row_index = startRowIndex; returnValue.Result.end_row_index = startRowIndex + returnValue.Result.page_size > recordCount ? recordCount : startRowIndex + returnValue.Result.page_size; /*@Get Treatments *------------------------------------------------*/ P_L5TR_GTD_1607 par = new P_L5TR_GTD_1607(); par.StartIndex = startRowIndex; par.NumberOfElements = Parameter.NumberOfElementsPerPage; par.S_Practice = count_param.S_Practice; par.statusParameters = count_param.statusParameters; par.s_Patient = count_param.s_Patient; par.s_HealthInsurance = count_param.s_HealthInsurance; returnValue.Result.treatments = cls_Get_TreatmentlData.Invoke(Connection, Transaction, par, securityTicket).Result.ToArray(); return(returnValue); #endregion UserCode }
private void lstCollectionLabels_SelectedIndexChanged(object sender, EventArgs e) { WallpaperAbyssApiV2.CollectionListItem item; item = WallpaperAbyssApiV2.WallpaperAbyss.GetCategoryList().Find((x => x.Name.Equals(lstCollectionLabels.Items[lstCollectionLabels.SelectedIndex].ToString(), StringComparison.InvariantCultureIgnoreCase))); List <WallpaperAbyssApiV2.CollectionListItem> subitems = null; // = WallpaperAbyssApiV2.WallpaperAbyss.GetSubCategoryList(item.Id); switch (cboLookupMethods.SelectedItem.ToString().ToLower()) { case "sub category": //Needs Collection subitems = WallpaperAbyssApiV2.WallpaperAbyss.GetSubCategoryList(item.Id); break; case "group": //Needs Collection subitems = WallpaperAbyssApiV2.WallpaperAbyss.GetGroupList(item.Id); break; } if (subitems != null) { SearchMethods sm = Settings.Instance.Searches[lstSearches.SelectedIndex]; bool found = false; lstSubCollection.Items.Clear(); foreach (WallpaperAbyssApiV2.CollectionListItem subItem in subitems) { lstSubCollection.Items.Add(subItem.Name); if (sm.SubId == subItem.Id) { lstSubCollection.SelectedIndex = lstSubCollection.Items.Count - 1; found = true; } } if (!found && lstSubCollection.Items.Count > 0) { lstSubCollection.SelectedIndex = 0; } } }
private static void TestSearch(ICredentialContext credential) { //// Step 1: Enter UserName and Password information //ICredentialContext credential = new CredentialContext //{ // UserName = "******", // Password = "******" //}; // Step 2: Create a method object var searchMethods = new SearchMethods(credential); // Step 3: Search using the search term ("Full Metal" in this case) string mangaResponse = searchMethods.SearchManga("Code Geass"); Console.WriteLine(mangaResponse); // Step 3: Search using the search term ("Full Metal" in this case) string animeResponse = searchMethods.SearchAnime("Full Metal"); Console.WriteLine(animeResponse); }
/// <summary> /// <para>Performs the My Trade Me method: /// Retrieve a member’s ledger. /// </para><para> /// Creates a query string using the parameters provided - parameters can be null if they are not required for the request. /// </para> /// REQUIRES AUTHENTICATION. /// </summary> /// <param name="criteria">The criteria.</param> /// <param name="page">Page number.</param> /// <param name="rows">Number of rows per page.</param> /// <returns>MemberLedger.</returns> public MemberLedger MemberLedger(MemberLedgerCriteria criteria, string page, string rows) { var query = Constants.MY_TRADEME + "/MemberLedger"; var conditions = "?"; _addAnd = false; if (!string.IsNullOrEmpty(string.Empty + criteria)) { query += "/" + criteria; } query += Constants.XML; conditions += SearchMethods.PageAndRowsHelper(page, rows, _addAnd); if (conditions.Equals("?")) { query += conditions; } return(this.MemberLedger(query)); }
/// <summary> /// <para>Performs the My Trade Me Method: /// Retrieve a member’s watchlist. /// </para><para>Creates a query string using the parameters provided - parameters can be null if they are not required for the request. /// </para> /// REQUIRES AUTHENTICATION. /// </summary> /// <param name="criteria">The criteria.</param> /// <param name="page">Page number.</param> /// <param name="rows">Number of rows per page.</param> /// <returns>Watchlist.</returns> public Watchlist Watchlist(WatchlistCriteria criteria, string page, string rows) { var query = String.Format(Constants.Culture, "{0}/{1}", Constants.MY_TRADEME, Constants.WATCHLIST); var conditions = "?"; _addAnd = false; if (!string.IsNullOrEmpty(string.Empty + criteria)) { query += "/" + criteria; } query += Constants.XML; conditions += SearchMethods.PageAndRowsHelper(page, rows, _addAnd); if (_addAnd) { query += conditions; } return(this.Watchlist(query)); }
/// <summary> /// <para>Performs the My Trade Me Method: /// Retrieve a list of lost items. /// </para><para> /// Creates a query string using the parameters provided - parameters can be null if they are not required for the request. /// </para> /// REQUIRES AUTHENTICATION. /// </summary> /// <param name="criteria">The criteria.</param> /// <param name="page">Page number.</param> /// <param name="rows">Number of rows per page.</param> /// <returns>Listings.</returns> public Listings LostItems(LostItemsCriteria criteria, string page, string rows) { var query = Constants.MY_TRADEME + "/Lost"; _addAnd = false; var conditions = "?"; if (!string.IsNullOrEmpty(string.Empty + criteria)) { query += "/" + criteria; } query += Constants.XML; conditions += SearchMethods.PageAndRowsHelper(page, rows, _addAnd); if (_addAnd) { query += conditions; } return(this.LostItems(query)); }
public void TestCase672CheckReviewTest(IProductReview review) { Assert.IsTrue(TestCase649 && TestCase670, "Blocked. Preconditions fail: add review test failed or approve review test failed"); Application.Get().Browser.OpenUrl(URL); HomePage homePage; Assert.DoesNotThrow(() => { homePage = new HomePage(); }, "Step 1 Failed: Not home page"); List <ProductItem> searchPage = new SearchMethods() .Search(review.GetProductName()) .GetListProduct(); Assert.True(searchPage.Any(), "Step 3 Failed: No search results"); ProductPageLogic productPage = searchPage .FirstOrDefault(x => x.GetTextFromProductName() == review.GetProductName()) .ClickProductName(); Assert.True(productPage.ProductPage.IsProductPageOf(review), $"Step 4 Failed: Not {review.GetProductName()} product page"); ProductPageReviewLogic productReviewPage = productPage.ProductPage.ClickWriteReviewLink(); Assert.True(productReviewPage.ProductPageReview.IsReviewPage(), "Step 5 Failed: Not reviews page"); bool hasReview = productReviewPage.ProductPageReview.ReviewExistInListOfReview(review); Assert.True(hasReview, "Step 6 Failed: Review not exist"); }
public void FindWithBinarySearch(int N, int min, int max, int key) { //An object that has randomly generated sorted array of N in [min, max] range int[] array = GeneratedArray.Generate(N, min, max); Stopwatch st1 = Stopwatch.StartNew(); SearchMethods bs = new SearchMethods(); int res1 = bs.BinarySearch(array, key); int count1 = bs.Iterations; st1.Stop(); Stopwatch st2 = Stopwatch.StartNew(); SearchMethods ls = new SearchMethods(); int res2 = ls.LinearSearch(array, key); int count2 = ls.Iterations; st2.Stop(); Stopwatch st3 = Stopwatch.StartNew(); SearchMethods ipS = new SearchMethods(); int res3 = ipS.InterpolationSearch(array, key); int count3 = ipS.Iterations; st3.Stop(); //Element [key] was found at position [result] in [time] ms - output to file using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"../../../../out/result.txt", true)) { file.WriteLine(String.Format("Params: Size={0}, Min={1}, Max={2}", N, min, max)); file.WriteLine(String.Format("Binary: Element {0} was found at position {1} in time {2} in {3} iterations", key, res1, st1.GetTimeString(), count1)); file.WriteLine(String.Format("Linear: Element {0} was found at position {1} in time {2} in {3} iterations", key, res2, st2.GetTimeString(), count2)); file.WriteLine(String.Format("Interp: Element {0} was found at position {1} in time {2} in {3} iterations\n", key, res3, st3.GetTimeString(), count3)); } }
public SearchMethodsFixture(CredentialContextFixture credentialContextFixture) { SearchMethods = new SearchMethods(credentialContextFixture.CredentialContext); }
public UnitySearchMethodMockup(MonoBehaviour callingScript, SearchMethods searchMethod, object mockup) { this.callingScript = callingScript; this.searchMethod = searchMethod; this.searchResult = mockup; }