public void TestParameterSerialization() { var decoder = new PackedDecoder(); var p = new List<Parameter>(); decoder.WriteParameters(p); Assert.AreNotEqual(0, p.Count); var c1 = p.Count; decoder.WriteParameters(p); Assert.AreEqual(c1, p.Count); decoder.ColorBPP = 4; var cf = new ColorFormat(12, 5, 6, 4, 1, 3, 18, 1); decoder.ColorFormat = cf; ((IPictureDecoderController)decoder).Width = 13; ((IPictureDecoderController)decoder).Height = 21; decoder.WriteParameters(p); Assert.AreEqual(1.ToString(), p.First(z => z.Name == "ppbyp").Value); Assert.AreEqual(cf.ToString(), p.First(z => z.Name == "ColorFormat").Value); Assert.AreEqual("13", p.First(z => z.Name == "Width").Value); Assert.AreEqual("21", p.First(z => z.Name == "Height").Value); var d2 = new PackedDecoder(); d2.ReadParameters(p); Assert.AreEqual(4, d2.ColorBPP); Assert.AreEqual(cf, d2.ColorFormat); Assert.AreEqual(13, ((IPictureDecoderController)decoder).Width); Assert.AreEqual(21, ((IPictureDecoderController)decoder).Height); }
public void Send_Given30TosAnd30Bccs_SendTwoBatches() { var senderMock = new Mock<IEmailSender>(); var service = new Portal.EmailService.EmailService(senderMock.Object); var tos = new List<string>(); var bccs = new List<string>(); const string from = "*****@*****.**"; const string subject = "Test Email"; const string body = "<div>Hallo test</div>"; for (var i = 0; i < 30; i++) tos.Add(string.Format("MyMail{0}@test.test", i)); for (var i = 0; i < 30; i++) bccs.Add(string.Format("MyBccMail{0}@test.test", i)); IList<SendEmailRequest> request = new List<SendEmailRequest>(); senderMock.SetupGet(s => s.MaxRecipientPerBatch).Returns(50); senderMock.Setup(s => s.Send(It.IsAny<SendEmailRequest>())).Callback<SendEmailRequest>(request.Add); service.Send(from, tos, bccs, subject, body); senderMock.Verify(s => s.Send(It.IsAny<SendEmailRequest>()), Times.Exactly(2)); Assert.That(request.Count, Is.EqualTo(2)); Assert.That(request.First().Destination.ToAddresses.Count, Is.EqualTo(30)); Assert.That(request.First().Destination.BccAddresses.Count, Is.EqualTo(20)); Assert.That(request.Skip(1).First().Destination.ToAddresses.Count, Is.EqualTo(0)); Assert.That(request.Skip(1).First().Destination.BccAddresses.Count, Is.EqualTo(10)); }
public void Given_selected_responsibilities_When_GetViewModel_Then_those_responsibilities_are_marked_as_selected() { // Given const int companyId = 12345; var templates = new List<StatutoryResponsibilityTemplateDto> { new StatutoryResponsibilityTemplateDto() { Id = 123L, Description = "description", ResponsibilityCategory = new ResponsibilityCategoryDto() { Category = "category"}, ResponsibilityReason = new ResponsibilityReasonDto() { Reason = "reason"}}, new StatutoryResponsibilityTemplateDto() { Id = 456L, Description = "description", ResponsibilityCategory = new ResponsibilityCategoryDto() { Category = "category"}, ResponsibilityReason = new ResponsibilityReasonDto() { Reason = "reason"} }, new StatutoryResponsibilityTemplateDto() { Id = 789L, Description = "description", ResponsibilityCategory = new ResponsibilityCategoryDto() { Category = "category"}, ResponsibilityReason = new ResponsibilityReasonDto() { Reason = "reason"} } }; _statutoryResponsibilityTemplateService .Setup(x => x.GetStatutoryResponsibilityTemplates()) .Returns(templates); // When var result = GetTarget() .WithCompanyId(companyId) .WithSelectedResponsibilityTemplates(new [] { templates.First().Id }) .GetViewModel(); // Then Assert.IsTrue(result.Responsibilities.Single(x => x.Id == templates.First().Id ).IsSelected); Assert.IsFalse(result.Responsibilities.Single(x => x.Id == templates.ElementAt(1).Id ).IsSelected); Assert.IsFalse(result.Responsibilities.Single(x => x.Id == templates.ElementAt(2).Id).IsSelected); }
public void CommaDelimited() { const string content = @"Name,WebSite,Created Google|,http://www.google.com|,9/4/98 Apple|,http://www.apple.com|,4/1/1976 Microsoft|,http://www.microsoft.com|,4/4/1975"; var fileName = Path.GetTempFileName(); File.WriteAllText(fileName, content); JunkResponse response; var request = new JunkRequest(fileName, "default.xml"); using (var scope = new AutofacJunkBootstrapper(request)) { var importer = scope.Resolve<JunkImporter>(); response = importer.Import(); } var companies = new List<Company>(); using (var cn = new SqlConnection(ConnectionString)) { companies.AddRange(cn.Query<Company>("SELECT Name,Website,Created FROM " + response.TableName + ";")); } Assert.AreEqual(3, companies.Count); var google = companies.First(c => c.Name == "Google|"); var apple = companies.First(c => c.Name == "Apple|"); Assert.AreEqual("http://www.google.com|", google.WebSite); Assert.AreEqual(Convert.ToDateTime("4/1/1976"), apple.Created); }
public static void Succeed(params Action[] assertions) { var errors = new List<Exception>(); foreach (var assertion in assertions) try { assertion(); } catch (Exception ex) { errors.Add(ex); } if (errors.Any()) { var ex = new AssertionException( string.Join(Environment.NewLine, errors.Select(e => e.Message)), errors.First()); // Use stack trace from the first exception to ensure first failed Assert is one click away ReplaceStackTrace(ex, errors.First().StackTrace); throw ex; } }
public void TestBindModel() { //{element}.{key} type의 from 데이터를 ICollection<KeyValue<String,String>으로 변환 var ctx = new ControllerContext(); var mockHc = new Mock<HttpContextBase>(); var mockHrc = new Mock<HttpRequestBase>(); ctx.RequestContext = new RequestContext(); mockHc.Setup(m => m.Request).Returns(mockHrc.Object); ctx.RequestContext.HttpContext = mockHc.Object; var nvc = new NameValueCollection(); nvc.Add("Options.US Shoe Size (Men's)", "10.5"); mockHrc.Setup(m => m.Form).Returns(nvc); var binder = new DynamicDictionaryObjectModelBinder(); var mbc = new ModelBindingContext(); var mmc = new Mock<ModelMetadata>(); mmc.Setup(p => p.Model).Returns(new DynamicDictionaryObject()); mbc.ModelMetadata = mmc.Object; dynamic output = binder.BindModel(ctx, mbc); ICollection<KeyValue> actual = output.Options; IList<KeyValue> expected = new List<KeyValue>(); expected.Add(new KeyValue() { Key = "US Shoe Size (Men's)", Value = "10.5" }); Assert.AreEqual(expected.Count, actual.Count); Assert.AreEqual(expected.First().Key, actual.First().Key); Assert.AreEqual(expected.First().Value, actual.First().Value); }
public void Couper() { var jeu = new List<Carte>(Paquet.TrenteDeuxCartes); jeu.Melanger(); var anciennePremiere = jeu.First(); var ancienneDerniere = jeu.Last(); jeu = jeu.Couper(); Check.That(jeu).HasSize(32); Check.That(jeu.First()).IsNotEqualTo(anciennePremiere); Check.That(jeu.Last()).IsNotEqualTo(ancienneDerniere); //Validation d'unicité des cartes var hashSet = new HashSet<Carte>(jeu); Check.That(hashSet).HasSize(32); }
public void SessionGracefullyWaitsPendingOperations() { Logger.Info("Starting SessionGracefullyWaitsPendingOperations"); var localCluster = Cluster.Builder().AddContactPoint(IpPrefix + "1").Build(); try { var localSession = (Session)localCluster.Connect(); //Create more async operations that can be finished var taskList = new List<Task>(); for (var i = 0; i < 1000; i++) { taskList.Add(localSession.ExecuteAsync(new SimpleStatement("SELECT * FROM system.schema_columns"))); } //Most task should be pending Assert.True(taskList.Any(t => t.Status == TaskStatus.WaitingForActivation), "Most task should be pending"); //Wait for finish Assert.True(localSession.WaitForAllPendingActions(60000), "All handles have received signal"); Assert.False(taskList.Any(t => t.Status == TaskStatus.WaitingForActivation), "All task should be completed (not pending)"); if (taskList.Any(t => t.Status == TaskStatus.Faulted)) { throw taskList.First(t => t.Status == TaskStatus.Faulted).Exception; } Assert.True(taskList.All(t => t.Status == TaskStatus.RanToCompletion), "All task should be completed"); localSession.Dispose(); } finally { localCluster.Shutdown(1000); } }
public void LawOfResistorsInSeriesTest(int in0) { Circuit sim = new Circuit(); var volt0 = sim.Create<DCVoltageSource>(); var volt1 = sim.Create<DCVoltageSource>(); var resCompare = sim.Create<Resistor>(in0 * 100); List<Resistor> resistors = new List<Resistor>(); for(int i = 0; i < in0; i++) resistors.Add(sim.Create<Resistor>()); sim.Connect(volt0.leadPos, resistors.First().leadIn); for(int i = 1; i < in0 - 1; i++) sim.Connect(resistors[i - 1].leadOut, resistors[i].leadIn); sim.Connect(volt0.leadNeg, resistors.Last().leadOut); sim.Connect(volt1.leadPos, resCompare.leadIn); sim.Connect(resCompare.leadOut, volt1.leadNeg); sim.doTicks(100); Assert.AreEqual(Math.Round(resistors.Last().getCurrent(), 12), Math.Round(resCompare.getCurrent(), 12)); }
public void Should_activate_upstream_deps_first() { var defaultsOrder = new List<Feature>(); var dependingFeature = new DependsOnOne_Feature { OnDefaults = f => defaultsOrder.Add(f) }; var feature = new MyFeature1 { OnDefaults = f => defaultsOrder.Add(f) }; var settings = new SettingsHolder(); var featureSettings = new FeatureActivator(settings); featureSettings.Add(dependingFeature); featureSettings.Add(feature); settings.EnableFeatureByDefault<MyFeature1>(); featureSettings.SetupFeatures(new FeatureConfigurationContext(null)); Assert.True(dependingFeature.IsActive); Assert.IsInstanceOf<MyFeature1>(defaultsOrder.First(), "Upstream deps should be activated first"); }
public void Eh_Um_Par() { var cartas = new List<Carta> { new Carta(NumeroCarta.C1, 'D'), new Carta(NumeroCarta.CJ, 'D'), new Carta(NumeroCarta.CQ, 'S'), new Carta(NumeroCarta.C9, 'H'), new Carta(NumeroCarta.CQ, 'C') }; Carta primeira = cartas.First(); bool tempar = false; for (int index = 0; index < cartas.Count; index++) { for (int i = index + 1; i < cartas.Count; i++) { if (cartas[index].Numero == cartas[i].Numero) { tempar = true; break; } } } Assert.AreEqual(true, tempar); }
public void Initial_snapshot_and_subsequent_deltas_yield_full_snapshot_each_time() { var key = "EURUSD"; // arrange var observations = new List<Update>(); _observableDictionary.Get(key) .Only(DictionaryNotificationType.Values) // ignore meta notifications .Select(dn => dn.Value) // select out the new value in the dictionary .Subscribe(observations.Add); // act _serverUpdateStream.OnNext(new Either<FullUpdate, DeltaUpdate>(new FullUpdate(key) { { "bid", "1.234"}, { "ask", "1.334"}, { "valueDate", "2014-07-16"} })); _serverUpdateStream.OnNext(new Either<FullUpdate, DeltaUpdate>(new DeltaUpdate(key) { { "bid", "1.233" }})); _serverUpdateStream.OnNext(new Either<FullUpdate, DeltaUpdate>(new DeltaUpdate(key) { { "ask", "1.333" }})); _serverUpdateStream.OnNext(new Either<FullUpdate, DeltaUpdate>(new DeltaUpdate(key) { { "bid", "1.231" }, { "ask", "1.331" }})); // assert observations.ForEach(update => Assert.AreEqual(4, update.Values.Count)); var first = observations.First(); var last = observations.Last(); Assert.AreEqual("1.234", first.Values["bid"]); Assert.AreEqual("1.334", first.Values["ask"]); Assert.AreEqual("1.231", last.Values["bid"]); Assert.AreEqual("1.331", last.Values["ask"]); }
public void Index_WhenCalls_SetsUpViewModelWithAllPlatformsAndSelectedList() { List<Platform> selectedPlatforms = new List<Platform>(); List<Platform> allPlatforms = new List<Platform> { new Platform(), new Platform() }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<Platform>> platformDbSetStub = TestHelpers.GetFakeAsyncDbSet(allPlatforms.AsQueryable()); dbStub. Setup(db => db.Platforms). Returns(platformDbSetStub.Object); PlatformsController controller = new PlatformsController(dbStub.Object); var result = controller.Index(selectedPlatforms); Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<PlatformViewModel>()); var model = (PlatformViewModel) result.Model; Assert.That(model.Selected, Is.SameAs(selectedPlatforms)); Assert.That(model.AllPlatforms.Count(), Is.EqualTo(allPlatforms.Count)); Assert.That(model.AllPlatforms, Has.Member(allPlatforms.First()).And.Member(allPlatforms.Last())); }
public void Should_activate_upstream_dependencies_first() { var order = new List<Feature>(); var dependingFeature = new NamespaceB.MyFeature { OnActivation = f => order.Add(f) }; var feature = new NamespaceA.MyFeature { OnActivation = f => order.Add(f) }; var settings = new SettingsHolder(); var featureSettings = new FeatureActivator(settings); featureSettings.Add(dependingFeature); featureSettings.Add(feature); settings.EnableFeatureByDefault<NamespaceA.MyFeature>(); featureSettings.SetupFeatures(null, null); Assert.True(dependingFeature.IsActive); Assert.IsInstanceOf<NamespaceA.MyFeature>(order.First(), "Upstream dependencies should be activated first"); }
public async Task Can_report_progress_when_downloading_async() { var hold = AsyncServiceClient.BufferSize; AsyncServiceClient.BufferSize = 100; try { var asyncClient = new JsonServiceClient(ListeningOn); var progress = new List<string>(); //Note: total = -1 when 'Transfer-Encoding: chunked' //Available in ASP.NET or in HttpListener when downloading responses with known lengths: //E.g: Strings, Files, etc. asyncClient.OnDownloadProgress = (done, total) => progress.Add("{0}/{1} bytes downloaded".Fmt(done, total)); var response = await asyncClient.GetAsync(new TestProgress()); progress.Each(x => x.Print()); Assert.That(response.Length, Is.GreaterThan(0)); Assert.That(progress.Count, Is.GreaterThan(0)); Assert.That(progress.First(), Is.EqualTo("100/1160 bytes downloaded")); Assert.That(progress.Last(), Is.EqualTo("1160/1160 bytes downloaded")); } finally { AsyncServiceClient.BufferSize = hold; } }
public void Index_WhenCalls_SetsUpViewModelWithAllContentDescriptorsAndSelectedList() { List<ESRBContentDescriptor> selectedContentDescriptors = new List<ESRBContentDescriptor>(); List<ESRBContentDescriptor> allContentDescriptors = new List<ESRBContentDescriptor> { new ESRBContentDescriptor(), new ESRBContentDescriptor() }; Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<ESRBContentDescriptor>> contentDescriptorsDbSetStub = TestHelpers.GetFakeAsyncDbSet(allContentDescriptors.AsQueryable()); dbStub. Setup(db => db.ESRBContentDescriptors). Returns(contentDescriptorsDbSetStub.Object); ESRBDescriptionController controller = new ESRBDescriptionController(dbStub.Object); var result = controller.Index(selectedContentDescriptors); Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<ESRBDescriptionViewModel>()); var model = (ESRBDescriptionViewModel)result.Model; Assert.That(model.Selected, Is.SameAs(selectedContentDescriptors)); Assert.That(model.All.Count(), Is.EqualTo(allContentDescriptors.Count)); Assert.That(model.All, Has.Member(allContentDescriptors.First()).And.Member(allContentDescriptors.Last())); }
public void BlackScholesPerformance() { double k = 90; var volatility = 0.2; var t = 5; var s = new List<NArray>(); int batchCount = 1000; int vectorLength = 5000; using (var stream = new RandomNumberStream(StorageLocation.Host, RandomNumberGeneratorType.MRG32K3A)) { var normal = new Normal(stream, 0, 1); for (int i = 0; i < batchCount; ++i) { s.Add(100 * NMath.Exp(NArray.CreateRandom(vectorLength, normal) * 0.2)); } } var result = NArray.CreateLike(s.First()); double elapsedTime = TestHelpers.TimeitSeconds(() => { for (int i = 0; i < batchCount; ++i) { NArray.Evaluate(() => { return Finance.BlackScholes(CallPut.Call, s[i], k, volatility, t); }, new List<NArray>(), Aggregator.ElementwiseAdd, new List<NArray> { result }); } }); Console.WriteLine(string.Format("Time per option price (single core): {0} ns", elapsedTime * 1e9 / (batchCount * vectorLength))); Console.WriteLine(string.Format("Valuations per second (single core): {0:F0} million", batchCount * vectorLength / (elapsedTime * 1e6))); }
public void BasicTest() { string goodInstance = "goodInstance"; var statePersister = new Mock<IStatePersister>(); // Creating fake data for the statePersister... var configurationsPersisted = new List<Configuration>() { GetConfig(1), GetConfig(2), GetConfig(3) }; Configuration firstGoodConfiguration = GetConfig(1); Configuration secondGoodConfiguration = GetConfig(6); firstGoodConfiguration.Instance = goodInstance; secondGoodConfiguration.Instance = goodInstance; configurationsPersisted.Add(firstGoodConfiguration); configurationsPersisted.Add(secondGoodConfiguration); statePersister.Setup(o => o.Read()).Returns(configurationsPersisted); //Creating a fake requestmanager. var subscriptionsRequest = new Mock<IRequestManager<ConfigurationSubscription, ConfigurationSubscriptionAnswer>>(); var updateRequest = new Mock<IRequestManager<ConfigurationUpdate, ConfigurationUpdateAnswer>>(); var allAnswerSent = new List<AnwserMessage<ConfigurationSubscriptionAnswer>>(); subscriptionsRequest.Setup(o => o.Send(It.IsAny<AnwserMessage<ConfigurationSubscriptionAnswer>>())). Callback<AnwserMessage<ConfigurationSubscriptionAnswer>>(allAnswerSent.Add); var toTest = new ConfigurationRequestHandler(subscriptionsRequest.Object, updateRequest.Object, statePersister.Object); //Sending a request to the manager var requestId = 1021; var request = GetRequestMessage(requestId, goodInstance); subscriptionsRequest.Raise(mock => mock.OnRequest += null, null, request); //We check that we received what we should, one message with two elements Assert.AreEqual(1, allAnswerSent.Count); Assert.AreEqual(requestId, allAnswerSent.First().id); var sentConfigurations = allAnswerSent.First().answer.result; Assert.AreEqual(2, sentConfigurations.Count); Assert.AreEqual(firstGoodConfiguration, sentConfigurations.First()); Assert.AreEqual(secondGoodConfiguration, sentConfigurations.Last()); //test wildcard : var requestAll = GetRequestMessage(requestId+1, ConfigurationRequestHandler.ConfigurationInstanceWildcard); subscriptionsRequest.Raise(mock => mock.OnRequest += null, null, requestAll); Assert.AreEqual(configurationsPersisted.Count, allAnswerSent.Last().answer.result.Count); }
public void When_Removing_Links() { var links = new List<ResourceLink> { new ResourceLink(), new ResourceLink() }; var subject = new ContractStub(links); subject.RemoveLink(links.First()); subject.RemoveLinkAt(0); Assert.That(subject.Links, Is.Empty); }
public void can_shift() { var ints = new List<int> {1, 2, 3, 4}; var x = ints.Shift(); x.ShouldEqual(1); ints.Count().ShouldEqual(3); ints.First().ShouldEqual(2); }
public void Add_Should_Save_And_Assigned_New_Ids_To_Multiple(IRepository<Contact, string> repository) { IList<Contact> contacts = new List<Contact> { new Contact { Name = "Contact 1"}, new Contact { Name = "Contact 2"}, new Contact { Name = "Contact 3"}, }; repository.Add(contacts); contacts.First().ContactId.ShouldNotBeEmpty(); contacts.Last().ContactId.ShouldNotBeEmpty(); contacts.First().ShouldNotBeSameAs(contacts.Last().ContactId); var added = repository.GetAll(); added.Count().ShouldEqual(3); }
public void Tokens2SimpleInvert_Test() { string String = "{1} {0}"; List<int> List = new List<int> { 1, 0 }; FixStringAndList(ref String, ref List); Assert.AreEqual("{0} {1}", String); Assert.AreEqual(0, List.First()); Assert.AreEqual(1, List.Skip(1).First()); }
public void Tokens2CorrectDoNothing_Test() { string String = "{0} {1}"; List<int> List = new List<int> { 0, 1 }; FixStringAndList(ref String, ref List); Assert.AreEqual("{0} {1}", String); Assert.AreEqual(0, List.First()); Assert.AreEqual(1, List.Skip(1).First()); }
public void SetUp() { scheduler = new VirtualScheduler(); leftBrainPeerObservable = new Subject<IEnumerable<Peer>>(); rightBrainPeerObservable = new Subject<IEnumerable<Peer>>(); leftBrain = TestNode.CreateCluster(clusterSize: 5, peerObservable: leftBrainPeerObservable, scheduler: scheduler); rightBrain = TestNode.CreateCluster(clusterSize: 5, peerObservable: rightBrainPeerObservable, scheduler: scheduler); leftBrainLeader = leftBrain.First(); leftBrainLeader.StartElection().Wait(); rightBrain.First().StartElection().Wait(); rightBrain.First().StepDown(2, "none"); scheduler.AdvanceBy(TestNode.ElectionTimeout); rightBrain.First().StartElection().Wait(); rightBrain.ForEach(n => n.Term.Should().Be(3)); }
public void CheckAndReadValidFile() { string filePath = AppDomain.CurrentDomain.BaseDirectory + @"/TestFiles/csd.txt"; var exepected = new List<string> { "devineni,srikanth,male,black,01/02/1985" }; var actual = FileReader.ReadFile(filePath); Assert.AreEqual(exepected.Count, actual.Count); Assert.AreEqual(exepected.First(), actual.First()); }
public void UpdateAlbums_Doesnt_Copy_Album_Art_If_It_Already_Exists() { var lastFmClient = MockRepository.GenerateMock<ILastfmService>(); var config = MockRepository.GenerateMock<IConfig>(); var user = "******"; var existingUri = "http://existingUri.com"; var lastFmLibraryAlbums = new List<LastfmLibraryAlbum> { new LastfmLibraryAlbum { Artist = "John Coltrane", Name = "Giant Steps", ArtworkLocation = @"http://uri.here.com/asdf" } }; var albums = new List<Album> { new Album { Artist = "John Coltrane", Name = "Giant Steps", PlayCount = 12, ArtworkLocation = existingUri } }; var lastFmAlbumInfo = new LastFmAlbumInfo(lastFmClient); config.Expect(c => c.LastFmUser).Return(user); lastFmClient.Expect(l => l.FindAllAlbums(user)).Return(lastFmLibraryAlbums); using (new ConfigScope(config)) { lastFmAlbumInfo.UpdateAlbums(albums); } Assert.AreNotEqual(lastFmLibraryAlbums.First().ArtworkLocation, albums.First().ArtworkLocation); Assert.AreEqual(existingUri, albums.First().ArtworkLocation); }
public void Should_be_able_to_build_the_IsUrl_rule() { var ruleType = typeof(IsUrl<>); var list = new List<object>(); _validationRuleBuilder.Build<TestViewModel>(_discoveredType, ruleType, _propertyInfoOfStringProperty, new List<PropertyInfo>(), list.Add); list.Count.ShouldEqual(1); list.First().GetType().ShouldEqual(typeof(IsUrl<TestViewModel>)); }
public void Tokens3singleDup_Test() { string String = "{2} {1} {0}"; List<int> List = new List<int> { 2, 1, 0 }; FixStringAndList(ref String, ref List); Assert.AreEqual("{0} {1} {2}", String); Assert.AreEqual(0, List.First()); Assert.AreEqual(1, List.Skip(1).First()); Assert.AreEqual(2, List.Skip(2).First()); }
public void OnePathReturnsOne() { var traversal = new List<string>(); var startLeg = "AB"; _traverser.Invoke(startLeg, new Dictionary<string, int>{{startLeg, 3}}, ref traversal); Assert.That(traversal.Count, Is.EqualTo(1)); Assert.That(traversal.First(), Is.EqualTo(startLeg)); }
private List<int> FindSequence(List<int> ordered) { var top = ordered.First(); var next = top; var sequence = new List<int>(); do { sequence.Add(top); ordered.Remove(top); if (!ordered.Any()) break; next = ordered.First(); if (top == next - 1) top = next; } while (top == next); return sequence; }