public void Test() { var rand = new Random(3); List<string> list1 = new List<string>(); WeakList<string> list2 = new WeakList<string>(); for (int x = 0; x < 1000; x++) { var str = x.ToString(); list1.Add(str); list2.Add(str); if (!list1.SequenceEqual(list2)) throw new Exception("Lists are not the same."); } for (int x = 1000; x < 2000; x++) { var str = x.ToString(); var removeItem = list1[rand.Next(list1.Count)]; list1.Remove(removeItem); list2.Remove(removeItem); if (!list1.SequenceEqual(list2)) throw new Exception("Lists are not the same."); list1.Add(str); list2.Add(str); if (!list1.SequenceEqual(list2)) throw new Exception("Lists are not the same."); } for (int x = 0; x < 100; x++) { list1.RemoveAt(rand.Next(list1.Count)); GC.Collect(); if (!list1.SequenceEqual(list2)) throw new Exception("Lists are not the same."); } list2.Clear(); foreach (var data in list2) throw new Exception(); }
public void TestDifferingLists() { var x = new List<int> {1, 2, 3, 4, 5, 6}; var y = new List<int> {1, 2, 3, 4, 5, 7}; ApproveException(() => x.SequenceEqual(y)); }
public void RemoveWithEmptyItems() { ICollection<int> col = new List<int> { 1, 2, 3 }; col.Remove(new int[] { }); Assert.IsTrue(col.SequenceEqual(new [] { 1, 2, 3 })); }
public void RemoveAll() { ICollection<int> col = new List<int> { 1, 2, 3, 4, 5 }; col.RemoveAll(x => x % 2 == 0); Assert.IsTrue(col.SequenceEqual(new [] { 1, 3, 5 })); }
public void RemoveItems() { ICollection<int> col = new List<int> { 1, 2, 3, 4, 5 }; col.Remove(new int[] { 2, 4 }); Assert.IsTrue(col.SequenceEqual(new [] { 1, 3, 5 })); }
public void story_data_is_observed_during_invocation() { var data = new List<KeyValuePair<string, object>>() { new KeyValuePair<string, object>("bool_value", true), new KeyValuePair<string, object>("int_value", 123), new KeyValuePair<string, object>("string_value", "test!"), }; var handlerRules = new Ruleset<IStory, IStoryHandler>() { Rules = { new PredicateRule( _ => true, // always run for story _ => new ActionHandler( (story) => Assert.AreEqual(0, story.Data.Count()), // make sure OnStart() is invoked with zero data items. (story, task) => Assert.IsTrue(data.SequenceEqual(story.Data))) // make sure OnStop() is invoked with 3 data items. ), }, }; new Story("testStory", handlerRules).Run(story => { foreach (var kvp in data) { story.Data[kvp.Key] = kvp.Value; } }); }
public void RemoveWithNullItems() { ICollection<int> col = new List<int> { 1, 2, 3 }; col.Remove((int[])null); Assert.IsTrue(col.SequenceEqual(new [] { 1, 2, 3 })); }
public void TestGetRandomItemsInNonUniformDistribution() { var items = GetNonUniformlyDistributedItems(10).ToList(); var randomItemRetriever = new RandomItemRetriever<IProbabilityWeightedItem>(_randomGenerator, items); var actualItems = Enumerable.Range(0, 10) .Select(counter => randomItemRetriever.NextItem()) .ToList(); var expectedItems = new List<IProbabilityWeightedItem> { items[0], items[1], items[1], items[2], items[2], items[2], items[3], items[3], items[3], items[3] }; Assert.IsTrue(expectedItems.SequenceEqual(actualItems)); }
public void ParseTest(List<TimePeriodToken> TimePeriodTokens, List<Shift> expectedShifts) { var parser = new ShiftsFactory(TimePeriodTokens, task, date, interval, exceedingAllowed); var actualShifts = parser.Parse(); Assert.IsTrue(expectedShifts.SequenceEqual<Shift>(actualShifts)); }
public void SetEquality() { var a = new List<int> { 1, 2, 3 }; var b = new List<int> { 1, 2, 3 }; var result = a.SequenceEqual(b); Assert.IsTrue(result); }
public void TaskFactoryMakeShiftTest(Model.Task test, List<ShiftsSpecification> shiftSpecList, List<Model.Shift> expectedShifts) { var parser = new TaskFactory(); var actualShifts = parser.MakeShifts(test, shiftSpecList); Assert.IsTrue(expectedShifts.SequenceEqual(actualShifts)); }
public void WorkerFactoryMakeIndisposedTest(Model.Worker test, List<IndisposedSpecification> indisposedSpecList, List<Model.Indisposed> expectedIndisposeds) { var parser = new WorkerFactory(); var actualShifts = parser.MakeIndisposeds(test, indisposedSpecList); Assert.IsTrue(expectedIndisposeds.SequenceEqual(actualShifts)); }
public void ScanTest(string shiftsField, List<TimePeriodToken> expectedTokens) { var scanner = new TimePeriodScanner(shiftsField); scanner.Scan(); var actualTokens = scanner.Tokens; Assert.IsTrue(expectedTokens.SequenceEqual<TimePeriodToken>(actualTokens)); }
public void PedidoTemProdutoCliente() { var clientes = new List<Cliente> { new Cliente("Gabriel") }; var produto = new Produto("batata", 2.99m); var pedido = new Pedido(produto, clientes); Assert.AreEqual(produto, pedido.Produto); Assert.IsTrue(clientes.SequenceEqual(pedido.Clientes), "clientes"); }
public void TestValidateAllValidRecords() { List<RawStudentInfo> records = new List<RawStudentInfo> { new RawStudentInfo{FirstName="John", LastName="Conn", Age="20", Sex = "Male"}, new RawStudentInfo{FirstName="Sarah", LastName="Libouee", Age="25", Sex = "Female"}, new RawStudentInfo{FirstName="Lucia", LastName="Fabi", Age="22", Sex = "Female"} }; Assert.IsTrue(records.SequenceEqual(stService.GetRecords(records, "En-US").ValidRecords)); }
public void Can_Be_Enumerated() { var expectedDirectoryNames = new List<string>{ "1000", "1001" }; var expectedUrls = expectedDirectoryNames.Select(GetUrl); expectedDirectoryNames.ForEach(name => CreateDirectory(name)); var directories = Sut.GetDirectories("").ToList(); Assert.That(expectedDirectoryNames.SequenceEqual(directories), String.Join(",", directories)); }
public void GetLocalReferencesTest() { var expected = new List<string> { "DummyAssembly1.dll", "DummyAssembly2.dll", }; var actual = AssemblyAnalyzer.GetLocalReferences("DummyApplication.exe"); Assert.IsTrue(expected.SequenceEqual(actual)); }
private static void Test(TypeModel m) { var list = new List<object> { new A { Id = "Abracadabra" }, new B { Id = "Focuspocus" }, new A { Id = "Abracadabra" }, }; using (var ms = new MemoryStream()) { m.Serialize(ms, list); ms.Position = 0; var list2 = (List<object>)m.Deserialize(ms, null, typeof(List<object>)); Debug.Assert(list.SequenceEqual(list2)); File.WriteAllBytes(@"output.dump", ms.ToArray()); } }
public void Each_ExecuteCorrectNumberOfTimesWithCorrectValue() { var items = new List<int>(); Enumerable.Range(1, 10) .SmartLoop() .Each(items.Add) .Execute(); Assert.AreEqual(10, items.Count); Assert.IsTrue(items.SequenceEqual(Enumerable.Range(1, 10))); }
public void StringebisListEqual() { var l1 = new List<string>() { "a", "b", "c", "d", "f" }; var l2 = new List<string>() { "a", "f", "c", "d"}; l1.Sort(); l2.Sort(); foreach (var item in l2) { Console.WriteLine(item); } Console.WriteLine(l1.SequenceEqual(l2)); }
public void Can_Be_Enumerated_With_Filter_But_Filter_Is_Ignored() { var paths = new List<string> { "1001/test1.dat", "1001/test2.txt" }; paths.ForEach(path => Sut.AddFile(path, CreateTestStream())); var files = Sut.GetFiles("1001/", "*.txt").ToList(); Assert.That(paths.SequenceEqual(files), String.Join(",", files)); }
public void CanConcatEventStreams() { var subject1 = new EventSubject<TestModel, int, IEventContext>(); var subject2 = new EventSubject<TestModel, int, IEventContext>(); var stream = EventObservable.Concat(subject1, subject2); List<int> received = new List<int>(); stream.Observe((m, e, c) => received.Add(e)); subject1.OnNext(_model, 1, _eventContext); subject2.OnNext(_model, 2, _eventContext); subject1.OnNext(_model, 3, _eventContext); subject2.OnNext(_model, 4, _eventContext); Assert.IsTrue(received.SequenceEqual(new[] {1, 2, 3, 4})); }
public void ForEach() { Spec.ForAny<int[]>(xs => { var x = new List<int>(); xs.AsQueryExpr().ForEach(num => x.Add(num)).Run(); var y = new List<int>(); xs.ToList().ForEach(num => y.Add(num)); return x.SequenceEqual(y); }).QuickCheckThrowOnFailure(); }
public void PaymentDetailComparer_Returns_False_If_Are_Not_Equal() { var firstPaymentDetail = new PaymentDetail { Description = "Refaktura za wsdfode", MeasureUnit = "szt.", PricePerUnit = 53, Quantity = 1 }; var secondPaymentDetail = new PaymentDetail { Description = "czynsz", MeasureUnit = "szt.", PricePerUnit = 45333, Quantity = 5 }; var thirdPaymentDetail = new PaymentDetail { Description = "Refaktura za wode", MeasureUnit = "szt.", PricePerUnit = 53, Quantity = 1 }; var fourthPaymentDetail = new PaymentDetail { Description = "czynsz", MeasureUnit = "szt.", PricePerUnit = 45333, Quantity = 5 }; var aPaymentDetails = new List<PaymentDetail> { firstPaymentDetail, secondPaymentDetail }; var bPaymentDetails = new List<PaymentDetail> { thirdPaymentDetail, fourthPaymentDetail }; bool equalAB = aPaymentDetails.SequenceEqual(bPaymentDetails, new PaymentDetailComparer()); Assert.IsFalse(equalAB); }
public void ShouldNavigateMaze() { var expectedPath = new[] { CreatePath(1), CreatePath(4), CreatePath(7), CreatePath(6), CreatePath(5), CreatePath(4), CreatePath(8), CreatePath(9), CreatePath(8), CreatePath(10) }; var path = new List<string>(); var configuration = HttpHostConfiguration.Create() .SetResourceFactory((type, instanceContext, request) => new RoomResource(Maze.NewInstance(), Monsters.NullEncounters()), (instanceContext, obj) => { }); // Workaround for serialization issue in Preview 4. // Must clear default XML formatter from Formatters before adding Atom formatter. var hostConfiguration = (HttpHostConfiguration) configuration; hostConfiguration.OperationHandlerFactory.Formatters.Clear(); hostConfiguration.OperationHandlerFactory.Formatters.Insert(0, AtomMediaType.Formatter); using (var host = new HttpConfigurableServiceHost(typeof(RoomResource), configuration, new Uri("http://" + Environment.MachineName + ":8081/rooms/"))) { host.Open(); var moveCount = 0; var client = AtomClient.CreateDefault(); IApplicationState state = new Started(new Uri("http://" + Environment.MachineName + ":8081/rooms/1"), ApplicationStateInfo.WithEndurance(5)); while (!state.IsTerminalState && moveCount++ < 20) { state = state.NextState(client); if (state.GetType().Equals(typeof (Exploring))) { path.Add(state.CurrentResponse.RequestMessage.RequestUri.AbsoluteUri); } } Assert.IsInstanceOf(typeof (GoalAchieved), state); Assert.IsTrue(path.SequenceEqual(expectedPath)); host.Close(); } }
public void DefaultSortMethodSortsProperFirstByScoreSecondByName() { DefaultSort sorter = new DefaultSort(); IPlayer first = new Player("Ivan", 2); IPlayer second = new Player("Angel", 1); IPlayer third = new Player("Angus", 1); IList<IPlayer> inputPlayers = new List<IPlayer> { first, third, second }; IList<IPlayer> expectedPlayers = new List<IPlayer> { first, second, third }; IList<IPlayer> actualPlayers = sorter.Sort(inputPlayers); Assert.IsTrue(expectedPlayers.SequenceEqual(actualPlayers), "The expected and the result lists of sorted Players are NOT equal!"); }
public void CanSetComponentExecutionOrder() { var updateOrder = new List<int>(); DualityApp.AppData = new DualityAppData(); Scene.SetComponentExecutionOrder(typeof(ComponentTwo), typeof(ComponentThree), typeof(ComponentOne)); var gameObject = new GameObject(); gameObject.AddComponent(new ComponentOne(updateOrder)); gameObject.AddComponent(new ComponentTwo(updateOrder)); gameObject.AddComponent(new ComponentThree(updateOrder)); Scene.Current.AddObject(gameObject); Scene.Current.Update(); Assert.True(updateOrder.SequenceEqual(new[] { 2, 3, 1 })); }
public void ComponentsAreDeactivatedInExecutionOrder() { var updateOrder = new List<int>(); var deactivationOrder = new List<int>(); DualityApp.AppData = new DualityAppData(); Scene.SetComponentExecutionOrder(typeof(ComponentTwo), typeof(ComponentOne), typeof(ComponentThree)); var gameObject = new GameObject(); gameObject.AddComponent(new ComponentOne(updateOrder, deactivationOrder)); gameObject.AddComponent(new ComponentFour(updateOrder, deactivationOrder)); Scene.Current.AddObject(gameObject); gameObject.Active = false; Assert.IsTrue(deactivationOrder.SequenceEqual(new[] { 1, 4 })); }
public void UnspecifiedComponentsRunLastAndInTheOrderTheyWereAdded() { var updateOrder = new List<int>(); DualityApp.AppData = new DualityAppData(); Scene.SetComponentExecutionOrder(typeof(ComponentTwo), typeof(ComponentOne)); var gameObject = new GameObject(); gameObject.AddComponent(new ComponentOne(updateOrder)); gameObject.AddComponent(new ComponentTwo(updateOrder)); gameObject.AddComponent(new ComponentFour(updateOrder)); gameObject.AddComponent(new ComponentThree(updateOrder)); Scene.Current.AddObject(gameObject); Scene.Current.Update(); Assert.True(updateOrder.SequenceEqual(new[] { 2, 1, 4, 3 })); }
public void AddRange() { var collection = new List<int>(); // Adds and returns the number of added items Assert.AreEqual(4, Extensions.AddRange(collection, new[] { 0, 1, 2, 3 })); Assert.AreEqual(4, collection.Count); // Adds and allows to iterate over the items as they are added Assert.IsTrue(collection.AddRangeEnumerable(new[] { 10, 20, 30 }).SequenceEqual(new[] { 10, 20, 30 })); var count = collection.Count; Assert.AreEqual(7, count); foreach (var item in collection.AddRangeEnumerable(new[] { 100, 200, 300 })) { GC.KeepAlive(item); count++; Assert.AreEqual(count, collection.Count); } Assert.IsTrue(collection.SequenceEqual(new[] { 0, 1, 2, 3, 10, 20, 30, 100, 200, 300 })); }