本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Zip方法的典型用法代码示例。如果您正苦于以下问题:C# List.Zip方法的具体用法?C# List.Zip怎么用?C# List.Zip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Zip方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestZipAddTo_NullCombiner_Throws
public void TestZipAddTo_NullCombiner_Throws()
{
IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist();
IExpandableSublist<List<int>, int> list2 = new List<int>().ToSublist();
Func<int, int, int> combiner = null;
list1.Zip(list2, combiner);
}
示例2: TestZipAddTo_NullDestination_Throws
public void TestZipAddTo_NullDestination_Throws()
{
IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist();
IExpandableSublist<List<int>, int> list2 = new List<int>().ToSublist();
IExpandableSublist<List<int>, int> destination = null;
Func<int, int, int> combiner = (i, j) => i + j;
list1.Zip(list2, combiner).AddTo(destination);
}
示例3: TestGetAllMatching
public void TestGetAllMatching()
{
const string dir = "TestRecursiveMatching";
RemoveDirectory(Path.Combine(Drive.GetDriveRoot(), UnitTestFolder, dir));
var expected = new List<string>();
BuildNestedDirectory(Path.Combine(Drive.GetDriveRoot(), UnitTestFolder, dir), expected);
var drive = new Drive(Path.Combine(UnitTestFolder, dir), Drive.Reason.Read);
var actual = drive.GetAllMatching("image");
expected.Sort();
actual.Sort();
var same = expected.Zip(actual, (first, second) => first == second).All(x => x);
Assert.IsTrue(same);
}
示例4: ReadXsvLineTest01
public void ReadXsvLineTest01()
{
var result = new List<IList<string>>();
using (var reader = new XsvReader(new StringReader(testData01)))
{
while (!reader.EndOfData)
{
var row = reader.ReadXsvLine(new[] { "," }).ToArray();
result.Add(row);
}
}
foreach (var row in result.Zip(expected01, (l, r) => new { expected = r, actual = l }))
{
Console.WriteLine(row.actual.ConcatWith("|") + "\\n");
CollectionAssert.AreEqual((ICollection)row.expected, (ICollection)row.actual);
}
}
示例5: testBunchOfInsertionsAndDeletions
public void testBunchOfInsertionsAndDeletions()
{
var list = new List<double> { 74, 101, 11, 1000, 4, -101, -1000 };
var minHeap = new MinHeap();
list.ForEach(elem => minHeap.Add(elem));
list.Sort();
var mins = new List<double>();
for (int i = 0; i < list.Count; i++)
{
mins.Add(minHeap.removeMin());
}
List<Tuple<double, double>> expectedVsActual = list.Zip(mins, Tuple.Create).ToList();
foreach(var tuple in expectedVsActual)
{
Assert.AreEqual(tuple.Item1, tuple.Item2);
}
}
示例6: TestZipCopy_NullList2_Throws
public void TestZipCopy_NullList2_Throws()
{
IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist();
IExpandableSublist<List<int>, int> list2 = null;
Func<int, int, int> combiner = (i, j) => i + j;
list1.Zip(list2, combiner);
}
示例7: Zip_abnormal
public void Zip_abnormal()
{
// arrange
List<int> first = new List<int>() { 1, 2, 3 };
List<String> second = new List<String>() { "Angular", "React", "Backbone" };
Func<int, String, String> resultSelector = (x, y) => String.Format("{0} {1}", x, y);
Func<int, String, String> resultSelectorNull = null;
// act and assert
try
{
first.Zip(null, resultSelector);
Assert.Fail();
}
catch (Exception e)
{
Assert.IsTrue(e is ArgumentNullException);
}
try
{
first.Zip(second, resultSelectorNull);
Assert.Fail();
}
catch (Exception e)
{
Assert.IsTrue(e is ArgumentNullException);
}
}
示例8: RowToDictionary
private Dictionary<string, string> RowToDictionary(ListViewRow row,
List<string> names)
{
var values = row.Cells.Select(c => c.Text).ToList();
var combined = names.Zip(values, (k, v) => new { k, v });
return combined.ToDictionary(x => x.k, x => x.v);
}
示例9: ReadXsvObservableTest
public void ReadXsvObservableTest()
{
var csv = new List<IList<string>>();
using (var reader = new XsvReader(new StringReader(testData01)))
{
csv.Add(reader.ReadXsvLine(new[] { "," }).ToArray());
#if net40
IDisposable disposable = reader.ReadXsvAsObservable(new[] { "," }, System.Reactive.Concurrency.ThreadPoolScheduler.Instance).Subscribe(row =>
#endif
#if net45
IDisposable disposable = reader.ReadXsvAsObservable(new[] { "," }).Subscribe(row =>
#endif
{
csv.Add(row);
Console.WriteLine("OnNext");
Console.WriteLine(row.ConcatWith(", "));
},
e => Console.WriteLine("OnError " + e.Message),
() =>
{
Console.WriteLine("OnCompleted.");
foreach (var row in csv.Zip(expected01, (l, r) => new { expected = r, actual = l }))
{
Console.WriteLine(row.actual.ConcatWith("|") + "\\n");
CollectionAssert.AreEqual((ICollection)row.expected, (ICollection)row.actual);
}
});
}
}
示例10: Zip
public void Zip()
{
// arrange
List<int> first = new List<int>() { 1, 2, 3 };
List<String> second = new List<String>() { "Angular", "React", "Backbone" };
// act
List<String> actual = first.Zip(second, (x, y) => String.Format("{0} {1}", x, y)).ToList();
// assert
Assert.AreEqual("1 Angular", actual[0]);
Assert.AreEqual("2 React", actual[1]);
Assert.AreEqual("3 Backbone", actual[2]);
}
示例11: TestSerializeDeserializeUsingSequentialContainers
public void TestSerializeDeserializeUsingSequentialContainers()
{
//CreateDeserializerOnly a new AvroSerializer instance and specify a custom serialization strategy AvroDataContractResolver
//for handling only properties attributed with DataContract/DateMember.
var settings = new AvroSerializerSettings();
//CreateDeserializerOnly a new buffer
using (var buffer = new MemoryStream())
{
//CreateDeserializerOnly sample data
var testData = new List<SensorData>
{
new SensorData { Value = new byte[] { 1, 2, 3, 4, 5 }, Position = new Location { Room = 243, Floor = 1 } },
new SensorData { Value = new byte[] { 6, 7, 8, 9 }, Position = new Location { Room = 244, Floor = 1 } }
};
//CreateDeserializerOnly a SequentialWriter instance for type SensorData which can serialize a sequence of SensorData objects to stream
using (var w = AvroContainer.CreateWriter<SensorData>(buffer, settings, Codec.Null))
{
using (var writer = new SequentialWriter<SensorData>(w, 24))
{
// Serialize the data to stream using the sequential writer
testData.ForEach(writer.Write);
}
}
//Prepare the stream for deserializing the data
buffer.Seek(0, SeekOrigin.Begin);
//CreateDeserializerOnly a SequentialReader for type SensorData which will derserialize all serialized objects from the given stream
//It allows iterating over the deserialized objects because it implements IEnumerable<T> interface
using (var reader = new SequentialReader<SensorData>(
AvroContainer.CreateReader<SensorData>(buffer, true, settings, new CodecFactory())))
{
var results = reader.Objects;
//Finally, verify that deserialized data matches the original ones
var pairs = testData.Zip(results, (serialized, deserialized) => new { expected = serialized, actual = deserialized });
foreach (var pair in pairs)
{
Assert.IsTrue(this.Equal(pair.expected, pair.actual));
}
}
}
}
示例12: TestPointMappingRecoverFromLSM
public void TestPointMappingRecoverFromLSM()
{
ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager(
Globals.ShardMapManagerConnectionString,
ShardMapManagerLoadPolicy.Lazy);
ListShardMap<int> listsm = smm.GetListShardMap<int>(RecoveryManagerTests.s_listShardMapName);
Assert.IsNotNull(listsm);
ShardLocation sl = new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, RecoveryManagerTests.s_shardedDBs[0]);
Shard s = listsm.CreateShard(sl);
Assert.IsNotNull(s);
for (int i = 0; i < 5; i++)
{
PointMapping<int> r = listsm.CreatePointMapping(creationInfo: new PointMappingCreationInfo<int>(i, s, MappingStatus.Online));
Assert.IsNotNull(r);
}
// Delete all the ranges and shardmaps from the shardlocation.
using (SqlConnection conn = new SqlConnection(Globals.ShardMapManagerTestConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("delete from shard1.__ShardManagement.ShardMappingsLocal", conn))
{
cmd.ExecuteNonQuery();
}
}
RecoveryManager rm = new RecoveryManager(smm);
var gs = rm.DetectMappingDifferences(sl);
// Validate that all the shard locations are in fact missing from the LSM.
foreach (RecoveryToken g in gs)
{
var kvps = rm.GetMappingDifferences(g);
Assert.AreEqual(5, kvps.Keys.Count, "The count of differences does not match the expected.");
foreach (var kvp in kvps)
{
ShardRange range = kvp.Key;
MappingLocation mappingLocation = kvp.Value;
Assert.AreEqual(MappingLocation.MappingInShardMapOnly, mappingLocation, "An unexpected difference between global and local shardmaps was detected. This is likely a false positive and implies a bug in the detection code.");
}
rm.RebuildMappingsOnShard(g, kvps.Keys.Take(3));
}
gs = rm.DetectMappingDifferences(sl);
foreach (RecoveryToken g in gs)
{
var kvps = rm.GetMappingDifferences(g);
Assert.AreEqual(2, kvps.Values.Where(loc => loc != MappingLocation.MappingInShardMapAndShard).Count(), "The count of differences does not match the expected.");
// We expect that the last two ranges only are missing from the shards.
var expectedLocations = new List<MappingLocation>()
{
MappingLocation.MappingInShardMapAndShard,
MappingLocation.MappingInShardMapAndShard,
MappingLocation.MappingInShardMapAndShard,
MappingLocation.MappingInShardMapOnly,
MappingLocation.MappingInShardMapOnly,
};
Assert.IsTrue(expectedLocations.Zip(kvps.Values, (x, y) => x == y).Aggregate((x, y) => x && y), "RebuildRangeShardMap rebuilt the shards out of order with respect to its keeplist.");
// Rebuild the range, leaving 1 inconsistency
rm.RebuildMappingsOnShard(g, kvps.Keys.Skip(1));
}
gs = rm.DetectMappingDifferences(sl);
foreach (RecoveryToken g in gs)
{
var kvps = rm.GetMappingDifferences(g);
Assert.AreEqual(1, kvps.Values.Where(loc => loc != MappingLocation.MappingInShardMapAndShard).Count(), "The count of differences does not match the expected.");
// Rebuild the range, leaving no inconsistencies
rm.RebuildMappingsOnShard(g, kvps.Keys);
}
gs = rm.DetectMappingDifferences(sl);
// Everything should be semantically consistent now.
foreach (RecoveryToken g in gs)
{
var kvps = rm.GetMappingDifferences(g);
Assert.AreEqual(0, kvps.Values.Where(loc => loc != MappingLocation.MappingInShardMapAndShard).Count(), "The count of differences does not match the expected.");
// As a sanity check, make sure the root is restorable from this LSM.
rm.ResolveMappingDifferences(g, MappingDifferenceResolution.KeepShardMapping);
}
gs = rm.DetectMappingDifferences(sl);
foreach (RecoveryToken g in gs)
{
//.........这里部分代码省略.........