本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Select方法的典型用法代码示例。如果您正苦于以下问题:C# List.Select方法的具体用法?C# List.Select怎么用?C# List.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompareIntegerWeights
public void CompareIntegerWeights()
{
Random random = new Random((int) DateTime.Now.Ticks);
List<double> xRepeatedValues = new List<double>();
List<double> yRepeatedValues = new List<double>();
List<int> weights = new List<int>();
var sampleTuples = new List<Tuple<double[], double>>();
for (int i = 0; i < 10; i++)
{
int weight = random.Next(1, 10);
weights.Add(weight);
double x = random.NextDouble();
xRepeatedValues.AddRange(Enumerable.Repeat(x, weight));
double y = random.NextDouble();
yRepeatedValues.AddRange(Enumerable.Repeat(y, weight));
sampleTuples.Add(new Tuple<double[], double>(new[]{x}, y));
}
const double epsilon = 1E-12;
var repeatedIntercept = Statistics.Intercept(new Statistics(yRepeatedValues),
new Statistics(xRepeatedValues));
var repeatedSlope = Statistics.Slope(new Statistics(yRepeatedValues), new Statistics(xRepeatedValues));
var repeatedSlopeWithoutIntercept = SlopeWithoutIntercept(yRepeatedValues, xRepeatedValues);
var weightedRegression = WeightedRegression.Weighted(sampleTuples, weights.Select(w=>(double)w).ToArray(), true);
Assert.AreEqual(repeatedIntercept, weightedRegression[0], epsilon);
Assert.AreEqual(repeatedSlope, weightedRegression[1], epsilon);
var weightedRegressionWithoutIntercept = WeightedRegression.Weighted(sampleTuples,
weights.Select(w => (double) w).ToArray());
Assert.AreEqual(repeatedSlopeWithoutIntercept, weightedRegressionWithoutIntercept[0], epsilon);
}
示例2: Test_Neighbors
public void Test_Neighbors()
{
var list = ShortestPath.GetNeighbors(new Position(1, 1), 3, 3);
var correct = new List<Position> {
new Position(0, 0),
new Position(0, 1),
new Position(0, 2),
new Position(1, 0),
new Position(1, 2),
new Position(2, 0),
new Position(2, 1),
new Position(2, 2)
};
Assert.IsTrue(list.Select(o => o.x).SequenceEqual(correct.Select(o => o.x)));
Assert.IsTrue(list.Select(o => o.y).SequenceEqual(correct.Select(o => o.y)));
list = ShortestPath.GetNeighbors(new Position(2, 2), 3, 3);
correct = new List<Position> {
new Position(1, 1),
new Position(1, 2),
new Position(2, 1),
};
Assert.IsTrue(list.Select(o => o.x).SequenceEqual(correct.Select(o => o.x)));
Assert.IsTrue(list.Select(o => o.y).SequenceEqual(correct.Select(o => o.y)));
list = ShortestPath.GetNeighbors(new Position(0, 0), 3, 3);
correct = new List<Position> {
new Position(0, 1),
new Position(1, 0),
new Position(1, 1),
};
Assert.IsTrue(list.Select(o => o.x).SequenceEqual(correct.Select(o => o.x)));
Assert.IsTrue(list.Select(o => o.y).SequenceEqual(correct.Select(o => o.y)));
}
示例3: TestGetToken
public void TestGetToken()
{
//arrange
var list = new List<ITokenPairRecord>();
var processor = new InstrumentationLib.Moles.MMemoryFile<ITokenPairRecord>()
{
Open = () => true,
WriteT = ( b ) => { list.Add(b); return true; }
};
var service = new InstrumentationLib.TokenService(1000, processor.Instance) {Enabled = true};
const int eventId = 3;
//act
var tokenPairRec = service.GetToken(eventId);
//assert
System.Threading.Thread.Sleep(1000);
Assert.AreEqual(1, list.Count, "list count");
Assert.AreEqual((ulong)1, tokenPairRec.T2.Id);
Assert.AreEqual((short)1000, tokenPairRec.T2.AppId);
Assert.AreEqual(eventId, tokenPairRec.T2.EventId);
Assert.AreEqual((ulong)1, list.Select(r => r.T2.Id).First());
Assert.AreEqual((short)1000, list.Select(r => r.T2.AppId).First());
Assert.AreEqual(eventId, list.Select(r => r.T2.EventId).First());
Assert.AreEqual(true, list.Select(r => r.T1.IsNull()).First());
}
示例4: ParseEndUserSuppliedXriIdentifer
public void ParseEndUserSuppliedXriIdentifer()
{
List<char> symbols = new List<char>(XriIdentifier.GlobalContextSymbols);
symbols.Add('(');
List<string> prefixes = new List<string>();
prefixes.AddRange(symbols.Select(s => s.ToString()));
prefixes.AddRange(symbols.Select(s => "xri://" + s.ToString()));
foreach (string prefix in prefixes) {
var id = Identifier.Parse(prefix + "andrew");
Assert.IsInstanceOfType(id, typeof(XriIdentifier));
}
}
示例5: Test_GetShortestPath
public void Test_GetShortestPath()
{
var cells = new Cell[,] {
{ new Cell("a"), new Cell("b"), new Cell("c") },
{ new Cell("z"), new Cell("z"), new Cell("d") },
{ new Cell("z"), new Cell("z"), new Cell("e") }
};
var path = ShortestPath.GetShortestPath(cells, new Position(0, 0), new Position(2, 2));
var correct = new List<Position> {
new Position(0,0), new Position(0,1),
new Position(1,2), new Position(2,2),
};
Assert.IsTrue(path.Select(o => o.x).SequenceEqual(correct.Select(o => o.x)));
Assert.IsTrue(path.Select(o => o.y).SequenceEqual(correct.Select(o => o.y)));
}
示例6: SelectProperties
private List<PropertyInfo> SelectProperties(Type t)
{
IPropertySelectorPolicy selector = new PropertySelectorPolicy<DependencyAttribute>();
IBuilderContext context = GetContext(t);
var properties = new List<SelectedProperty>(selector.SelectProperties(context, context.PersistentPolicies));
return properties.Select(sp => sp.Property).ToList();
}
示例7: Change3Tags_Successful
public void Change3Tags_Successful()
{
// Init
var mp3Files = new List<IMp3File>
{
new FakeMp3File(new Mp3Tags(), SourceFolder + "1.newartist1 - newtitle1.mp3"),
new FakeMp3File(new Mp3Tags(), SourceFolder + "2.newartist2 - newtitle2.mp3"),
new FakeMp3File(new Mp3Tags(), SourceFolder + "3.newartist3 - newtitle3.mp3"),
};
// Act
var commandPool = mp3Files.Select(mp3File => new ChangeTagsCommand(mp3File, "{track}.{artist} - {title}")).Cast<Command>().ToList();
commandPool.ForEach(command => command.Execute());
// Assert
Assert.AreEqual("newartist1", mp3Files[0].Tags.Artist);
Assert.AreEqual("newartist2", mp3Files[1].Tags.Artist);
Assert.AreEqual("newartist3", mp3Files[2].Tags.Artist);
Assert.AreEqual("newtitle1", mp3Files[0].Tags.Title);
Assert.AreEqual("newtitle2", mp3Files[1].Tags.Title);
Assert.AreEqual("newtitle3", mp3Files[2].Tags.Title);
Assert.AreEqual((uint)1, mp3Files[0].Tags.Track);
Assert.AreEqual((uint)2, mp3Files[1].Tags.Track);
Assert.AreEqual((uint)3, mp3Files[2].Tags.Track);
}
示例8: Aggregate
public static void Aggregate(params Action[] actions)
{
var exceptions = new List<AssertFailedException>();
foreach (var action in actions)
{
try
{
action();
}
catch (AssertFailedException ex)
{
exceptions.Add(ex);
}
}
var assertionTexts =
exceptions.Select(assertFailedException => assertFailedException.Message).ToList();
if (0 != assertionTexts.Count)
{
throw new
AssertFailedException(
assertionTexts.Aggregate(
(aggregatedMessage, next) => aggregatedMessage + Environment.NewLine + next));
}
}
示例9: JobManager_Executa_Metodos_Em_Sequencia_TEST
public void JobManager_Executa_Metodos_Em_Sequencia_TEST()
{
var idList = new List<Guid>();
for (int i = 0; i < 20; i++)
{
var a = i;
idList.Add(TestJobQueue.Instance.Enqueue(
"op-err" + i,
() => { Thread.Sleep(10); throw new Exception("ERRO SOCORRO" + a); },
"master"));
}
var jobs = idList.Select(x => JobManager.Instance.FindJob(x)).ToList();
while (jobs.Any(x => !x.Done))
{
Thread.Sleep(10);
}
var idx = 0;
foreach (var job in jobs.OrderBy(x => x.StartDate))
{
Assert.IsTrue(job.Done);
Assert.IsNotNull(job.Error);
Assert.AreEqual(jobs[idx], job);
Assert.AreEqual("ERRO SOCORRO" + idx, job.Error.Message);
idx++;
}
}
示例10: RunAllTests
public void RunAllTests()
{
var ta = new TestArguments(new[] { string.Format("assembly={0}", _testAssembly), "newDomain=true" });
// Get tests
var assembly = Assembly.LoadFrom(ta.AssemblyLocation);
var filteredTests = new List<MethodInfo>(AssemblyParser.GetTestMethods(assembly));
var tests = filteredTests.Select(test => string.Format("{0}.{1}", test.ReflectedType.FullName, test.Name)).ToList();
// Run tests
var sw = Stopwatch.StartNew();
TestResult result = new Runner.TestRunner().RunTestsInParallel(tests, assembly, ta.NumberOfThreads);
sw.Stop();
var total = (from object r in result.Results select r as TestResult).Count();
var failed = (from object r in result.Results select r as TestResult).Count(tr => tr.IsFailure || tr.IsError);
var passed = (from object r in result.Results select r as TestResult).Count(tr => tr.IsSuccess);
// Test should finish in under one minute
Assert.IsTrue(sw.ElapsedMilliseconds / 1000 < 60);
// 10 Tests were run
Assert.IsTrue(total == 10);
// 1 Failed
Assert.IsTrue(failed == 1);
// 9 Passed
Assert.IsTrue(passed == 9);
}
示例11: Can_add_documents_and_search
public void Can_add_documents_and_search()
{
var documents = new List<Document>();
for(var i = 0; i < 10; i++)
{
dynamic newDocument = CreateDocument();
newDocument.BookId = 9-i;
documents.Add(newDocument);
_luceneIndex.Insert(newDocument);
Thread.Sleep(1200);
}
var documentIds = documents.Select(c => c._id.Value).ToList();
documentIds.Reverse();
_luceneIndex.Refresh();
var criteria = new SearchCriteria
{
Query = "hitchhiker AND galaxy",
SortByField = "BookId",
TopN = 10
};
var result = _luceneIndex.Search(criteria);
Assert.AreEqual<int?>(result.ItemCount, 10);
Assert.AreEqual<int?>(result.ItemCount, result.TotalHits);
Assert.IsTrue(result.Items.SequenceEqual(documentIds));
}
示例12: Analyse_Common_Successful
public void Analyse_Common_Successful()
{
// Init
const string sourceFolder = @"D:\music\";
var mp3Files = new List<IMp3File>
{
new FakeMp3File(new Mp3Tags
{
Album = "TestAlbum1", Artist = "TestArtist1", Genre = "TestGenre1", Title = "TestTitle1", Track = 1
}, sourceFolder + "TestArtist1 - TestTitle2.mp3"),
new FakeMp3File(new Mp3Tags
{
Album = "TestAlbum2", Artist = "TestArtist2", Genre = "TestGenre2", Title = "TestTitle2", Track = 2
}, sourceFolder + "TestArtist2 - TestTitle2.mp3"),
};
var fakeWriter = new FakeWorker();
var commandPool = mp3Files.Select(mp3File => new AnalyseCommand(mp3File, "{artist} - {title}", fakeWriter)).Cast<Command>().ToList();
// Act
commandPool.ForEach(command => command.Execute());
// Assert
Assert.AreEqual("File: " + mp3Files[0].FullName + "\n" +
"{title} in file name: TestTitle2; {title} in tags: TestTitle1\n\n", fakeWriter.Stream.ToString());
}
示例13: ClassSetup
public static void ClassSetup(TestContext testContext)
{
//Set up a test configuration to use.
_testConfig = new NameValueCollection();
_testConfig.Add("applicationName", "DMTestApp");
_testUsers = TestUtils.GetTestUsers(2, "Role");
_testRoles = TestUtils.GetTestRoles(3, "Sample");
//Clear out old data in case our previous run crashed
ClassCleanup();
var mRoleSetup = new RoleProv();
mRoleSetup.Initialize("DormouseRoleProvider", _testConfig);
mRoleSetup.CreateRole("DefaultRole");
foreach (var r in _testRoles)
{
mRoleSetup.CreateRole(r);
}
var mpSetup = new MemberProv();
mpSetup.Initialize("DormouseMembershipProvider", _testConfig);
foreach (var u in _testUsers)
{
MembershipCreateStatus status;
mpSetup.CreateUser(u.username, u.password, u.email, u.passwordQuestion,
u.passwordAnswer, u.isApproved, u.providerUserKey, out status);
}
mRoleSetup.AddUsersToRoles(_testUsers.Select(u=>u.username).ToArray(), new[] { "DefaultRole" });
}
示例14: TestSelectAdd_NullDestination_Throws
public void TestSelectAdd_NullDestination_Throws()
{
IReadOnlySublist<List<int>, int> list = new List<int>().ToSublist();
IExpandableSublist<List<int>, int> destination = null;
Func<int, int> converter = i => i;
list.Select(converter).AddTo(destination);
}
示例15: TestStrategy
public void TestStrategy(Strategy strategy, World environment, StrategyTesterReport start, List<PointD> expectedPoints, List<double> expectedAngles, List<bool> expectedResults)
{
var curReport = start;
var reports = new List<StrategyTesterReport>();
while (true)
{
var newAction = strategy.GetNextState(curReport);
var movesList = newAction.Item1;
if (newAction.Item2 is EndOfStrategy) break;
curReport = environment.TryMove(curReport, movesList, true);
reports.Add(curReport);
}
CollectionAssert.AreEqual(reports.Select(x => x.Coords).ToList(), expectedPoints);
CollectionAssert.AreEqual(reports.Select(x => x.AngleInRadians).ToList(), expectedAngles, new DoubleComaperer());
CollectionAssert.AreEqual(reports.Select(x => x.Success).ToList(), expectedResults);
}