本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Shuffle方法的典型用法代码示例。如果您正苦于以下问题:C# List.Shuffle方法的具体用法?C# List.Shuffle怎么用?C# List.Shuffle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Shuffle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShuffleTest
public void ShuffleTest()
{
List<int> orderedNumbers = new List<int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
List<int> unorderedNumbers = orderedNumbers.Shuffle().ToList();
Assert.AreNotEqual(orderedNumbers, unorderedNumbers);
}
示例2: GetRandomElementsFromListShufflingTest
public void GetRandomElementsFromListShufflingTest()
{
List<int> l = new List<int>(10);
for (int i = 0; i < 10; i++)
l.Add(i);
l.Shuffle();
}
示例3: TestShuffle
public void TestShuffle()
{
var test = new List<int>() { 25, 67, 10, 88, 35124, 6524, 5, 125, 654, 56, 1, 5451, 15211, 22101, 65121, 1254, 15121, 210, 310, 510, 610, 710, 810, 910 };
var r = test.Shuffle().ToList();
var orderChanged = false;
for(var i = 0; i < test.Count(); i++)
{
if (test[i] != r[i]) continue;
orderChanged = true;
break;
}
Assert.IsTrue(orderChanged);
}
示例4: TestShuffle3Items
public void TestShuffle3Items()
{
List<int> original = new List<int>() { 0, 1, 2 };
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
List<int> shuffled = original.Shuffle();
stopwatch.Stop();
Console.WriteLine(string.Format("Shuffling 3 items took {0} milliseconds or {1} ticks", stopwatch.ElapsedMilliseconds, stopwatch.ElapsedTicks));
CollectionAssert.AllItemsAreUnique(shuffled);
for (int index = 0; index < shuffled.Count; index++) {
Assert.AreNotEqual(original[index], shuffled[index]);
}
}
示例5: EnumerableExtensionsTests_Shuffle_OrderIsShuffled
public void EnumerableExtensionsTests_Shuffle_OrderIsShuffled()
{
// Arrange
var list = new List<int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
// Act
var result = list.Shuffle().ToList();
// Assert
for (var i = 0; i < result.Count; i++)
{
if (list[i] != result[i])
{
return;
}
}
Assert.Fail("List has not been shuffled.");
}
示例6: ResumeInAllDirections
public void ResumeInAllDirections()
{
List<TransferItem> allItems = AllTransferDirectionTest.GetTransformItemsForAllDirections(resume: true);
int fileCount = expectedFileNodes.Keys.Count;
// Execution and store checkpoints
CancellationTokenSource tokenSource = new CancellationTokenSource();
var transferContext = new TransferContext();
var progressChecker = new ProgressChecker(fileCount, 1024 * fileCount);
transferContext.ProgressHandler = progressChecker.GetProgressHandler();
allItems.ForEach(item =>
{
item.CancellationToken = tokenSource.Token;
item.TransferContext = transferContext;
});
var options = new TestExecutionOptions<DMLibDataInfo>();
options.DisableDestinationFetch = true;
// Checkpoint names
const string PartialStarted = "PartialStarted",
AllStarted = "AllStarted",
AllStartedAndWait = "AllStartedAndWait",
BeforeCancel = "BeforeCancel",
AfterCancel = "AfterCancel";
Dictionary<string, TransferCheckpoint> checkpoints = new Dictionary<string, TransferCheckpoint>();
TransferItem randomItem = allItems[random.Next(0, allItems.Count)];
randomItem.AfterStarted = () =>
{
Test.Info("Store check point after transfer item: {0}.", randomItem.ToString());
checkpoints.Add(PartialStarted, transferContext.LastCheckpoint);
};
options.AfterAllItemAdded = () =>
{
progressChecker.DataTransferred.WaitOne();
checkpoints.Add(AllStarted, transferContext.LastCheckpoint);
Thread.Sleep(1000);
checkpoints.Add(AllStartedAndWait, transferContext.LastCheckpoint);
Thread.Sleep(1000);
checkpoints.Add(BeforeCancel, transferContext.LastCheckpoint);
tokenSource.Cancel();
checkpoints.Add(AfterCancel, transferContext.LastCheckpoint);
};
var result = this.RunTransferItems(allItems, options);
// Resume with stored checkpoints in random order
var checkpointList = new List<KeyValuePair<string,TransferCheckpoint>>();
checkpointList.AddRange(checkpoints);
checkpointList.Shuffle();
foreach(var pair in checkpointList)
{
Test.Info("===Resume with checkpoint '{0}'===", pair.Key);
options = new TestExecutionOptions<DMLibDataInfo>();
options.DisableDestinationFetch = true;
progressChecker.Reset();
transferContext = new TransferContext(DMLibTestHelper.RandomReloadCheckpoint(pair.Value))
{
ProgressHandler = progressChecker.GetProgressHandler(),
// The checkpoint can be stored when DMLib doesn't check overwrite callback yet.
// So it will case an skip file error if the desination file already exists and
// We don't have overwrite callback here.
OverwriteCallback = DMLibInputHelper.GetDefaultOverwiteCallbackY()
};
TransferEventChecker eventChecker = new TransferEventChecker();
eventChecker.Apply(transferContext);
List<TransferItem> itemsToResume = allItems.Select(item =>
{
TransferItem itemToResume = item.Clone();
itemToResume.TransferContext = transferContext;
return itemToResume;
}).ToList();
result = this.RunTransferItems(itemsToResume, options);
foreach (DMLibDataType destDataType in DataTypes)
{
DataAdaptor<DMLibDataInfo> destAdaptor = GetSourceAdaptor(destDataType);
DMLibDataInfo destDataInfo = destAdaptor.GetTransferDataInfo(string.Empty);
foreach (FileNode destFileNode in destDataInfo.EnumerateFileNodes())
{
string fileName = destFileNode.Name;
FileNode sourceFileNode = expectedFileNodes[fileName];
Test.Assert(DMLibDataHelper.Equals(sourceFileNode, destFileNode), "Verify transfer result.");
}
}
Test.Assert(result.Exceptions.Count == 0, "Verify no error happens. Actual: {0}", result.Exceptions.Count);
}
//.........这里部分代码省略.........
示例7: Test_Shuffle
public void Test_Shuffle()
{
var list = new List<int> { 1, 2, 3 };
var newList = list.Shuffle().ToList();
Assert.IsFalse((newList[0] == list[0]).And(newList[1] == list[1]).And(newList[2] == list[2]));
}
示例8: ShuffleTestNull
public void ShuffleTestNull()
{
var nulls = new List<string> { null, null, null };
nulls.Shuffle();
}
示例9: ShuffleTestEmpty
public void ShuffleTestEmpty()
{
var ints = new List<int>();
ints.Shuffle();
}
示例10: VoxelMaterialAssetsGenerateFixed
public void VoxelMaterialAssetsGenerateFixed()
{
SpaceEngineersCore.LoadDefinitions();
var materials = SpaceEngineersCore.Resources.GetMaterialList();
Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?");
var files = new[] { @".\TestAssets\Arabian_Border_7.vx2", @".\TestAssets\cube_52x52x52.vx2" };
foreach (var fileOriginal in files)
{
foreach (var material in materials)
{
var fileNewVoxel =
Path.Combine(Path.GetDirectoryName(Path.GetFullPath(fileOriginal)),
Path.GetFileNameWithoutExtension(fileOriginal) + "_" + material.Id.SubtypeId + ".vx2").ToLower();
var voxelMap = new MyVoxelMap();
voxelMap.Load(fileOriginal, materials[0].Id.SubtypeId);
IList<byte> materialAssets;
Dictionary<byte, long> materialVoxelCells;
voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells);
var distribution = new[] { Double.NaN, .99, };
var materialSelection = new byte[] { 0, SpaceEngineersCore.Resources.GetMaterialIndex(material.Id.SubtypeId) };
var newDistributiuon = new List<byte>();
int count;
for (var i = 1; i < distribution.Count(); i++)
{
count = (int)Math.Floor(distribution[i] * materialAssets.Count); // Round down.
for (var j = 0; j < count; j++)
{
newDistributiuon.Add(materialSelection[i]);
}
}
count = materialAssets.Count - newDistributiuon.Count;
for (var j = 0; j < count; j++)
{
newDistributiuon.Add(materialSelection[0]);
}
newDistributiuon.Shuffle();
voxelMap.SetMaterialAssets(newDistributiuon);
voxelMap.Save(fileNewVoxel);
}
}
}
示例11: VoxelMaterialAssetsRandom
public void VoxelMaterialAssetsRandom()
{
SpaceEngineersCore.LoadDefinitions();
var materials = SpaceEngineersCore.Resources.GetMaterialList();
Assert.IsTrue(materials.Count > 0, "Materials should exist. Has the developer got Space Engineers installed?");
var stoneMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Stone_05"));
Assert.IsNotNull(stoneMaterial, "Stone material should exist.");
var goldMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Gold"));
Assert.IsNotNull(goldMaterial, "Gold material should exist.");
var uraniumMaterial = materials.FirstOrDefault(m => m.Id.SubtypeId.Contains("Uraninite_01"));
Assert.IsNotNull(uraniumMaterial, "Uranium material should exist.");
const string fileOriginal = @".\TestAssets\Arabian_Border_7.vx2";
const string fileNewVoxel = @".\TestOutput\Arabian_Border_7_mixed.vx2";
var voxelMap = new MyVoxelMap();
voxelMap.Load(fileOriginal, materials[0].Id.SubtypeId);
IList<byte> materialAssets;
Dictionary<byte, long> materialVoxelCells;
voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells);
Assert.AreEqual(35465, materialAssets.Count, "Asset count should be equal.");
var distribution = new[] { Double.NaN, .5, .25 };
var materialSelection = new[] { SpaceEngineersCore.Resources.GetMaterialIndex(stoneMaterial.Id.SubtypeId), SpaceEngineersCore.Resources.GetMaterialIndex(goldMaterial.Id.SubtypeId), SpaceEngineersCore.Resources.GetMaterialIndex(uraniumMaterial.Id.SubtypeId) };
var newDistributiuon = new List<byte>();
int count;
for (var i = 1; i < distribution.Count(); i++)
{
count = (int)Math.Floor(distribution[i] * materialAssets.Count); // Round down.
for (var j = 0; j < count; j++)
{
newDistributiuon.Add(materialSelection[i]);
}
}
count = materialAssets.Count - newDistributiuon.Count;
for (var j = 0; j < count; j++)
{
newDistributiuon.Add(materialSelection[0]);
}
newDistributiuon.Shuffle();
var assetNameCount = voxelMap.CountAssets(newDistributiuon);
Assert.AreEqual(3, assetNameCount.Count, "Asset Mertials count should be equal.");
Assert.AreEqual(8867, assetNameCount[stoneMaterial.Id.SubtypeId], "Asset Mertials count should be equal.");
Assert.AreEqual(17732, assetNameCount[goldMaterial.Id.SubtypeId], "Asset Mertials count should be equal.");
Assert.AreEqual(8866, assetNameCount[uraniumMaterial.Id.SubtypeId], "Asset Mertials count should be equal.");
voxelMap.SetMaterialAssets(newDistributiuon);
voxelMap.CalculateMaterialCellAssets(out materialAssets, out materialVoxelCells);
var cellCount = voxelMap.SumVoxelCells();
voxelMap.Save(fileNewVoxel);
}
示例12: PrepareCloudFileWithDifferentSizeRange
private void PrepareCloudFileWithDifferentSizeRange(CloudFile cloudFile)
{
List<int> ranges = new List<int>();
List<int> gaps = new List<int>();
// Add one 4MB - 16MB range
ranges.Add(random.Next(4 * 1024 * 1024, 16 * 1024 * 1024));
// Add one 1B range
ranges.Add(1);
int remainingPageNumber = random.Next(10, 20);
// Add ten - twenty 1B - 4MB range
for (int i = 0; i < remainingPageNumber; ++i)
{
ranges.Add(random.Next(1, 4 * 1024 * 1024));
}
// Add one 4M - 8M gap
gaps.Add(random.Next(4 * 1024 * 1024, 8 * 1024 * 1024));
// Add 512B - 2048B gaps
for (int i = 1; i < ranges.Count - 1; ++i)
{
gaps.Add(random.Next(1, 512 * 4));
}
if (DMLibTestContext.DestType == DMLibDataType.PageBlob)
{
int totalSize = ranges.Sum() + gaps.Sum();
int remainder = totalSize % 512;
if (remainder != 0)
{
ranges[ranges.Count - 1] += 512 - remainder;
}
}
ranges.Shuffle();
gaps.Shuffle();
CloudFileHelper.GenerateCloudFileWithRangedData(cloudFile, ranges, gaps);
}
示例13: PreparePageBlobWithDifferenSizePage
private void PreparePageBlobWithDifferenSizePage(CloudPageBlob pageBlob)
{
List<int> ranges = new List<int>();
List<int> gaps = new List<int>();
// Add one 4MB - 16MB page, align with 512 byte
ranges.Add(random.Next(4 * 2 * 1024, 16 * 2 * 1024) * 512);
// Add one 512B page
ranges.Add(512);
int remainingPageNumber = random.Next(10, 20);
// Add ten - twenty 512B - 4MB page, align with 512 byte
for (int i = 0; i < remainingPageNumber; ++i)
{
ranges.Add(random.Next(1, 4 * 2 * 1024) * 512);
}
// Add one 4M - 8M gap, align with 512 byte
gaps.Add(random.Next(4 * 2 * 1024, 8 * 2 * 1024) * 512);
// Add 512B - 2048B gaps, align with 512 byte
for (int i = 1; i < ranges.Count - 1; ++i)
{
gaps.Add(random.Next(1, 5) * 512);
}
ranges.Shuffle();
gaps.Shuffle();
CloudBlobHelper.GeneratePageBlobWithRangedData(pageBlob, ranges, gaps);
}
示例14: Shuffle
public void Shuffle()
{
var items = new List<string> { "a", "b", "c", "d", "e" };
items.Shuffle();
}
示例15: ShuffleWithProvidedRandomGenerator
public void ShuffleWithProvidedRandomGenerator()
{
var items = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8 };
using(var random = (new MockSecureRandomForShuffle()))
{
items.Shuffle(random);
}
CollectionAssert.AreEqual(new List<int> { 7, 5, 4, 3, 1, 8, 2, 6 }, items);
}