本文整理汇总了C#中List.SequenceEqual方法的典型用法代码示例。如果您正苦于以下问题:C# List.SequenceEqual方法的具体用法?C# List.SequenceEqual怎么用?C# List.SequenceEqual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.SequenceEqual方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SmokeTest
public void SmokeTest()
{
var adam = new Employee { Name = "Adam", Age = 50, Salary = 125 };
var alice = new Employee { Name = "Alice", Age = 25, Salary = 100 };
var bob = new Employee { Name = "Bob", Age = 30, Salary = 75 };
var carol = new Employee { Name = "Carol", Age = 35, Salary = 100 };
var xavier = new Employee { Name = "Xavier", Age = 35, Salary = 100 };
var employees = new List<Employee> { adam, alice, bob, carol, xavier };
employees.Sort(OrderedComparer<Employee>.OrderBy(x => x.Name));
Assert.True(employees.SequenceEqual(new[] { adam, alice, bob, carol, xavier }));
employees.Sort(OrderedComparer<Employee>
.OrderByDescending(x => x.Age)
.ThenBy(x => x.Name)
);
Assert.True(employees.SequenceEqual(new[] { adam, carol, xavier, bob, alice }));
employees.Sort(OrderedComparer<Employee>
.OrderByDescending(x => x.Salary)
.ThenBy(x => x.Name, StringComparer.OrdinalIgnoreCase)
);
Assert.True(employees.SequenceEqual(new[] { adam, alice, carol, xavier, bob }));
employees.Sort(OrderedComparer<Employee>
.OrderByDescending(x => x.Age)
.ThenByDescending(x => x.Salary)
.ThenBy(x => x.Name)
);
Assert.True(employees.SequenceEqual(new[] { adam, carol, xavier, bob, alice }));
}
示例2: Run
/// <summary>
/// Runs the specified test specification.
/// </summary>
/// <param name="specification">The test specification to run.</param>
/// <returns>
/// The result of running the test specification.
/// </returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="specification"/> is <c>null</c>.</exception>
public EventCentricAggregateFactoryTestResult Run(EventCentricAggregateFactoryTestSpecification specification)
{
if (specification == null) throw new ArgumentNullException("specification");
var sut = specification.SutFactory();
sut.Initialize(specification.Givens);
IAggregateRootEntity factoryResult = null;
var result = Catch.Exception(() => factoryResult = specification.When(sut));
if (result.HasValue)
{
return specification.Fail(result.Value);
}
#if NET20
var actualEvents = new List<object>(factoryResult.GetChanges()).ToArray();
if (!actualEvents.SequenceEqual(specification.Thens, new WrappedEventComparerEqualityComparer(_comparer)))
{
return specification.Fail(actualEvents);
}
#else
var actualEvents = factoryResult.GetChanges().ToArray();
if (!actualEvents.SequenceEqual(specification.Thens, new WrappedEventComparerEqualityComparer(_comparer)))
{
return specification.Fail(actualEvents);
}
#endif
return specification.Pass();
}
示例3: ChainOntoRegularIComparables
public void ChainOntoRegularIComparables()
{
var items = new List<string> { "aaa", "AAA", "abb", "aaaa" };
var comparer = StringComparer.OrdinalIgnoreCase;
items.Sort(comparer);
Assert.True(items.SequenceEqual(new[] { "AAA", "aaa", "aaaa", "abb" }, StringComparer.OrdinalIgnoreCase));
items.Sort(comparer.ThenByDescending(x => x, StringComparer.Ordinal));
Assert.True(items.SequenceEqual(new[] { "aaa", "AAA", "aaaa", "abb" }, StringComparer.Ordinal));
}
示例4: FindLoop
static int[] FindLoop(int[] line)
{
for (int i = 0; i < line.Length; i++)
{
int nextOccurrence = Array.IndexOf(line, line[i], i + 1);
if (nextOccurrence != -1)
{
List<int> testRange = new List<int>(),
compareRange = new List<int>();
for (int j = i; j < nextOccurrence; j++)
testRange.Add(line[j]);
for (int j = 0; j < testRange.Count; j++)
{
if (j >= line.Length)
{
compareRange.Clear();
break;
}
compareRange.Add(line[j + nextOccurrence]);
}
if (testRange.SequenceEqual(compareRange))
return testRange.ToArray();
}
}
return new int[0];
}
示例5: DoTestDescending
public static void DoTestDescending()
{
List<int> numbers = new List<int> { 23, 42, 4, 16, 8, 15, 3, 9, 55, 0, 34, 12, 2, 46, 25 };
numbers.CombSortDescending(Comparer<int>.Default);
Debug.Assert(numbers.SequenceEqual(numbers.OrderByDescending(i => i)), "Wrong CombSort descending");
}
示例6: BibTeXCheck
bool BibTeXCheck(){
if(!aux.ContainsKey(".aux") || aux[".aux"] == null) return false;
var bibcite = new System.Text.RegularExpressions.Regex("\\\\bibcite\\{(.*?)\\}");
var citation = new System.Text.RegularExpressions.Regex("\\\\citation\\{(.*?)\\}");
var bibs = new List<string>();
var cits = new List<string>();
bool existbibdata = false;
Encoding[] encs = KanjiEncoding.GuessKajiEncoding(aux[".aux"]);
Encoding enc;
if(encs.Length == 0) enc = Encoding.GetEncoding("shift_jis");
else enc = encs[0];
using(var fs = new StringReader(enc.GetString(aux[".aux"]))) {
while(true) {
string line = fs.ReadLine();
if(line == null) break;
if(!existbibdata && line.IndexOf("\\bibdata{") != -1) existbibdata = true;
var m = bibcite.Match(line);
if(m.Success) bibs.Add(m.Groups[1].Value);
m = citation.Match(line);
if(m.Success) cits.Add(m.Groups[1].Value);
}
}
if(!existbibdata)return false;
cits.Sort(); cits = new List<string>(cits.Distinct());
bibs.Sort(); bibs = new List<string>(bibs.Distinct());
return !(cits.SequenceEqual(bibs));
}
示例7: ConcurrentSubscribers
/// <summary>
/// Tests the ReplaySubject with concurrent subscribers.
/// </summary>
public static void ConcurrentSubscribers()
{
var N = int.MaxValue;
var M = int.MaxValue;
var r = new ReplaySubject<int>(4);
var rnd = new Random();
var ts = new List<Task>();
for (var i = 0; i < 16; i++)
{
var rnd2 = new Random(rnd.Next());
ts.Add(Task.Factory.StartNew(async () =>
{
var n = rnd2.Next(10, 1000);
for (var j = 0; j < M; j++)
{
var xs = new List<int>();
await r.Take(n).Scan((x1, x2) =>
{
if (x2 - x1 != 1)
Debugger.Break();
if (x2 == 0)
Debugger.Break();
return x2;
}).ForEachAsync(xs.Add);
var f = xs.First();
if (!xs.SequenceEqual(Enumerable.Range(f, xs.Count)))
{
Console.WriteLine("FAIL!");
Debugger.Break();
}
else
{
Console.Write(".");
}
if (j % 1000 == 0)
{
await Task.Delay(50);
}
}
}));
}
for (var i = 0; i < N; i++)
{
r.OnNext(i);
}
Console.WriteLine("Done!");
Task.WaitAll(ts.ToArray());
}
示例8: Notifier_should_send_notifications_within_specified_time_span
public async Task Notifier_should_send_notifications_within_specified_time_span()
{
var minimumChecks = 3;
var expectedEventTimeline = new List<string>();
for (var i = 0; i < minimumChecks; ++i)
expectedEventTimeline.AddRange(new[] { "updateHealth_start", "delay_start", "update_finish", "update_finish" });
var countdown = new AsyncCountdown("notifications", minimumChecks);
var endpointId = Guid.NewGuid();
var interval = TimeSpan.FromMilliseconds(300);
SetupHealthCheckInterval(interval);
SetupEndpointRegistration(endpointId);
_mockClient
.Setup(c => c.SendHealthUpdateAsync(endpointId, AuthenticationToken, It.IsAny<HealthUpdate>(), It.IsAny<CancellationToken>()))
.Returns(() => _awaitableFactory.Return().WithDelay(TimeSpan.FromMilliseconds(100)).WithTimeline("updateHealth").WithCountdown(countdown).RunAsync());
_mockTimeCoordinator
.Setup(c => c.Delay(interval, It.IsAny<CancellationToken>()))
.Returns(() => _awaitableFactory.Return().WithDelay(TimeSpan.FromMilliseconds(50)).WithTimeline("delay").RunAsync());
using (CreateNotifier())
await countdown.WaitAsync(TestMaxTime);
var actualEventTimeline = _awaitableFactory.GetOrderedTimelineEvents()
.Select(eventName => (eventName == "updateHealth_finish" || eventName == "delay_finish") ? "update_finish" : eventName)
.Take(minimumChecks * 4)
.ToArray();
Assert.True(expectedEventTimeline.SequenceEqual(actualEventTimeline), $"Expected:\n{string.Join(",", expectedEventTimeline)}\nGot:\n{string.Join(",", actualEventTimeline)}");
}
示例9: TestCompleteSequence
static public bool TestCompleteSequence()
{
var ledRed = Light.Leds[Color.Red];
ledRed.RunSequence();
var ledYellow = Light.Leds[Color.Yellow];
ledYellow.RunSequence(false);
var ledGreen = Light.Leds[Color.Green];
ledGreen.RunSequence(false);
ledYellow.RunSequence(false);
ledRed.RunSequence(false);
var expectedSequence = new List<object>();
expectedSequence.Add(new Tuple<Color, string>(Color.Red, "High"));
expectedSequence.Add(new Tuple<Color, string>(Color.Red, "3000ms"));
expectedSequence.Add(new Tuple<Color, string>(Color.Red, "Low"));
expectedSequence.Add(new Tuple<Color, string>(Color.Yellow, "High"));
expectedSequence.Add(new Tuple<Color, string>(Color.Yellow, "3000ms"));
expectedSequence.Add(new Tuple<Color, string>(Color.Yellow, "Low"));
expectedSequence.Add(new Tuple<Color, string>(Color.Green, "High"));
expectedSequence.Add(new Tuple<Color, string>(Color.Green, "3000ms"));
expectedSequence.Add(new Tuple<Color, string>(Color.Green, "Low"));
expectedSequence.Add(new Tuple<Color, string>(Color.Yellow, "High"));
expectedSequence.Add(new Tuple<Color, string>(Color.Yellow, "3000ms"));
expectedSequence.Add(new Tuple<Color, string>(Color.Yellow, "Low"));
expectedSequence.Add(new Tuple<Color, string>(Color.Red, "High"));
expectedSequence.Add(new Tuple<Color, string>(Color.Red, "3000ms"));
expectedSequence.Add(new Tuple<Color, string>(Color.Red, "Low"));
return (expectedSequence.SequenceEqual(Light.Sequence));
}
示例10: DoTestAscending
public static void DoTestAscending()
{
List<int> numbers = new List<int> { 54, 26, 93, 17, 77, 31, 44, 55, 20 };
numbers.GnomeSortAscending(Comparer<int>.Default);
Debug.Assert(numbers.SequenceEqual(numbers.OrderBy(i => i)), "Wrong GnomeSort ascending");
}
示例11: DoTestDescending
public static void DoTestDescending()
{
List<int> numbers = new List<int> { 84, 69, 76, 86, 94, 91, 77, 31, 44, 55, 20 };
numbers.GnomeSortDescending(Comparer<int>.Default);
Debug.Assert(numbers.SequenceEqual(numbers.OrderByDescending(i => i)), "Wrong GnomeSort descending");
}
示例12: SOMAlgorithm
/// <summary>
/// Devuelve una Lista de Listas de Tuplas(Doule,Doule) que contiene el historial de configuraciones de los pesos.
/// El algoritmo tiene como condicion de Fin que se estabilicen los pesos, es decir que termina cuando la anteultima y ultima configuracion son iguales.
/// </summary>
/// <param name="Pesos">Lista de tuplas(double,double) que representa la configuracion de pesos iniciales.</param>
/// <param name="Patrones">Lista de tuplas(double,double) que representa los patrones de entrada.</param>
public List<List<Tuple<Double, Double>>> SOMAlgorithm(List<Tuple<Double, Double>> Pesos, List<Tuple<Double, Double>> Patrones)
{
this.HistorialActualizacion = new List<List<Tuple<Double, Double>>>();
this.HistorialDistancias = new List<List<Double>>();
var UltimaConfig = new List<Tuple<Double, Double>>();
var AnteUltimaConfig = new List<Tuple<Double, Double>>();
int i = 0;
//foreach (var Patron in Patrones)
do
{
var Patron = Patrones[i % 5];
var IxGanador = FuncionActivacion(Pesos, Patron);
Pesos = ActualizarPesos(Pesos, Patron, Patrones.IndexOf(Patron)+1, IxGanador);
HistorialActualizacion.Add(Pesos);//Se guardan las configuraciones de pesos parciales. La ultima será la final.
//Print pesos
////Console.WriteLine();
////Console.WriteLine("Nuevos Pesos:");
//Pesos.ForEach(delegate(Tuple<Double, Double> peso) { //Console.WriteLine(peso.Item1 + "; " + peso.Item2); });
//Console.WriteLine();
i++;
UltimaConfig = HistorialActualizacion.Last();
if (i>=2)
{
AnteUltimaConfig = HistorialActualizacion.ElementAt(HistorialActualizacion.IndexOf(UltimaConfig)-1) ;
}
} while (!UltimaConfig.SequenceEqual(AnteUltimaConfig));
return HistorialActualizacion;
}
示例13: CustomComparerTest
public void CustomComparerTest()
{
var items = new List<string> { "aaa", "AAA", "abb", "aaaa" };
items.Sort(OrderedComparer<string>.OrderBy(x => x, StringComparer.Ordinal));
Assert.True(items.SequenceEqual(new[] { "AAA", "aaa", "aaaa", "abb" }));
items.Sort(OrderedComparer<string>.OrderByDescending(x => x.Length).ThenBy(x => x, StringComparer.Ordinal));
Assert.True(items.SequenceEqual(new[] { "aaaa", "AAA", "aaa", "abb" }));
items.Sort(OrderedComparer<string>.OrderBy(x => x.Length).ThenBy(x => x, StringComparer.Ordinal));
Assert.True(items.SequenceEqual(new[] { "AAA", "aaa", "abb", "aaaa" }));
items.Sort(OrderedComparer<string>.OrderBy(x => x.Length).ThenBy(x => x, StringComparer.OrdinalIgnoreCase));
Assert.True(items.SequenceEqual(new[] { "AAA", "AAA", "abb", "aaaa" }, StringComparer.OrdinalIgnoreCase));
}
示例14: DifferentSchedulers
/// <summary>
/// Tests the Replay operator with different schedulers, supporting ISchedulerLongRunning and otherwise.
/// Stresses the ScheduledObserver implementation with its counting logic.
/// </summary>
public static void DifferentSchedulers()
{
while (true)
{
for (int i = 100; i <= 10000; i *= 10)
{
foreach (var s in new IScheduler[] { Scheduler.Default, TaskPoolScheduler.Default, ThreadPoolScheduler.Instance })
{
foreach (var b in new[] { true, false })
{
var t = b ? s : s.DisableOptimizations();
var e = new ManualResetEvent(false);
var xs = Observable.Range(0, i, TaskPoolScheduler.Default.DisableOptimizations()).Do(_ => { }, () => e.Set());
var ys = xs.Replay(t);
var f = new ManualResetEvent(false);
var r = new List<int>();
ys.Subscribe(r.Add, () => f.Set());
ys.Connect();
e.WaitOne();
f.WaitOne();
if (!r.SequenceEqual(Enumerable.Range(0, i)))
throw new Exception();
Console.Write(".");
}
}
}
}
}
示例15: DoTestDescending
public static void DoTestDescending()
{
List<int> numbers = new List<int> { 23, 42, 4, 16, 8, 15, 3, 9, 55, 0, 34, 12, 2, 46, 25 };
numbers.PigeonHoleSortDescending();
Debug.Assert(numbers.SequenceEqual(numbers.OrderByDescending(i => i)), "Wrong PigeonHole descending");
}