本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Sum方法的典型用法代码示例。如果您正苦于以下问题:C# List.Sum方法的具体用法?C# List.Sum怎么用?C# List.Sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Sum方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildRepoert
public void BuildRepoert()
{
var items = new List<SettlementDetails>
{
new SettlementDetails
{
Name = "A",
Amount = 1m,
},
new SettlementDetails
{
Name = "B",
Amount = 2m,
Amount1 = 2,
},
new SettlementDetails
{
Name = "C",
Amount = 3m,
Amount1 = 1,
}
};
var target = new DataTable<SettlementDetails>();
target.Column("Name", s => s.Name);
//計算列
IColumn colum4CalculateRow1 = target.Column("Amount0", s => s.Amount).Sum<decimal?>();
IColumn colum4CalculateRow2 = target.Column("Amount1", s => s.Amount1).Sum<decimal?>();
target.Sum<decimal?>("Amount+Amount1", colum4CalculateRow1, colum4CalculateRow2);
target.SetData(items);
var columns = new[] { "Name", "Amount0", "Amount1", "Amount+Amount1" };
int index = 0;
//check column Name;
foreach (IColumn column in target.Columns)
{
Assert.AreEqual(columns[index], column.Name);
index++;
}
//check the row item0;
index = 0;
foreach (var item in target.GetRows())
{
Assert.AreEqual(items[index].Name, item[0]);
Assert.AreEqual(items[index].Amount, item[1]);
Assert.AreEqual(items[index].Amount1, item[2]);
Assert.AreEqual((items[index].Amount ?? 0) + (items[index].Amount1 ?? 0), item[3], "row is " + index);
index++;
}
Assert.AreEqual(items.Sum(item => item.Amount), (colum4CalculateRow1).SumResult());
Assert.AreEqual(items.Sum(item => item.Amount1), (colum4CalculateRow2).SumResult());
}
示例2: TestSumIenumerable
public void TestSumIenumerable()
{
List<int> tl = new List<int>() { 1, 2, 3 };
int sum = tl.Sum<int>();
Console.WriteLine(sum);
Assert.AreEqual(6, sum, "Error in result of sum");
}
示例3: All
public void All()
{
var e1 = Emit<LotsOfParams>.NewDynamicMethod();
var args = new List<int>();
for (ushort i = 0; i < 260; i++)
{
e1.LoadConstant(i);
e1.StoreArgument(i);
args.Add(i);
}
for (ushort i = 0; i < 260; i++)
{
e1.LoadArgument(i);
}
for (var i = 0; i < 259; i++)
{
e1.Add();
}
e1.Return();
var d1 = e1.CreateDelegate();
var x = (int)d1.DynamicInvoke(args.Cast<object>().ToArray());
Assert.AreEqual(args.Sum(), x);
}
示例4: BestFitFunctions
public BestFitFunctions(int maxBoxSize, int slotSize, int numBoxes)
{
Boxes = new List<Box>();
Slots = new List<Slot>();
m_SlotSize = slotSize;
Random rand = new Random();
for (int i = 0; i < numBoxes; i++)
{
Boxes.Add(new Box() { Weight = rand.Next(maxBoxSize), Id = i });
}
double sumOfBoxes = Boxes.Sum(b => b.Weight);
double bestFit = 0;
for (int i = 1; i <= 10; i++)
{
double slots = (sumOfBoxes * i) / slotSize;
double fit = slots - Math.Floor(slots);
if (fit > bestFit)
{
SlotsCountExact = slots;
System.Diagnostics.Debug.WriteLine("Optimal fit sum " + slots);
bestFit = fit;
Repetitions = i;
m_NumSlots = (int)Math.Ceiling(slots);
}
}
m_SlotIndexBitSize = Convert.ToString(m_NumSlots - 1, 2).Length;
Slots = new List<Slot>();
for (int i = 0; i < m_NumSlots; i++)
Slots.Add(new Slot() { Size = m_SlotSize });
}
示例5: AllNonGeneric
public void AllNonGeneric()
{
var returnType = typeof(LotsOfParams).GetMethod("Invoke").ReturnType;
var paramTypes = typeof(LotsOfParams).GetMethod("Invoke").GetParameters().Select(p => p.ParameterType).ToArray();
var e1 = Emit.NewDynamicMethod(returnType, paramTypes);
var args = new List<int>();
for (ushort i = 0; i < 260; i++)
{
e1.LoadConstant(i);
e1.StoreArgument(i);
args.Add(i);
}
for (ushort i = 0; i < 260; i++)
{
e1.LoadArgument(i);
}
for (var i = 0; i < 259; i++)
{
e1.Add();
}
e1.Return();
var d1 = e1.CreateDelegate<LotsOfParams>();
var x = (int)d1.DynamicInvoke(args.Cast<object>().ToArray());
Assert.AreEqual(args.Sum(), x);
}
示例6: All
public void All()
{
var e1 = Emit<LotsOfParams>.NewDynamicMethod();
for (ushort i = 0; i < 260; i++)
{
e1.LoadArgumentAddress(i);
e1.LoadIndirect<int>();
}
for (var i = 0; i < 259; i++)
{
e1.Add();
}
e1.Return();
var d1 = e1.CreateDelegate();
var rand = new Random();
var args = new List<int>();
for (var i = 0; i < 260; i++)
{
args.Add(rand.Next(10));
}
var ret = (int)d1.DynamicInvoke(args.Cast<object>().ToArray());
Assert.AreEqual(args.Sum(), ret);
}
示例7: Performance_test_get_properties_for_type_without_cache
public void Performance_test_get_properties_for_type_without_cache()
{
// Arrange
// Pre-load all of the Domain Types so we can test against a Pool containing existing objects.
IEnumerable<Type> types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(assembly => assembly.GetTypes());
types.AsParallel().ForAll(type => PropertyCache.GetPropertiesForType(type));
var times = new List<double>();
const int _iterations = 1000;
// Act
for (int count = 0; count < _iterations; count++)
{
// Remove PayItem so we can test it not existing in the Pool.
TypeCache.ClearTypeFromPool<TypePoolFixture>();
// Act
var timer = new Stopwatch();
timer.Start();
IEnumerable<PropertyInfo> results =
PropertyCache.GetPropertiesForType<TypePoolFixture>();
timer.Stop();
times.Add(timer.Elapsed.TotalMilliseconds);
}
Debug.WriteLine($"The average time to fetch an uncached collection of properties over {_iterations} iterations was {times.Sum() / times.Count}ms");
}
示例8: OpdaterRostatistikTest
public void OpdaterRostatistikTest()
{
//NB: DENNE TEST SLETTER ALT DATA I BASEN
UnitTestHelper.InitierAlleKomponenterMedDefault();
UnitTestHelper.SletAlt();
Baad baad = UnitTestHelper.LavEnkeltBaad();
UnitTestHelper.IndsaetXNytMedlem(1, MedlemsstatusEnum.Aktiv);
Medlem medlem = UnitTestHelper.HentFoersteMedlem();
DateTime detteAar = DateTime.UtcNow.Subtract(new TimeSpan(1, 0, 0, 0));
DateTime sidsteAar = detteAar.Subtract(TimeSpan.FromDays(365));
List<int> turlaengderDetteAar = new List<int>();
List<int> turlaengderSidsteAar = new List<int>();
Random r = new Random();
for (int i = 0; i < 5; i++)
{
int turlaengde = r.Next(100);
turlaengderDetteAar.Add(turlaengde);
UnitTestHelper.OpretTurPaaBaadOgMedlem(medlem.ID, baad.ID, detteAar, turlaengde);
turlaengde = r.Next(100);
turlaengderSidsteAar.Add(turlaengde);
UnitTestHelper.OpretTurPaaBaadOgMedlem(medlem.ID, baad.ID, sidsteAar, turlaengde);
}
MedlemBO medlemBO = new MedlemBO(medlem);
medlemBO.OpdaterRostatistik();
Assert.AreEqual(medlem.Rostatistik.KilometerDetteAar, turlaengderDetteAar.Sum());
Assert.AreEqual(medlem.Rostatistik.KilometerSidsteAar, turlaengderSidsteAar.Sum());
}
示例9: TestSumAggregate
public void TestSumAggregate()
{
List<int?> l = new List<int?> { 0, 3, null, 4, 5 };
int? sum = l.Sum();
int? agg = l.Aggregate((int?)0, (s, x) => s + x);
Assert.IsFalse(sum == (int?)null);
Assert.IsTrue(agg == (int?)null);
}
示例10: Sum_Empty_DefaultMoney
public void Sum_Empty_DefaultMoney()
{
var source = new List<MoneyStub>();
var actual = source.Sum(s => s.Value);
Assert.AreEqual(0, actual.Amount);
Assert.AreEqual("BRL", actual.Currency);
}
示例11: GetDivisors
public void GetDivisors()
{
var divisors = new List<int>();
{
//220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110
divisors = Utils.GetDivisors(220).ToList();
Assert.AreEqual(divisors.Count, 11);
Assert.AreEqual(divisors.Sum(), 284);
}
{
//284 are 1, 2, 4, 71 and 142
divisors = Utils.GetDivisors(284).ToList();
Assert.AreEqual(divisors.Count, 5);
Assert.AreEqual(divisors.Sum(), 220);
}
}
示例12: EmptyCollectionTest
public void EmptyCollectionTest()
{
List<int> list = new List<int>();
try
{
list.Sum();
}
catch (ArgumentException e)
{
Assert.AreEqual(e.Message, string.Format("{0} is empty", list.GetType()));
}
}
示例13: Sum_Source_Money
public void Sum_Source_Money()
{
var source = new List<MoneyStub>()
{
new MoneyStub() { Value = Money.Reais(1) },
new MoneyStub() { Value = Money.Reais(2) },
new MoneyStub() { Value = Money.Reais(3) }
};
var actual = source.Sum(s => s.Value);
Assert.AreEqual(6, actual.Amount);
Assert.AreEqual("BRL", actual.Currency);
}
示例14: GetScore
private double GetScore(List<double> source, int clicknum)
{
var result = (double)0;
int count = source.Count;
if (clicknum > count)
{
var num = clicknum / count;
result += source.Sum() * num;
clicknum = clicknum % count;
}
for (int i = 0; i < clicknum; i++)
{
result += source[i];
}
return result;
}
示例15: BenchmarkAsync
public async Task BenchmarkAsync()
{
await WarmupAsync();
var measureResults = new List<TimeSpan>();
for (var interation = 0; interation < IterationCount; interation++)
{
var measureResult = await MeasureAsync(ActionAsync);
measureResults.Add(measureResult);
}
for (var i = 0; i < measureResults.Count; i++)
{
Console.WriteLine("#{0}: {1}", i, measureResults[i]);
}
var averageTicks = measureResults.Sum(timeSpan => timeSpan.Ticks)/measureResults.Count;
var average = TimeSpan.FromTicks(averageTicks);
Console.WriteLine("Average: {0}", average);
}