public void FirstInInsertOrder_OnPartialRange_ShouldReturnPartialRange() { // Arrange IOrganization org = new Organization(); List <Person> people = new List <Person> { new Person("Ivan", 350), new Person("Pesho", 1200), new Person("Mitko", 20), new Person("Maria", 0), new Person("Stamat", 1500), new Person("Alex", 850), new Person("Rosi", 3000) }; foreach (Person person in people) { org.Add(person); } // Act // IEnumerable<Person> Result() => org.FirstByInsertOrder(300); var s = org.FirstByInsertOrder(300); // Assert //CollectionAssert.AreEqual(people, Result()); CollectionAssert.AreEqual(people, s); }
public void GetWithNameSize_WithInvalidLength_ShouldThrow() { // Arrange IOrganization org = new Organization(); List <Person> people = new List <Person> { new Person("Ivan", 350), new Person("Pesho", 1200), new Person("Mitko", 20), new Person("Maria", 0), new Person("Stamat", 1500), new Person("Alex", 850), new Person("Rosi", 3000) }; foreach (Person person in people) { org.Add(person); } // Act IEnumerable <Person> GetWithNameSize() => org.GetWithNameSize(3); // Assert Assert.That(GetWithNameSize, Throws.ArgumentException); }
public static void Main() { //var person1 = new Person("Stamat", 1000); //var person2 = new Person("Bai Ivan", 4040); //var person3 = new Person("Stamat", 1000); //var person4 = new Person("Stamat", 0.99); //var org = new Organization(); //org.Add(person1); //org.Add(person2); //org.Add(person3); //org.Add(person4); //org.Contains(person1); //org.Contains(new Person("Stamat", 1000)); //org.ContainsByName("Stamat"); //org.ContainsByName("Bai Ivan"); //org.ContainsByName("Rachel"); IOrganization org = new Organization(); const int count = 100_000; Stopwatch stopwatch = Stopwatch.StartNew(); for (int i = 0; i < count; i++) { org.Add(new Person(i.ToString(), i)); } stopwatch.Stop(); System.Console.WriteLine(stopwatch.ElapsedMilliseconds); }
public void FirstByInsertOrder_On100000Elements_ShouldWorkFast() { // Arrange IOrganization org = new Organization(); const int count = 100000; List <Person> people = new List <Person>(); for (int i = 0; i < count; i++) { people.Add(new Person(i.ToString(), i)); org.Add(people[i]); } Stopwatch sw = Stopwatch.StartNew(); // Act //IEnumerable<Person> Result() => org.FirstByInsertOrder(50000); var s = org.FirstByInsertOrder(50000); // Assert //CollectionAssert.AreEqual(people.Take(50000), Result()); CollectionAssert.AreEqual(people.Take(50000), s); sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 40); }
/// <summary> /// Add a new organization. /// </summary> /// <param name="context"></param> /// <param name="cache"></param> protected override void InternalPOST(HttpContext context, HandlerTimedCache cache) { if (context.User.Identity.IsAuthenticated) { // We are currently logged in User user = UserHelper.GetUser(context.User.Identity.Name); if (user.IsSysAdmin()) { string name = WebUtil.GetParam(context, "name", true); Organization.Add(name); context.Response.Write("ok"); context.Response.StatusCode = (int)HttpStatusCode.Created; return; } else { context.Response.Write("not authorized"); context.Response.StatusCode = (int)HttpStatusCode.Forbidden; return; } } context.Response.Write("not authenticated"); context.Response.StatusCode = (int)HttpStatusCode.Forbidden; return; }
public void PeopleByInsertOrder_OnMultipleElements_ShouldReturnCorrectElements() { // Arrange IOrganization org = new Organization(); List <Person> people = new List <Person> { new Person("Ivan", 350), new Person("Pesho", 1200), new Person("Mitko", 20), new Person("Maria", 0), new Person("Stamat", 1500), new Person("Alex", 850), new Person("Rosi", 3000) }; foreach (Person person in people) { org.Add(person); } // Act IEnumerable <Person> Result() => org.PeopleByInsertOrder(); // Assert CollectionAssert.AreEqual(people, Result()); }
public void GetAtIndex_WithManyElements_ShouldReturnCorrectly() { // Arrange IOrganization org = new Organization(); List <Person> people = new List <Person> { new Person("Ivan", 350), new Person("Pesho", 1200), new Person("Mitko", 20), new Person("Maria", 0), new Person("Stamat", 1500), new Person("Alex", 850), new Person("Rosi", 3000) }; foreach (Person person in people) { org.Add(person); } // Act & Assert Assert.AreEqual(people[1], org.GetAtIndex(1)); Assert.AreEqual(people[3], org.GetAtIndex(3)); Assert.AreEqual(people[5], org.GetAtIndex(5)); }
public void SearchWithNameSize_OnExistingRange_ShouldReturnElementsInRange() { // Arrange IOrganization org = new Organization(); List <Person> people = new List <Person> { new Person("Ivan", 350), new Person("Pesho", 1200), new Person("Mitko", 20), new Person("Maria", 0), new Person("Stamat", 1500), new Person("Alex", 850), new Person("Rosi", 3000) }; foreach (Person person in people) { org.Add(person); } // Act //IEnumerable<Person> Search() => org.SearchWithNameSize(4, 5); var s = org.SearchWithNameSize(4, 5); // Assert //CollectionAssert.AreEquivalent(people.Where(x => x.Name.Length == 4 || x.Name.Length == 5), Search()); CollectionAssert.AreEquivalent(people.Where(x => x.Name.Length == 4 || x.Name.Length == 5), s); }
public void GetByName_OnManyRepeatingNames_ShouldWorkFast() { // Arrange IOrganization org = new Organization(); const int count = 100_000; int filler = 0; for (int i = 0; i < count; i++) { if (filler == 100) { filler = 0; } org.Add(new Person(filler.ToString(), i)); filler++; } Stopwatch sw = Stopwatch.StartNew(); // Act & Assert Assert.AreEqual(1000, org.GetByName("0").Count()); sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 30); }
public void SearchWithNameSize_OnNonExistingRange_ShouldReturnEmptyCollection() { // Arrange IOrganization org = new Organization(); List <Person> people = new List <Person> { new Person("Ivan", 350), new Person("Pesho", 1200), new Person("Mitko", 20), new Person("Maria", 0), new Person("Stamat", 1500), new Person("Alex", 850), new Person("Rosi", 3000) }; foreach (Person person in people) { org.Add(person); } // Act IEnumerable <Person> Search() => org.SearchWithNameSize(1, 3); // Assert CollectionAssert.IsEmpty(Search()); }
public void GetWithNameSize_On100000ElementsWithRandomLength_ShouldWorkFast() { // Arrange IOrganization org = new Organization(); const int count = 100000; int expected = 0; Random random = new Random(); for (int i = 0; i < count; i++) { int len = random.Next(1, 100); if (len == 35) { expected++; } org.Add(new Person(new string('a', len), 25)); } Stopwatch sw = Stopwatch.StartNew(); // Act //int GetWithNameSize() => org.GetWithNameSize(35).Count(); var s = org.GetWithNameSize(35).Count(); // Assert //Assert.AreEqual(expected, GetWithNameSize()); Assert.AreEqual(expected, s); sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 25); }
public void ContainsByName_On100000Elements_ShouldWorkFast() { // Arrange IOrganization org = new Organization(); const int count = 100_000; List <string> names = new List <string>(100_000); for (int i = 0; i < count; i++) { Person p = new Person(i.ToString(), i); org.Add(p); names.Add(p.Name); } // Act Stopwatch sw = Stopwatch.StartNew(); bool Result(int index) { return(org.ContainsByName(names[index])); } // Assert for (int i = 0; i < count; i++) { Assert.True(Result(i)); } sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 200); }
public void Contains_Existing100000Elements_ShouldWorkCorrectly() { // Arrange IOrganization org = new Organization(); const int count = 100_000; LinkedList <Person> people = new LinkedList <Person>(); for (int i = 0; i < count; i++) { people.AddLast(new Person(i.ToString(), i)); org.Add(people.Last.Value); } // Act Stopwatch sw = Stopwatch.StartNew(); LinkedListNode <Person> node = people.First; while (node != null) { Assert.True(org.Contains(node.Value)); node = node.Next; } sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 200); }
public void SearchWithNameSize_OnLargeRange_ShouldWorkFast() { // Arrange IOrganization org = new Organization(); const int count = 100_000; int expected = 0; Random random = new Random(); for (int i = 0; i < count; i++) { int len = random.Next(1, 100); if (len >= 35 && len <= 635) { expected++; } org.Add(new Person(new string('a', len), 25)); } Stopwatch sw = Stopwatch.StartNew(); // Act IEnumerable <Person> GetWithNameSize() => org.SearchWithNameSize(35, 635); // Assert Assert.AreEqual(expected, GetWithNameSize().Count()); sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 230); }
public void FirstByInsertOrder_WithParameters_ShouldReturnCorrectElements() { // Arrange IOrganization org = new Organization(); List <Person> people = new List <Person> { new Person("Ivan", 350), new Person("Pesho", 1200), new Person("Mitko", 20) }; foreach (Person person in people) { org.Add(person); } // Act //IEnumerable<Person> Result() => org.FirstByInsertOrder(3); var s = org.FirstByInsertOrder(); // Assert //CollectionAssert.AreEqual(people, Result()); CollectionAssert.AreEqual(people, s); }
public void GetAtIndex_With100000Elements_ShouldWorkFast() { // Arrange IOrganization org = new Organization(); const int count = 100000; List <Person> people = new List <Person>(); for (int i = 0; i < count; i++) { people.Add(new Person(i.ToString(), i)); org.Add(people[i]); } // Act & Assert Stopwatch sw = Stopwatch.StartNew(); Random rand = new Random(); for (int i = 0; i < 50000; i++) { int rnd = rand.Next(0, count - 1); Assert.AreEqual(people[rnd], org.GetAtIndex(rnd)); } sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 150); }
public static void Main() { IOrganization org = new Organization(); List <Person> people = new List <Person> { new Person("Ivan", 350), new Person("Pesho", 1200), new Person("Mitko", 20), new Person("Maria", 0), new Person("Stamat", 1500), new Person("Alex", 850), new Person("Rosi", 3000) }; foreach (Person person in people) { org.Add(person); } // Act IEnumerable <Person> GetWithNameSize() => org.GetWithNameSize(3); // Assert System.Console.WriteLine(GetWithNameSize()); }
public static void Main() { // Arrange IOrganization org = new Organization(); List <Person> people = new List <Person> { new Person("Ivan", 350), new Person("Pesho", 1200), new Person("Mitko", 20), new Person("Maria", 0), new Person("Stamat", 1500), new Person("Alex", 850), new Person("Rosi", 3000) }; foreach (Person person in people) { org.Add(person); } // Act & Assert var a = people.Where(x => x.Name.Length == 4); var b = org.GetWithNameSize(4); System.Console.WriteLine(); }
public static void Main() { try { IOrganization org = new Organization(); org.Add(new Person("Ivan", 350)); org.Add(new Person("Pesho", 1200)); org.Add(new Person("Mitko", 20)); org.Add(new Person("Maria", 0)); org.Add(new Person("Stamat", 1500)); org.Add(new Person("Alex", 850)); org.Add(new Person("Rosi", 3000)); var search = org.GetWithNameSize(-1); foreach (var person in search) { Console.WriteLine(person.Name); } } catch (ArgumentException e) { Console.WriteLine(e.Message); } }
public void Add() { var item = new ItemViewModel(); item.PropertyChanged += items_OnNotifyPropertyChanged; Item.Add(item); organization.Add(item); SelectedIndex = Item.IndexOf(item); }
public void Add() { var person = new PersonViewModel(); person.PropertyChanged += Person_OnNotifyPropertyChanged; People.Add(person); organization.Add(person); SelectedIndex = People.IndexOf(person); }
public void Add() { var person = new StudentViewModel(); person.PropertyChanged += Person_OnNotifyPropertyChanged; Student.Add(person); organization.Add(person); SelectedIndex = Student.IndexOf(person); }
public void GetByName_OnTwoUniqueNamesWith100000Elements_ShouldWorkFast() { // Arrange IOrganization org = new Organization(); const int count = 100_000; for (int i = 0; i < count; i++) { org.Add(new Person("0", i)); } org.Add(new Person("1", 1)); // Act & Assert Stopwatch sw = Stopwatch.StartNew(); Assert.AreEqual(1, org.GetByName("1").Count()); sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 20); }
public void Add_SingleElement_ShouldIncreaseCount() { // Arrange IOrganization org = new Organization(); Person p = new Person("pesho", 500); // Act org.Add(p); // Assert Assert.AreEqual(1, org.Count); }
public void Add_SingleElement_ShouldBeReturnedAsFirstElementByIndex() { // Arrange IOrganization org = new Organization(); Person p = new Person("pesho", 500); // Act org.Add(p); // Assert Assert.AreEqual(p, org.GetAtIndex(0)); }
public void Contains_ExistingElement_ShouldReturnTrue() { // Arrange IOrganization org = new Organization(); Person p = new Person("pesho", 500); // Act org.Add(p); bool actual = org.Contains(p); // Assert Assert.True(actual); }
public void Count_OnManyElements_ShouldWork() { // Arrange IOrganization org = new Organization(); const int count = 100_000; // Act & Assert for (int i = 0; i < count; i++) { Assert.AreEqual(i, org.Count); org.Add(new Person(i.ToString(), i)); } }
public void Add_50000Elements_ShouldWork() { // Arrange IOrganization org = new Organization(); const int count = 100_000; Stopwatch stopwatch = Stopwatch.StartNew(); for (int i = 0; i < count; i++) { org.Add(new Person(i.ToString(), i)); } stopwatch.Stop(); Assert.Less(stopwatch.ElapsedMilliseconds, 350, "The code runs too slow"); }
public void Add_SingleElement_ShouldAddElement() { // Arrange IOrganization org = new Organization(); Person p = new Person("pesho", 500); // Act org.Add(p); // Assert foreach (Person person in org) { if (person.Name == p.Name && person.Salary == p.Salary) { Assert.Pass(); } } }
public void PeopleByInsertOrder_On100000Elements_ShouldWorkFast() { // Arrange IOrganization org = new Organization(); const int count = 100_000; List <Person> people = new List <Person>(); for (int i = 0; i < count; i++) { people.Add(new Person(i.ToString(), i)); org.Add(people[i]); } Stopwatch sw = Stopwatch.StartNew(); // Act & Assert CollectionAssert.AreEqual(people, org.PeopleByInsertOrder()); sw.Stop(); Assert.Less(sw.ElapsedMilliseconds, 150); }