本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Skip方法的典型用法代码示例。如果您正苦于以下问题:C# List.Skip方法的具体用法?C# List.Skip怎么用?C# List.Skip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Skip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateSum
public List<int> CalculateSum(string ItemName, int BatchAmount)
{
//拿出資料集合
List<Product> Products = _ProductDao.GetAll();
//決定要加總那一個項目
List<int> Items = new List<int>();
switch (ItemName)
{
case "Id":
Items = Products.Select(p => p.Id).ToList();
break;
case "Cost":
Items = Products.Select(p => p.Cost).ToList();
break;
case "Revenue":
Items = Products.Select(p => p.Revenue).ToList();
break;
case "SellPrice":
Items = Products.Select(p => p.SellPrice).ToList();
break;
}
//計算集合
List<int> Result = new List<int>();
for (int i = 0; i < Items.Count / BatchAmount + (Items.Count % BatchAmount == 0 ? 0 : 1); i++)
{
Result.Add(Items.Skip(i * BatchAmount).Take(BatchAmount).Sum());
}
return Result;
}
示例2: EtwFileSourceTest
public void EtwFileSourceTest()
{
var observable = EtwObservable.FromFiles(FileName);
var source = new TimeSource<EtwNativeEvent>(observable, e => e.TimeStamp);
var parsed = from p in source
where p.Id == 2
select p.TimeStamp;
var buf = parsed.Take(13).Buffer(TimeSpan.FromSeconds(1), source.Scheduler);
var list = new List<IList<DateTimeOffset>>();
ManualResetEvent completed = new ManualResetEvent(false);
buf.Subscribe(
t => list.Add(t),
()=>completed.Set());
source.Connect();
completed.WaitOne();
Assert.AreEqual(2, list.Count());
Assert.AreEqual(7, list.First().Count);
Assert.AreEqual(6, list.Skip(1).First().Count);
}
示例3: TestMaxItemCount
public async Task TestMaxItemCount()
{
var nextItem = 0;
var pool = new PipelinedPool<int>(() => TaskPort.FromResult(++nextItem), null, new PipelinedPoolOptions
{
MaxRequestsPerItem = 10,
TargetItemCount = 2,
});
var items = new List<IPooledItem<int>>();
for (int i = 0; i < 20; ++i)
{
var task = pool.Borrow();
Assert.AreEqual(true, task.IsCompleted);
var item = await task;
items.Add(item);
}
Assert.AreEqual(20, items.Count);
Assert.AreEqual(10, items.Count(v => v.Item == 1));
Assert.AreEqual(10, items.Count(v => v.Item == 2));
var waiter = pool.Borrow();
Assert.AreEqual(false, waiter.IsCompleted);
items.First().Dispose();
Assert.AreEqual(true, waiter.IsCompleted);
foreach (var item in items.Skip(1))
{
item.Dispose();
}
waiter.Result.Dispose();
}
示例4: ShortSpam
public void ShortSpam()
{
InitializeDatastore.Run();
var testList = new List<Tuple<string, bool>> {
new Tuple<string, bool> ("a somewhat short message1", false),
new Tuple<string, bool> ("Waterboyy I'm not, leblanc is just annoying to play against", false),
new Tuple<string, bool> ("i see you're a master theory crafter", false),
new Tuple<string, bool> ("a somewhat short message2", false),
new Tuple<string, bool> ("a somewhat short message3", true),
};
var total = new List<Message>();
foreach (var tuple in testList) {
total.Add(new PublicMessage(tuple.Item1));
var op = total.First();
var context = total.Skip(1).ToList();
var testCase = new Banner(op, null, context).SelfSpam();
if (tuple.Item2) {
Assert.IsNotNull(testCase);
} else {
Assert.IsNull(testCase);
}
}
}
示例5: CanReadTest
public void CanReadTest()
{
ConcatenatedStream cStream = new ConcatenatedStream(streamSampleOne, streamSampleTwo, streamSampleThree);
int totalLength = sampleStreamSize * 2;
List<byte> output = new List<byte>();
while (cStream.CanRead)
{
output.Add((byte)cStream.ReadByte());
}
Assert.IsTrue(
output.Take(sampleStreamSize).SequenceEqual(streamSampleOne.ToArray()),
"First array does not match");
Assert.IsTrue(
output.Skip(sampleStreamSize).Take(sampleStreamSize).SequenceEqual(streamSampleTwo.ToArray()),
"Second array does not match");
Assert.IsTrue(
output.Skip(sampleStreamSize * 2).Take(sampleStreamSize).SequenceEqual(streamSampleThree.ToArray()),
"Third array does not match");
}
示例6: VerifyTerminalVelocityReached
public void VerifyTerminalVelocityReached()
{
List<double> velocities = new List<double> { 0 };
const int MAX_ITER = 10000;
while (velocities.Count < MAX_ITER)
velocities.Add(VelocitySimulation.CalculateNewVelocity(velocities.Last()));
Assert.IsTrue(Math.Abs(velocities.Skip(MAX_ITER - 100).Take(100).Average() - velocities.Last()) < 0.001);
}
示例7: GetMethodCode
private List<string> GetMethodCode(List<string> codeLines, string functionName)
{
const int lineNumbersToRead = 20;
// find line number where the method starts, check if, the method name does not occur in comment line
int findNeighbourLineNumber = codeLines.FindIndex(line => line.Contains(functionName) && !line.Contains("//"));
// just take the 20 following lines of the beginning line of the method
// TODO: could make it more accurate and find end of method
return codeLines.Skip(findNeighbourLineNumber - 1).Take(lineNumbersToRead).ToList();
}
示例8: TestXmlSerializer_IEnumerable
public void TestXmlSerializer_IEnumerable()
{
IEnumerable<int> list = new List<int>() { 1, 2, 3, 4 };
var xml = XmlSerializer.Serialize(list);
var roundTrip = (XmlSerializer.Deserialize(xml) as IEnumerable).Cast<int>();
Assert.IsNotNull(roundTrip);
Assert.AreEqual<int>(list.Count(), roundTrip.Count());
int count = list.Count();
for (int i = 0; i < count; i++)
{
Assert.AreEqual<int>(list.Skip(i).First(), roundTrip.Skip(i).First());
}
}
示例9: ShouldListAllArtists
public void ShouldListAllArtists()
{
// Arrange
List<string> artists = new List<string>
{
"1", "2", "3", "4"
};
Dictionary<string, IEnumerable<string>> genreArtistMap = new Dictionary<string, IEnumerable<string>>
{
{ "Pop", artists.Take(2) },
{ "Rock", artists.Skip(2).Take(2) }
};
IArtistsRepository repos = MockArtistsRepository.CreateMockRepository(genreArtistMap);
ArtistsController controller = new ArtistsController(repos);
// Act
ViewResult result = controller.AllArtists(1);
// Assert
Assert.AreEqual("", result.ViewName);
}
示例10: TestSendMessageIteration
public void TestSendMessageIteration()
{
var array = new List<int>{1,2,3,4,5,6,7,8,9};
var max = 2;
var iterations = array.Count / max;
for (int i = 0; i < iterations + 1; i++)
{
array.Skip(i * max).Take(max).ToList<int>().ForEach(it =>{
Console.WriteLine(it);
});
}
}
示例11: TestSaveAndGet_IEnumerable
public void TestSaveAndGet_IEnumerable()
{
IEnumerable<int> testList = new List<int>() { 1, 2, 3, 4 };
testFile.SaveItem(key, testList);
var roundtrip = testFile.GetItem<IEnumerable>(key).Cast<int>();
Assert.IsNotNull(testList);
Assert.IsNotNull(roundtrip);
Assert.AreEqual<int>(testList.Count(), roundtrip.Count());
int count = testList.Count();
for (int i = 0; i < count; i++)
{
Assert.AreEqual<int>(testList.Skip(i).First(), roundtrip.Skip(i).First());
}
}
示例12: TestAllReduceInternal
internal async Task TestAllReduceInternal()
{
var data = Enumerable.Range(1, 1000).Select(_ => Generator.GenerateShared(10)).ToList();
var stringSerializerCompiler = (VowpalWabbitSingleExampleSerializerCompiler<CbAdfShared>)
VowpalWabbitSerializerFactory.CreateSerializer<CbAdfShared>(new VowpalWabbitSettings { EnableStringExampleGeneration = true });
var stringSerializerAdfCompiler = (VowpalWabbitSingleExampleSerializerCompiler<CbAdfAction>)
VowpalWabbitSerializerFactory.CreateSerializer<CbAdfAction>(new VowpalWabbitSettings { EnableStringExampleGeneration = true });
var stringData = new List<List<string>>();
VowpalWabbitPerformanceStatistics statsExpected;
using (var spanningTree = new SpanningTreeClr())
{
spanningTree.Start();
using (var vw1 = new VowpalWabbit(new VowpalWabbitSettings(@"--total 2 --node 1 --unique_id 0 --span_server localhost --cb_adf --rank_all --interact xy") { EnableStringExampleGeneration = true }))
using (var vw2 = new VowpalWabbit(new VowpalWabbitSettings(@"--total 2 --node 0 --unique_id 0 --span_server localhost --cb_adf --rank_all --interact xy") { EnableStringExampleGeneration = true } ))
{
var stringSerializer = stringSerializerCompiler.Func(vw1);
var stringSerializerAdf = stringSerializerAdfCompiler.Func(vw1);
// serialize
foreach (var d in data)
{
var block = new List<string>();
using (var context = new VowpalWabbitMarshalContext(vw1))
{
stringSerializer(context, d.Item1, SharedLabel.Instance);
block.Add(context.ToString());
}
block.AddRange(d.Item2.Select((a, i) =>
{
using (var context = new VowpalWabbitMarshalContext(vw1))
{
stringSerializerAdf(context, a, i == d.Item3.Action ? d.Item3 : null);
return context.ToString();
}
}));
stringData.Add(block);
}
await Task.WhenAll(
Task.Factory.StartNew(() => Ingest(vw1, stringData.Take(500))),
Task.Factory.StartNew(() => Ingest(vw2, stringData.Skip(500))));
vw1.SaveModel("expected.1.model");
vw2.SaveModel("expected.2.model");
statsExpected = vw1.PerformanceStatistics;
}
}
// skip header
var expected1Model = File.ReadAllBytes("expected.1.model").Skip(0x15).ToList();
var expected2Model = File.ReadAllBytes("expected.2.model").Skip(0x15).ToList();
var settings = new VowpalWabbitSettings("--cb_adf --rank_all --interact xy")
{
ParallelOptions = new ParallelOptions
{
MaxDegreeOfParallelism = 2
},
ExampleCountPerRun = 2000,
ExampleDistribution = VowpalWabbitExampleDistribution.RoundRobin
};
using (var vw = new VowpalWabbitThreadedLearning(settings))
{
await Task.WhenAll(
Task.Factory.StartNew(() => Ingest(vw, stringData.Take(500))),
Task.Factory.StartNew(() => Ingest(vw, stringData.Skip(500))));
// important to enqueue the request before Complete() is called
var statsTask = vw.PerformanceStatistics;
var modelSave = vw.SaveModel("actual.model");
await vw.Complete();
var statsActual = await statsTask;
VWTestHelper.AssertEqual(statsExpected, statsActual);
await modelSave;
// skip header
var actualModel = File.ReadAllBytes("actual.model").Skip(0x15).ToList();
CollectionAssert.AreEqual(expected1Model, actualModel);
CollectionAssert.AreEqual(expected2Model, actualModel);
}
using (var vw = new VowpalWabbitThreadedLearning(settings))
{
var vwManaged = vw.Create<CbAdfShared, CbAdfAction>();
await Task.WhenAll(
Task.Factory.StartNew(() => Ingest(vwManaged, data.Take(500))),
//.........这里部分代码省略.........
示例13: TestRemove
public void TestRemove()
{
List<int> list = new List<int> { 1, 2, 3 };
Window<int> window = new Window<int>(list, 1);
ReadOnlyWindow<int> readOnlyWindow = new ReadOnlyWindow<int>(list, 1);
int[] l = list.Skip(1).ToArray();
CollectionAssert.AreEqual(l, window);
CollectionAssert.AreEqual(l, readOnlyWindow);
Assert.AreEqual(2, window.Count);
Assert.AreEqual(3, window.Length);
Assert.AreEqual(1, window.Offset);
Assert.AreEqual(2, readOnlyWindow.Count);
Assert.AreEqual(3, readOnlyWindow.Length);
Assert.AreEqual(1, readOnlyWindow.Offset);
// Remove through window
window.Remove(2);
l = list.Skip(1).ToArray();
CollectionAssert.AreEqual(l, window);
CollectionAssert.AreEqual(l, readOnlyWindow);
Assert.AreEqual(1, window.Count);
Assert.AreEqual(2, window.Length);
Assert.AreEqual(1, window.Offset);
Assert.AreEqual(1, readOnlyWindow.Count);
Assert.AreEqual(2, readOnlyWindow.Length);
Assert.AreEqual(1, readOnlyWindow.Offset);
// Remove from underlying list (note that the offset doesn't change, the window is effectively moved).
list.Remove(1);
l = list.Skip(1).ToArray();
CollectionAssert.AreEqual(l, window);
CollectionAssert.AreEqual(l, readOnlyWindow);
Assert.AreEqual(0, window.Count);
Assert.AreEqual(1, window.Length);
Assert.AreEqual(1, window.Offset);
Assert.AreEqual(0, readOnlyWindow.Count);
Assert.AreEqual(1, readOnlyWindow.Length);
Assert.AreEqual(1, readOnlyWindow.Offset);
// Remove all items!
list.Clear();
Assert.AreEqual(0, window.Count);
Assert.AreEqual(0, window.Length);
Assert.AreEqual(1, window.Offset); // Note the offset is beyond the end of the underlying data
Assert.AreEqual(0, readOnlyWindow.Count);
Assert.AreEqual(0, readOnlyWindow.Length);
Assert.AreEqual(1, readOnlyWindow.Offset); // Note the offset is beyond the end of the underlying data
}
示例14: TestListSkipComplex
public void TestListSkipComplex()
{
var l = new List<int> { -1, -2, -3, -4, -5 }.ToLiveList();
var t = l.Skip(3.ToLiveConst()).ToIndependent();
t.Check1(
() => Enumerable.Range(0, 5).ForEach(i => l.PublishInner.Insert(i, 100 + i)),
state =>
{
var s = state.Skip(1).First();
Assert.IsTrue(s.Status == StateStatus.Connected);
Assert.IsTrue(s.Delta.HasChange());
Assert.IsTrue(s.Inner.SequenceEqual(new[] { 103, 104, -1, -2, -3, -4, -5 }));
Assert.IsTrue(s.Delta.IndexDeltas.SequenceEqual(new[]
{
new IndexNode<int>
{
Index = 0,
DenseIndex = 0,
Data = new ListIndexDelta<int>
{
InsertItems = new[] { 103, 104, -1, -2, -3 },
},
},
}, new IndexNodeComparer<int>()));
});
l = new List<int> { -1, -2, -3, -4, -5 }.ToLiveList();
t = l.Skip(3.ToLiveConst()).ToIndependent();
t.Check1(
() =>
{
l.PublishInner.Insert(1, 100);
l.PublishInner.Insert(3, 200);
l.PublishInner.Insert(5, 300);
l.PublishInner.Insert(7, 400);
},
state =>
{
var s = state.Skip(1).First();
Assert.IsTrue(s.Status == StateStatus.Connected);
Assert.IsTrue(s.Delta.HasChange());
Assert.IsTrue(s.Inner.SequenceEqual(new[] { 200, -3, 300, -4, 400, -5 }));
Assert.IsTrue(s.Delta.IndexDeltas.SequenceEqual(new[]
{
new IndexNode<int>
{
Index = 0,
DenseIndex = 0,
Data = new ListIndexDelta<int>
{
InsertItems = new[] { 200, -3, 300 },
},
},
new IndexNode<int>
{
Index = 4,
DenseIndex = 1,
Data = new ListIndexDelta<int>
{
InsertItems = new[] { 400 },
},
},
}, new IndexNodeComparer<int>()));
});
l = new List<int> { -1, -2, -3, -4, -5 }.ToLiveList();
t = l.Skip(3.ToLiveConst()).ToIndependent();
t.Check1(
() =>
{
l.PublishInner.Insert(1, 100);
l.PublishInner.Insert(3, 200);
l.PublishInner.RemoveAt(4);
l.PublishInner.Insert(5, 300);
l.PublishInner.Insert(7, 400);
},
state =>
{
var s = state.Skip(1).First();
Assert.IsTrue(s.Status == StateStatus.Connected);
Assert.IsTrue(s.Delta.HasChange());
Assert.IsTrue(s.Inner.SequenceEqual(new[] { 200, -4, 300, -5, 400 }));
Assert.IsTrue(s.Delta.IndexDeltas.SequenceEqual(new[]
{
new IndexNode<int>
{
Index = 0,
DenseIndex = 0,
Data = new ListIndexDelta<int>
{
InsertItems = new[] { 200 },
},
},
new IndexNode<int>
{
Index = 2,
DenseIndex = 1,
//.........这里部分代码省略.........
示例15: GetPaginationTest
public void GetPaginationTest()
{
for (int i = 0; i < 20; i++)
{
List<int> items = new List<int>();
for (int j = 0; j < i; j++)
{
items.Add(j);
}
for (int resultsPerPage = 1; resultsPerPage < 21; resultsPerPage++)
{
var pageNumber = 0;
var page = items.GetPagination(resultsPerPage, ref pageNumber);
Assert.IsTrue(page.Count <= resultsPerPage);
Assert.IsTrue(page.IsEqualOrdered(items.Take(resultsPerPage).ToList()));
pageNumber = 99; // last page
page = items.GetPagination(resultsPerPage, ref pageNumber);
Assert.AreNotEqual(pageNumber, 99, i + " / " + resultsPerPage);
Assert.IsTrue(page.Count <= resultsPerPage);
if (items.Count > 0)
{
Assert.IsTrue(page.Count > 0, i + " / " + resultsPerPage);
Assert.IsTrue(page.IsEqualOrdered(items.Skip(items.Count - page.Count).Take(page.Count).ToList()));
}
}
}
}