本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Take方法的典型用法代码示例。如果您正苦于以下问题:C# List.Take方法的具体用法?C# List.Take怎么用?C# List.Take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Take方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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");
}
示例2: PlayExecutesSamePlayerOrderInEachRound
public void PlayExecutesSamePlayerOrderInEachRound()
{
var players = new[]
{
"Horse",
"Car",
"Hat"
};
var mockTurn = new Mock<ITurn>();
var game = new Game(players, mockTurn.Object, new GuidShuffler<String>());
var controller = new GameController(game);
var turnsTaken = new List<String>();
mockTurn.Setup(m => m.Take(It.IsAny<String>())).Callback((String p) => turnsTaken.Add(p));
controller.Play();
var lastRoundTurns = Enumerable.Empty<String>();
while (turnsTaken.Any())
{
var roundTurns = turnsTaken.Take(players.Count());
if (lastRoundTurns.Any())
{
for (var i = 0; i < lastRoundTurns.Count(); i++)
Assert.AreEqual(roundTurns.ElementAt(i), lastRoundTurns.ElementAt(i));
}
lastRoundTurns = roundTurns;
turnsTaken.RemoveRange(0, players.Count());
}
}
示例3: SupportVectorMachinePerformanceTest
public void SupportVectorMachinePerformanceTest() {
ex = null;
var cv = new CrossValidation();
cv.Algorithm = new SupportVectorRegression();
var rand = new HeuristicLab.Random.MersenneTwister();
double[,] data = GenerateData(1000, rand);
List<string> variables = new List<string>() { "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "y" };
Dataset ds = new Dataset(variables, data);
cv.Problem.ProblemDataParameter.ActualValue = new RegressionProblemData(ds, variables.Take(10), variables.Last());
cv.Folds.Value = 5;
cv.SamplesStart.Value = 0;
cv.SamplesEnd.Value = 999;
cv.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(cv_ExceptionOccurred);
cv.Stopped += new EventHandler(cv_Stopped);
cv.Prepare();
cv.Start();
trigger.WaitOne();
if (ex != null) throw ex;
TestContext.WriteLine("Runtime: {0}", cv.ExecutionTime.ToString());
}
示例4: FillsInWithSongsWhenNotEnoughSpecified
public void FillsInWithSongsWhenNotEnoughSpecified()
{
var all = new List<Song>(GetRandomSongs(75000));
var songs = new PlaylistGenerator(new List<ICriteriaCounter<Song>>())
.GeneratePlayList(all, 100, all.Take(50));
Assert.AreEqual(songs.Count(), 100);
}
示例5: Init
public void Init()
{
var columns = new List<SysColumn>()
{
new SysColumn()
{
Name = "FirstColumn",
ColumnID = 1,
Identity = true,
Nullable = false,
SystemType = Core.Enumerations.SysType.Int
},
new SysColumn()
{
Name = "SecondColumn",
ColumnID = 1,
Identity = false,
Nullable = true,
SystemType = Core.Enumerations.SysType.VarChar,
MaxLength = 100
},
new SysColumn()
{
Name = "ThirdColumn",
ColumnID = 1,
Identity = false,
Nullable = false,
SystemType = Core.Enumerations.SysType.NVarChar,
MaxLength = 100
}
};
_sourceTable = new SysTable() { Name = "SourceTable" };
_sourceTable.Columns.AddRange(columns);
_targetTable = new SysTable() { Name = "TargetTable" };
_targetTable.Columns.AddRange(columns.Take(2));
}
示例6: 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);
}
示例7: Generate_LongRunning2
public void Generate_LongRunning2()
{
var start = default(ManualResetEvent);
var end = default(ManualResetEvent);
var s = new TestLongRunningScheduler(x => start = x, x => end = x);
var xs = Observable.Generate(0, _ => true, x => x + 1, x => x, s);
var lst = new List<int>();
var d = xs.Subscribe(x => { lst.Add(x); });
start.WaitOne();
while (lst.Count < 100)
;
d.Dispose();
end.WaitOne();
Assert.IsTrue(lst.Take(100).SequenceEqual(Enumerable.Range(0, 100)));
}
示例8: CreateAsync_IDisposable_Token
public void CreateAsync_IDisposable_Token()
{
var stopped = new ManualResetEvent(false);
var s = Disposable.Create(() => stopped.Set());
var e = new ManualResetEvent(false);
var xs = Observable.Create<int>((observer, ct) =>
{
return Task.Factory.StartNew(() =>
{
var i = 0;
while (!ct.IsCancellationRequested)
{
if (i++ == 10)
e.Set();
observer.OnNext(42);
}
return s;
});
});
var lst = new List<int>();
var d = xs.Subscribe(lst.Add);
e.WaitOne();
d.Dispose();
stopped.WaitOne();
Assert.IsTrue(lst.Take(10).SequenceEqual(Enumerable.Repeat(42, 10)));
}
示例9: TestSkipAndTakeWorksLikePs1
public void TestSkipAndTakeWorksLikePs1()
{
var myList = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
var lastIndex = myList.Count - 1;
var myI = 7;
var left = myList.Take(myI).ToList();
var printMySkipTakeList = string.Join(",", left);
System.Diagnostics.Debug.WriteLine(printMySkipTakeList);
var right = myList.Skip(myI+1).Take(lastIndex).ToList();
left.AddRange(right);
printMySkipTakeList = string.Join(",", left);
System.Diagnostics.Debug.WriteLine(printMySkipTakeList);
}
示例10: TestListTake
public void TestListTake()
{
var l = new List<int> { 1, 2, 3, 4, 5 }.ToLiveList();
var t = l.Take(3.ToLiveConst()).ToIndependent();
t.States().Take(1).Check(
() => { },
state =>
{
var s = state.Single();
Assert.IsTrue(s.Status == StateStatus.Connecting);
Assert.IsTrue(s.Inner.SequenceEqual(new[] { 1, 2, 3 }));
Assert.IsTrue(s.Delta == null);
});
t.States().Skip(1).Take(1).Check(
() => l.PublishInner.Insert(0, 0),
state =>
{
var s = state.Single();
Assert.IsTrue(s.Status == StateStatus.Connected);
Assert.IsTrue(s.Inner.SequenceEqual(new[] { 0, 1, 2 }));
Assert.IsTrue(s.Delta.IndexDeltas.SequenceEqual(new[]
{
new IndexNode<int>
{
Index = 0,
DenseIndex = 0,
Data = new ListIndexDelta<int>
{
InsertItems = new[] { 0 },
},
},
new IndexNode<int>
{
Index = 3,
DenseIndex = 1,
Data = new ListIndexDelta<int>
{
DeleteItems = new[] { 3 },
},
},
}, new IndexNodeComparer<int>()));
});
t.States().Skip(1).Take(1).Check(
() => l.PublishInner.RemoveAt(0),
state =>
{
var s = state.Single();
Assert.IsTrue(s.Status == StateStatus.Connected);
Assert.IsTrue(s.Inner.SequenceEqual(new[] { 1, 2, 3 }));
Assert.IsTrue(s.Delta.IndexDeltas.SequenceEqual(new[]
{
new IndexNode<int>
{
Index = 0,
DenseIndex = 0,
Data = new ListIndexDelta<int>
{
DeleteItems = new[] { 0 },
},
},
new IndexNode<int>
{
Index = 2,
DenseIndex = 1,
Data = new ListIndexDelta<int>
{
InsertItems = new[] { 3 },
},
},
}, new IndexNodeComparer<int>()));
});
t.States().Skip(1).Take(1).Check(
() => l.PublishInner[1] = 99,
state =>
{
var s = state.Single();
Assert.IsTrue(s.Status == StateStatus.Connected);
Assert.IsTrue(s.Delta.HasChange());
Assert.IsTrue(s.Inner.SequenceEqual(new[] { 1, 99, 3 }));
Assert.IsTrue(s.Delta.IndexDeltas.SequenceEqual(new[]
{
new IndexNode<int>
{
Index = 1,
DenseIndex = 0,
Data = new ListIndexDelta<int>
{
InsertItems = new[] { 99 },
DeleteItems = new[] { 2 },
},
},
}, new IndexNodeComparer<int>()));
});
t.States().Skip(1).Take(1).Check(
() => l.PublishInner[2] = 88,
state =>
{
var s = state.Single();
//.........这里部分代码省略.........
示例11: GetDataByTestTypeIdPageableTest
public void GetDataByTestTypeIdPageableTest()
{
PagedResult<Test> expectedResult;
_repository
.Setup(it => it.GetDataByTestTypeIdPageable(It.IsAny<Int32>(), It.IsAny<String>(), It.IsAny<Int32>(), It.IsAny<Int32>()))
.Returns<Int32, String, Int32, Int32>((testTypeId, sortExpression, page, pageSize) =>
{
var query = _repositoryList.Where(x => x.TestTypeId==testTypeId);
switch (sortExpression)
{
case "Id":
query = new List<Test>(query.OrderBy(q => q.Id));
break;
case "TestTypeId":
query = new List<Test>(query.OrderBy(q => q.TestTypeId));
break;
case "ProjectId":
query = new List<Test>(query.OrderBy(q => q.ProjectId));
break;
case "GroupId":
query = new List<Test>(query.OrderBy(q => q.GroupId));
break;
case "Name":
query = new List<Test>(query.OrderBy(q => q.Name));
break;
case "TestValue":
query = new List<Test>(query.OrderBy(q => q.TestValue));
break;
case "IsActive":
query = new List<Test>(query.OrderBy(q => q.IsActive));
break; }
return query.Take(pageSize).Skip((page-1)*pageSize).ToList();
});
_repository
.Setup(it => it.GetDataByTestTypeIdRowCount(testTypeId))
.Returns(_repositoryList.Count);
var result = _target.GetDataByTestTypeIdPageable(TestTypeIdValue, "Id", 1, 2);
Assert.IsTrue(result.TryGetContentValue(out expectedResult));
Assert.AreEqual(_repositoryList.Where(x => x.TestTypeId==testTypeId).Take(2).ToList().Count, expectedResult.Results.Count);
Assert.AreEqual(_repositoryList.Where(x => x.TestTypeId==testTypeId).OrderBy(q => q.Id).FirstOrDefault().Id, expectedResult.Results.FirstOrDefault().Id);
}
示例12: GetConnectionsForProjectByProjectIdPageableTest
public void GetConnectionsForProjectByProjectIdPageableTest()
{
PagedResult<Connection> expectedResult;
_repository
.Setup(it => it.GetConnectionsForProjectByProjectIdPageable(It.IsAny<Int32>(), It.IsAny<String>(), It.IsAny<Int32>(), It.IsAny<Int32>()))
.Returns<Int32, String, Int32, Int32>((projectId, sortExpression, page, pageSize) =>
{
var query = _repositoryList;
switch (sortExpression)
{
case "ConnectionId":
query = new List<Connection>(query.OrderBy(q => q.ConnectionId));
break;
case "Name":
query = new List<Connection>(query.OrderBy(q => q.Name));
break;
case "ConnectionString":
query = new List<Connection>(query.OrderBy(q => q.ConnectionString));
break;
case "IsActive":
query = new List<Connection>(query.OrderBy(q => q.IsActive));
break; }
return query.Take(pageSize).Skip((page-1)*pageSize).ToList();
});
_repository
.Setup(it => it.GetConnectionsForProjectByProjectIdRowCount(projectId))
.Returns(_repositoryList.Count);
var result = _target.GetConnectionsForProjectByProjectIdPageable(ProjectIdValue, "ConnectionId", 1, PageSizeValue);
Assert.IsTrue(result.TryGetContentValue(out expectedResult));
Assert.AreEqual(_repositoryList.Take(2).ToList().Count, expectedResult.Results.Count);
Assert.AreEqual(_repositoryList.OrderBy(q => q.ConnectionId).FirstOrDefault().ConnectionId, expectedResult.Results.FirstOrDefault().ConnectionId);
}
示例13: TestListTakeSimple
public void TestListTakeSimple()
{
var l = new List<int>().ToLiveList();
l.PublishInner.Connect(Enumerable.Empty<int>());
var t = l.Take(3.ToLiveConst()).ToIndependent();
t.States().Take(1).Check(
() => { },
state =>
{
var s = state.Single();
Assert.IsTrue(s.Status == StateStatus.Connecting);
Assert.IsTrue(s.Inner.SequenceEqual(new int[] { }));
Assert.IsTrue(s.Delta == null);
});
t.States().Skip(1).Take(1).Check(
() => l.PublishInner.Add(0),
state =>
{
var s = state.Single();
Assert.IsTrue(s.Status == StateStatus.Connected);
Assert.IsTrue(s.Inner.SequenceEqual(new[] { 0 }));
Assert.IsTrue(s.Delta.IndexDeltas.SequenceEqual(new[]
{
new IndexNode<int>
{
Index = 0,
DenseIndex = 0,
Data = new ListIndexDelta<int>
{
InsertItems = new[] { 0 },
},
},
}, new IndexNodeComparer<int>()));
});
}
示例14: Search_Multiple_Results_Verify_Result
public void Search_Multiple_Results_Verify_Result()
{
var nonEmptyQuery = "tfs";
var expectedResults = new List<SearchResultItem>()
{
new SearchResultItem("101", "102", "description 113"),
new SearchResultItem("201", "202", "description 213"),
new SearchResultItem("301", "302", "description 313"),
new SearchResultItem("401", "402", "description 413"),
};
var output = new List<LocalViewwwJob>()
{
new LocalViewwwJob
{
RecordId = 101,
Creator = 102,
Created = DateTime.Now,
Session = 103,
StartTime = DateTime.Now,
Duration = 104,
Customer = 105,
Project = 106,
ProjectId = "107-108",
ProjectDescription = "project 109",
JobType = 110,
RateGroup = 111,
RateName = 112,
Description = "description 113",
Enabled = false,
ForceJobsEnabled = false
},
new LocalViewwwJob
{
RecordId = 201,
Creator = 202,
Created = DateTime.Now,
Session = 203,
StartTime = DateTime.Now,
Duration = 204,
Customer = 205,
Project = 206,
ProjectId = "207-208",
ProjectDescription = "project 209",
JobType = 210,
RateGroup = 211,
RateName = 212,
Description = "description 213",
Enabled = false,
ForceJobsEnabled = false
},
new LocalViewwwJob
{
RecordId = 301,
Creator = 302,
Created = DateTime.Now,
Session = 303,
StartTime = DateTime.Now,
Duration = 304,
Customer = 305,
Project = 306,
ProjectId = "307-308",
ProjectDescription = "project 309",
JobType = 310,
RateGroup = 311,
RateName = 312,
Description = "description 313",
Enabled = false,
ForceJobsEnabled = false
},
new LocalViewwwJob
{
RecordId = 401,
Creator = 402,
Created = DateTime.Now,
Session = 403,
StartTime = DateTime.Now,
Duration = 404,
Customer = 405,
Project = 406,
ProjectId = "407-408",
ProjectDescription = "project 409",
JobType = 410,
RateGroup = 411,
RateName = 412,
Description = "description 413",
Enabled = false,
ForceJobsEnabled = false
},
};
_mockDataAccessLayer1.Setup(x => x.Fetch(nonEmptyQuery)).Returns(output.Take(2).Select(job => job as IConvertableTo<SearchResultItem>).ToList());
_mockDataAccessLayer2.Setup(x => x.Fetch(nonEmptyQuery)).Returns(output.Skip(2).Select(job => job as IConvertableTo<SearchResultItem>).ToList());
List<SearchResultItem> results = _searchService.Search(nonEmptyQuery);
Assert.IsNotNull(results);
Assert.AreEqual(4, results.Count);
foreach (SearchResultItem expectedInResult in expectedResults)
{
Assert.IsTrue(results.Any(r => r.EmployeeKey == expectedInResult.EmployeeKey && r.EntryKey == expectedInResult.EntryKey && r.ProjectKey == expectedInResult.ProjectKey));
//.........这里部分代码省略.........
示例15: OcrParallelizationExperiment
public void OcrParallelizationExperiment()
{
// Init Drive
var relpath = Path.Combine(Dir.OcrDirectory, Dir.OcrParallelizationTesting);
var drive = new Drive(relpath, Drive.Reason.Read);
var regs = drive.Files("reg").ToList();
var revs = drive.Files("rev").ToList();
// Sort to ensure correct pairing
regs.Sort();
revs.Sort();
// Concatenate and Recognize
var images = regs.Concat(revs).Select(path => new Bitmap(path)).ToList();
int revStart = regs.Count;
var datas = new List<OcrData>(OCR.ParallelRecognize(images, images.Count(), Accuracy.Low, "eng", true));
var regdata = datas.Take(revStart);
var revdata = datas.Skip(revStart);
var difference = regdata.Zip(revdata, (reg, rev) =>
{
Console.WriteLine("-----------------------------------------------");
Console.WriteLine(OCR.StripNewLine(reg.Text + " vs " + rev.Text));
Console.WriteLine(reg.Cost + " vs " + rev.Cost);
Console.WriteLine("Diff: " + (reg.Cost - rev.Cost));
Console.WriteLine("scantime: " + reg.ScanTime + "ms and " + rev.ScanTime + "ms");
Console.WriteLine();
return reg.Cost - rev.Cost;
}).ToList();
difference.ForEach(diff => Assert.IsTrue(diff < 0));
}