本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Reverse方法的典型用法代码示例。如果您正苦于以下问题:C# List.Reverse方法的具体用法?C# List.Reverse怎么用?C# List.Reverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Reverse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: addAllVerticalPointsToListTest
public void addAllVerticalPointsToListTest()
{
List<Point> list = new List<Point>();
List<Point> listExpected = new List<Point>();
int miny = 0;
int maxy = 4;
int x = 1;
listExpected.Add(new Point(x, 0));
listExpected.Add(new Point(x, 1));
listExpected.Add(new Point(x, 2));
listExpected.Add(new Point(x, 3));
listExpected.Add(new Point(x, 4));
ArraySpaceUtilities.addAllVerticalPointsToList(ref list, miny, maxy, x, true);
Assert.AreEqual(listExpected.Count, list.Count);
Point[] listasarray = list.ToArray();
Point[] expectedlistasarray = listExpected.ToArray();
for (int i = 0; i < listasarray.Length; i++)
{
Assert.AreEqual(true, listasarray[i].Equals(expectedlistasarray[i]));
}
listExpected.Reverse();
list.Clear();
ArraySpaceUtilities.addAllVerticalPointsToList(ref list, miny, maxy, x, false);
Assert.AreEqual(listExpected.Count, list.Count);
listasarray = list.ToArray();
expectedlistasarray = listExpected.ToArray();
for (int i = 0; i < listasarray.Length; i++)
{
Assert.AreEqual(true, listasarray[i].Equals(expectedlistasarray[i]));
}
}
示例2: DoesMaxHeapifyTest5
public void DoesMaxHeapifyTest5()
{
List<int> sourceData = new List<int>(new int[] { -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 });
sourceData.Reverse();
sourceData.HeapifyMax();
var isHeap = IsMaxHeap(sourceData);
Assert.IsTrue(isHeap);
}
示例3: TestMethod1
public void TestMethod1()
{
Priority[] expectedValue = new Priority[] { Priority.High, Priority.High, Priority.Medium, Priority.Medium, Priority.Low, Priority.Low };
Priority[] actualValue = new Priority[] { Priority.Low, Priority.Medium, Priority.High, Priority.Medium, Priority.High, Priority.Low };
Quicksort(actualValue, 0, 5);
List<Priority> reverted = new List<Priority>(actualValue);
reverted.Reverse();
CollectionAssert.AreEqual(expectedValue, reverted);
}
示例4: InsertionSort
public List<Candidate> InsertionSort(List<Candidate> list)
{
int i, j;
for (i = 1; i < list.Count; i++)
{
for (int k = i; k > 0 && list[k].numberOfVotes < list[k - 1].numberOfVotes; k--)
Swap(list, k, k - 1);
}
list.Reverse();
return list;
}
示例5: PlusOne
public int[] PlusOne(int[] digits)
{
digits = digits.Reverse().ToArray();
List<int> res = new List<int>();
int carry = 1;
for (int i = 0; i < digits.Length; i++)
{
int newNumber = digits[i] + carry;
res.Add(newNumber % 10);
carry = newNumber / 10;
}
if (carry > 0)
{
res.Add(carry);
}
res.Reverse();
return res.ToArray();
}
示例6: TestPop
public void TestPop()
{
var dynamicStack = new DynamicStack<int>();
var list = new List<object>();
for (int i = 0; i < 1000; i++)
{
dynamicStack.Push(i);
list.Add(i);
}
for (int i = 0; i < 50; i++)
{
dynamicStack.Pop();
}
list.RemoveRange(950, 50);
list.Reverse();
var expected = list.ToArray();
var actual = dynamicStack.ToArray();
CollectionAssert.AreEqual(expected, actual);
}
示例7: testBunchOfInsertionsAndDeletions
public void testBunchOfInsertionsAndDeletions()
{
var list = new List<double> { 74, 101, 11, 1000, 4, -101, -1000 };
var maxHeap = new MaxHeap();
list.ForEach(elem => maxHeap.Add(elem));
list.Sort();
list.Reverse();
var maxes = new List<double>();
for (int i = 0; i < list.Count; i++)
{
maxes.Add(maxHeap.removeMax());
}
List<Tuple<double, double>> expectedVsActual = list.Zip(maxes, Tuple.Create).ToList();
foreach(var tuple in expectedVsActual)
{
Assert.AreEqual(tuple.Item1, tuple.Item2);
}
}
示例8: TestForwardBackward
public void TestForwardBackward()
{
var assembly = Assembly.GetAssembly(typeof (BookmarkEnumeratorTest));
var stream = assembly.GetManifestResourceStream(
typeof (BookmarkEnumeratorTest).Namespace + ".BookmarkEnumeratorTest.sky");
Assert.IsNotNull(stream);
var document = (SrmDocument) new XmlSerializer(typeof (SrmDocument)).Deserialize(stream);
Assert.IsNotNull(document);
var forwardEnumerator = new BookmarkEnumerator(document);
var backwardEnumerator = new BookmarkEnumerator(forwardEnumerator) {Forward = false};
var forwardList = new List<Bookmark>(forwardEnumerator);
var backwardList = new List<Bookmark>(backwardEnumerator);
Assert.AreNotEqual(0, forwardList.Count);
Assert.AreEqual(forwardList.Count, backwardList.Count);
// The very last location is the same for both the forwards and backwards enumerators.
backwardList.Reverse(0, backwardList.Count - 1);
CollectionAssert.AreEqual(forwardList, backwardList);
var forwardSet = new HashSet<Bookmark>(forwardList);
Assert.AreEqual(forwardList.Count, forwardSet.Count);
forwardSet.UnionWith(backwardList);
Assert.AreEqual(forwardList.Count, forwardSet.Count);
}
示例9: TestTemp
public void TestTemp()
{
using (HarperACL.ACLDataDataContext context = new HarperACL.ACLDataDataContext(ConfigurationManager.ConnectionStrings["AHT_MainConnectionString"].ConnectionString))
{
//var lastcustomer = (from a in context.Customers
// select new { cusnum = long.Parse(a.cusCustNum) })
// .OrderByDescending(x => x.cusnum)
// .ToList();
for (int i = 0; i < 20; i++)
{
DateTime end1 = new DateTime();
DateTime end2 = new DateTime();
DateTime start1 = new DateTime();
DateTime start2 = new DateTime();
start1 = DateTime.Now;
var lastcustomer1 = (from a in context.Customers
select new { cusnum = Convert.ToInt64(a.cusCustNum) })
.OrderByDescending(x => x.cusnum)
.Take(1).Single();
long newcustnum = lastcustomer1.cusnum + 1;
end1 = DateTime.Now;
start2 = DateTime.Now;
newcustnum = 0;
List<string> lastcustomer = (from a in context.Customers
select a.cusCustNum).ToList();
List<long> cusnumbs = new List<long>();
foreach (string cus in lastcustomer)
{
cusnumbs.Add(long.Parse(cus));
}
cusnumbs.Sort();
cusnumbs.Reverse();
newcustnum = cusnumbs[0];
newcustnum++;
end2 = DateTime.Now;
TimeSpan method1 = end1 - start1;
TimeSpan method2 = end2 - start2;
System.Diagnostics.Debug.WriteLine(string.Format("Old {0}: vs New: {1}", new object[] { method2.TotalMilliseconds, method1.TotalMilliseconds }));
}
}
}
示例10: OneRefactorTest
private void OneRefactorTest(string newName, string caretText, FileInput[] inputs, Version version, bool preview, string error, ExpectedPreviewItem[] expected = null) {
Console.WriteLine("Replacing {0} with {1}", caretText, newName);
version = version ?? new Version(2, 7);
for (int loops = 0; loops < 2; loops++) {
var views = new List<PythonEditor>();
try {
var mainView = new PythonEditor(inputs[0].Input, version.ToLanguageVersion(), _vs, filename: inputs[0].Filename);
var analyzer = mainView.Analyzer;
views.Add(mainView);
var bufferTable = new Dictionary<string, ITextBuffer> {
{ inputs[0].Filename, mainView.CurrentSnapshot.TextBuffer }
};
foreach (var i in inputs.Skip(1)) {
var editor = new PythonEditor(i.Input, version.ToLanguageVersion(), _vs, mainView.Factory, analyzer, i.Filename);
views.Add(editor);
bufferTable[i.Filename] = editor.CurrentSnapshot.TextBuffer;
}
// test runs twice, one w/ original buffer, once w/ re-analyzed buffers.
if (loops == 1) {
// do it again w/ a changed buffer
mainView.Text = mainView.Text;
}
var caretPos = inputs[0].Input.IndexOf(caretText);
mainView.View.MoveCaret(new SnapshotPoint(mainView.CurrentSnapshot, caretPos));
var extractInput = new RenameVariableTestInput(newName, bufferTable, preview);
var previewChangesService = new TestPreviewChanges(expected);
new VariableRenamer(views[0].View.View, _vs.ServiceProvider).RenameVariable(extractInput, previewChangesService);
if (error != null) {
Assert.AreEqual(error, extractInput.Failure);
return;
}
Assert.IsNull(extractInput.Failure, "Unexpected error message: " + (extractInput.Failure ?? ""));
Assert.AreEqual(preview, previewChangesService.Previewed, preview ? "Changes were not previewed" : "Changes were previewed");
AssertUtil.ArrayEquals(inputs.Select(i => i.Output).ToList(), views.Select(v => v.Text).ToList());
} finally {
views.Reverse();
foreach (var v in views) {
v.Dispose();
}
}
}
}
示例11: ExpressionSetTestImmediateSolveReverseInput
public void ExpressionSetTestImmediateSolveReverseInput()
{
var tests = new List<Tuple<string, string, double>>
{
new Tuple<string, string, double>("a", "2", 2),
new Tuple<string, string, double>("b", "{a}-1", 1),
new Tuple<string, string, double>("c","{a}+{b}", 3),
new Tuple<string, string, double>("d","{a}*{c}", 6),
new Tuple<string, string, double>("e","{d}-{b}", 5),
new Tuple<string, string, double>("f","{e}+4*{b}", 9),
new Tuple<string, string, double>("g","{f}/{c}+1", 4),
new Tuple<string, string, double>("all","({f}/{c}-{g}+{b})*({a}+{f})+{d}*{e}", 30)
};
tests.Reverse();
var set = new AlgexSet();
set.ImmediateSolve = true;
foreach (var test in tests)
{
set.Add(test.Item1, test.Item2);
}
foreach (var test in tests)
{
Assert.AreEqual(test.Item3, set[test.Item1]);
}
}
示例12: NodesSortingSparqlOrder
public void NodesSortingSparqlOrder()
{
SparqlOrderingComparer comparer = new SparqlOrderingComparer();
//Stream for Output
Console.WriteLine("## Sorting Test");
Console.WriteLine("NULLs < Blank Nodes < URI Nodes < Untyped Literals < Typed Literals");
Console.WriteLine();
//Create a Graph
Graph g = new Graph();
g.BaseUri = new Uri("http://example.org/");
g.NamespaceMap.AddNamespace("", new Uri("http://example.org/"));
//Create a list of various Nodes
List<INode> nodes = new List<INode>();
nodes.Add(g.CreateUriNode(":someUri"));
nodes.Add(g.CreateBlankNode());
nodes.Add(null);
nodes.Add(g.CreateBlankNode());
nodes.Add(g.CreateLiteralNode("cheese"));
nodes.Add(g.CreateLiteralNode("aardvark"));
nodes.Add(g.CreateLiteralNode(DateTime.Now.AddDays(-25).ToString(XmlSpecsHelper.XmlSchemaDateTimeFormat), new Uri(XmlSpecsHelper.XmlSchemaDataTypeDateTime)));
nodes.Add(g.CreateLiteralNode("duck"));
nodes.Add(g.CreateUriNode(":otherUri"));
nodes.Add(g.CreateLiteralNode("1.5", new Uri(XmlSpecsHelper.XmlSchemaDataTypeDouble)));
nodes.Add(g.CreateUriNode(new Uri("http://www.google.com")));
nodes.Add(g.CreateLiteralNode(DateTime.Now.AddYears(3).ToString(XmlSpecsHelper.XmlSchemaDateTimeFormat), new Uri(XmlSpecsHelper.XmlSchemaDataTypeDateTime)));
nodes.Add(g.CreateLiteralNode("23", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger)));
nodes.Add(g.CreateLiteralNode("M43d", new Uri(XmlSpecsHelper.XmlSchemaDataTypeBase64Binary)));
nodes.Add(g.CreateUriNode(new Uri("http://www.dotnetrdf.org")));
nodes.Add(g.CreateLiteralNode("12", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger)));
nodes.Add(g.CreateBlankNode("monkey"));
nodes.Add(g.CreateBlankNode());
nodes.Add(g.CreateLiteralNode("chaese"));
nodes.Add(g.CreateLiteralNode("1.0456345", new Uri(XmlSpecsHelper.XmlSchemaDataTypeDouble)));
nodes.Add(g.CreateLiteralNode("cheese"));
nodes.Add(g.CreateLiteralNode(Convert.ToBase64String(new byte[] { Byte.Parse("32") }), new Uri(XmlSpecsHelper.XmlSchemaDataTypeBase64Binary)));
nodes.Add(g.CreateLiteralNode("TA==", new Uri(XmlSpecsHelper.XmlSchemaDataTypeBase64Binary)));
nodes.Add(g.CreateLiteralNode("-45454", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger)));
nodes.Add(g.CreateLiteralNode(DateTime.Now.ToString(XmlSpecsHelper.XmlSchemaDateTimeFormat), new Uri(XmlSpecsHelper.XmlSchemaDataTypeDateTime)));
nodes.Add(g.CreateLiteralNode("-3", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger)));
nodes.Add(g.CreateLiteralNode("242344.3456435", new Uri(XmlSpecsHelper.XmlSchemaDataTypeDouble)));
nodes.Add(g.CreateLiteralNode("true", new Uri(XmlSpecsHelper.XmlSchemaDataTypeBoolean)));
nodes.Add(g.CreateUriNode(":what"));
nodes.Add(null);
nodes.Add(g.CreateLiteralNode("false", new Uri(XmlSpecsHelper.XmlSchemaDataTypeBoolean)));
nodes.Add(g.CreateLiteralNode("invalid-value", new Uri(XmlSpecsHelper.XmlSchemaDataTypeInteger)));
nodes.Sort(comparer);
//Output the Results
foreach (INode n in nodes)
{
if (n == null)
{
Console.WriteLine("NULL");
}
else
{
Console.WriteLine(n.ToString());
}
}
Console.WriteLine();
Console.WriteLine("Now in reverse...");
Console.WriteLine();
nodes.Reverse();
//Output the Results
foreach (INode n in nodes)
{
if (n == null)
{
Console.WriteLine("NULL");
}
else
{
Console.WriteLine(n.ToString());
}
}
}
示例13: Comments_Are_Ordered_By_Date_Descending
public void Comments_Are_Ordered_By_Date_Descending()
{
Initialize(true);
using (var repository = new NHibernateBlogService())
{
var comments = new List<Comment>();
for (int i = 0; i < 10; i++)
{
var comment = new Comment() { Name = "test", Content = "Test" };
comments.Add(comment);
Thread.Sleep(1);
}
comments.Reverse();
comments.ForEach(x => repository.Save(x));
Assert.IsTrue(comments.First().DateCreated > comments.Last().DateCreated);
}
using (var repository = new NHibernateBlogService())
{
var loadedComments = repository.GetComments();
Assert.IsFalse(loadedComments.First().DateCreated > loadedComments.Last().DateCreated);
}
}
示例14: TestReverseCopy_NullDestination_Throws
public void TestReverseCopy_NullDestination_Throws()
{
IReadOnlySublist<List<int>, int> list = new List<int>().ToSublist();
IExpandableSublist<List<int>, int> destination = null;
list.Reverse().CopyTo(destination);
}
示例15: Reverse
public void Reverse()
{
// arrange
List<int> list = new List<int>() { 1, 2, 3 };
// act
list.Reverse();
var actual = list;
// assert
Assert.AreEqual(3, actual[0]);
Assert.AreEqual(2, actual[1]);
Assert.AreEqual(1, actual[2]);
}