本文整理汇总了C#中NUnit.Framework.List.Count方法的典型用法代码示例。如果您正苦于以下问题:C# List.Count方法的具体用法?C# List.Count怎么用?C# List.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NUnit.Framework.List
的用法示例。
在下文中一共展示了List.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Calculate_When1DiscountAppliesMoreThanOnceAndThereAreAdditionalDiscountableItems_ReturnsCorrectCost
public void Calculate_When1DiscountAppliesMoreThanOnceAndThereAreAdditionalDiscountableItems_ReturnsCorrectCost()
{
const decimal expected = 1m;
var products = new List<Product>
{
new Product {Id = 1, Name = "Butter", UnitPrice = 0.80m},
new Product {Id = 1, Name = "Butter", UnitPrice = 0.80m},
new Product {Id = 1, Name = "Butter", UnitPrice = 0.80m},
new Product {Id = 1, Name = "Butter", UnitPrice = 0.80m},
new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m},
new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m},
new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m},
new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m},
new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m},
new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m},
new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m},
new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m}
};
_discountOfferRepositoryMock.Setup(m => m.GetDiscountOffers()).Returns(new List<DiscountOffer>
{
new DiscountOffer { ProductBoughtId = 1, NumberToBuy = 2, ProductDiscountedId = 3, PercentageOff = 0.5m }
});
var actual = _discountOfferCalculatorService.Calculate(products);
Assert.That(actual, Is.EqualTo(expected));
Assert.That(products.Count(p => p.Name == "Bread" && p.Processed) == 2);
Assert.That(products.Count(p => p.Name == "Bread" && p.Processed == false) == 6);
Assert.That(products.Where(p => p.Name == "Butter").All(p => p.Processed == false));
}
示例2: FiltersDataOutsideRTHWhenSessionSpansMultipleDays
public void FiltersDataOutsideRTHWhenSessionSpansMultipleDays()
{
var sessions = new List<InstrumentSession>
{
new InstrumentSession
{
OpeningDay = DayOfTheWeek.Monday ,
ClosingDay = DayOfTheWeek.Tuesday,
OpeningTime = new TimeSpan(8, 0, 0),
ClosingTime = new TimeSpan(16, 0, 0),
IsSessionEnd = true
}
};
var data = GetDataBetween(new DateTime(2014, 1, 13, 0, 0, 0), new DateTime(2014, 1, 14, 23, 0, 0));
var unfilteredData = new List<OHLCBar>(data);
RTHFilter.Filter(data, sessions);
var startCutoff = new DateTime(2014, 1, 13, 8, 0, 0);
var endingCutoff = new DateTime(2014, 1, 14, 16, 0, 0);
Assert.AreEqual(0, data.Count(x => x.DT < startCutoff));
Assert.AreEqual(0, data.Count(x => x.DT > endingCutoff));
Assert.AreEqual(
unfilteredData.Count
- unfilteredData.Count(x => x.DT <= startCutoff)
- unfilteredData.Count(x => x.DT > endingCutoff),
data.Count);
}
示例3: TestRandomSelectLessThanNumberOfSelections
public void TestRandomSelectLessThanNumberOfSelections()
{
IEnumerable<object> enumerable = new List<object> { new object(), new object() };
Assert.AreEqual(enumerable, enumerable.RandomSelect(enumerable.Count() + 1));
IList<object> selectedItems = new List<object>();
enumerable.RandomSelect(enumerable.Count() + 1, selectedItems.Add);
Assert.IsTrue(CollectionUtils.SequenceEqual(enumerable, selectedItems));
}
示例4: RandomShufflerHandleNullAbleList
public void RandomShufflerHandleNullAbleList()
{
const int expectedNumOfNull = 3;
const int expectedNumOfOne = 1;
var list = new List<int?>() { null, null, 1, null};
ListRandomShuffler.InPlaceShuffle(list);
var numOfNull = list.Count(i => i == null);
var numOfOne = list.Count(i => i == 1);
Assert.AreEqual(numOfNull, expectedNumOfNull);
Assert.AreEqual(numOfOne, expectedNumOfOne);
}
示例5: RandomShufflerHandleNullAbleRefferenceTypeList
public void RandomShufflerHandleNullAbleRefferenceTypeList()
{
const int expectedNumOfNull = 3;
const int expectedNumOfStr = 1;
const string str = "This is not null";
var list = new List<string>() { null, null, str, null };
ListRandomShuffler.InPlaceShuffle(list);
var numOfNull = list.Count(i => i == null);
var numOfStr = list.Count(i => i == str);
Assert.AreEqual(numOfNull, expectedNumOfNull);
Assert.AreEqual(numOfStr, expectedNumOfStr);
}
示例6: InspectObject_With_CircularReference
public void InspectObject_With_CircularReference()
{
var parent = new ClassWithCircularReference_Parent();
parent.Child = new ClassWithCircularReference_Child();
parent.Child.Parent = parent;
var itensFounded = new List<object>();
_objectInspector.InspectObject(parent, value =>
{
itensFounded.Add(value);
});
Assert.AreEqual(1, itensFounded.Count(p => p.Equals(parent)), "Deveria ter achado o objeto parent apenas uma vez");
Assert.AreEqual(1, itensFounded.Count(p => p.Equals(parent.Child)), "Deveria ter achado o objeto parent.Child apenas uma vez");
}
示例7: Buffer_CursorTop_Test
public void Buffer_CursorTop_Test()
{
var process = new Process { StartInfo = { FileName = "cmd.exe" } };
process.Start();
AttachConsole(process.Id);
var buffer = JConsole.GetActiveScreenBuffer();
Assert.That(buffer.CursorTop, Is.EqualTo(3));
Assert.That(buffer.CursorLeft, Is.GreaterThan(0));
var events = new List<EventArgs>();
events.Add(new ConsoleKeyEventArgs { KeyDown = true, RepeatCount = 1, KeyChar = 'd' });
events.Add(new ConsoleKeyEventArgs { KeyDown = false, RepeatCount = 1, KeyChar = 'd' });
events.Add(new ConsoleKeyEventArgs { KeyDown = true, RepeatCount = 1, KeyChar = 'i' });
events.Add(new ConsoleKeyEventArgs { KeyDown = false, RepeatCount = 1, KeyChar = 'i' });
events.Add(new ConsoleKeyEventArgs { KeyDown = true, RepeatCount = 1, KeyChar = 'r' });
events.Add(new ConsoleKeyEventArgs { KeyDown = false, RepeatCount = 1, KeyChar = 'r' });
events.Add(new ConsoleKeyEventArgs { KeyDown = true, RepeatCount = 1, KeyChar = (char)13 });
events.Add(new ConsoleKeyEventArgs { KeyDown = false, RepeatCount = 1, KeyChar = (char)13 });
var inputBuffer = JConsole.GetInputBuffer();
inputBuffer.WindowInput = true;
inputBuffer.WriteEvents(events, events.Count());
buffer.WriteLine(buffer.OutputMode.ToString());
}
示例8: PrintEmailsGroupedByDomain
public void PrintEmailsGroupedByDomain()
{
List<string> emails = new List<string> { "[email protected]", "[email protected]", "[email protected]" };
Dictionary<string, List<string>> groups = new Dictionary<string, List<string>>();
for (int i = 0; i < emails.Count(); i++)
{
Match split = Regex.Matches(emails[i], @"[^@]*@(.*)")[0];
string domain = split.Groups[1].Value;
if (!groups.ContainsKey(domain))
{
groups.Add(domain, new List<string> { emails[i] });
}
else
{
groups[domain].Add(emails[i]);
}
}
foreach (var key in groups.Keys)
{
Console.WriteLine("Emails for domain: " + key);
for (int i = 0; i < groups[key].Count; i++)
{
Console.WriteLine(groups[key][i]);
}
Console.WriteLine();
}
}
示例9: Given_EmptyList_When_RandomX_ReturnEmptyList
public void Given_EmptyList_When_RandomX_ReturnEmptyList()
{
var l = new List<string>();
IEnumerable<string> rand = new List<string>();
Assert.DoesNotThrow(() => rand = l.GetRandomX(4));
Assert.AreEqual(0, rand.Count());
}
示例10: D_visit_complete_tree_depthFirst_on_VisitDescendants
public void D_visit_complete_tree_depthFirst_on_VisitDescendants()
{
// ACT
var result = new List<Tuple<List<string>, string>>();
"rootNode".VisitDescendants(this.GetChildNodes, (b, n) => result.Add(Tuple.Create(b.ToList(), n)), depthFirst: true);
// ASSERT
Assert.AreEqual(5, result.Count());
CollectionAssert.AreEqual(new[] {
"leftNode",
"leftLeaf",
"rightNode",
"leftRightLeaf",
"rightRightLeaf"
}, result.Select(i => i.Item2));
CollectionAssert.AreEqual(new[] { "leftNode", "leftLeaf", "rightNode", "leftRightLeaf", "rightRightLeaf" }, result.Select(i => i.Item2));
CollectionAssert.AreEqual(new[] { "rootNode" }, result.ElementAt(0).Item1);
CollectionAssert.AreEqual(new[] { "rootNode", "leftNode" }, result.ElementAt(1).Item1);
CollectionAssert.AreEqual(new[] { "rootNode" }, result.ElementAt(2).Item1);
CollectionAssert.AreEqual(new[] { "rootNode", "rightNode" }, result.ElementAt(3).Item1);
CollectionAssert.AreEqual(new[] { "rootNode", "rightNode" }, result.ElementAt(4).Item1);
}
示例11: TestBolsterAllies
public void TestBolsterAllies()
{
Start game = new Start();
game.beginGame();
Legacy legacy = new Legacy();
List<int> firstList = new List<int>();
foreach (Hero hero in GameEngine.getHeroes())
{
firstList.Add(hero.hand.Count());
}
Card bolster = new Card("Images\\Hero\\Legacy\\BolsterAllies.png");
legacy.BolsterAllies(bolster);
List<int> secondList = new List<int>();
foreach (Hero hero in GameEngine.getHeroes())
{
secondList.Add(hero.hand.Count());
}
for(int i = 0; i < secondList.Count(); i++)
{
Assert.AreEqual(secondList[i], firstList[i] + 1);
}
}
示例12: UsingWebRequest
public void UsingWebRequest()
{
var count = 0;
var requestUri = new Uri("http://google.com");
var sp = Stopwatch.StartNew();
var tasks = new List<Task>();
for (var i = 0; i < 10; i++)
{
var t = Task.Run(() =>
{
var webRequest = WebRequest.Create(requestUri);
webRequest.GetResponse().Close();
Interlocked.Increment(ref count);
});
tasks.Add(t);
}
var whenAll = Task.WhenAll(tasks);
while (whenAll.IsCompleted == false && whenAll.IsFaulted == false)
{
Thread.Sleep(1000);
Console.WriteLine("{0} - {1}, {2}", sp.Elapsed, count, tasks.Count(x=> x.IsCompleted == false));
}
Console.WriteLine(sp.Elapsed);
}
示例13: TestSmaSimple
public void TestSmaSimple()
{
int period = 5;
List<double> data = new List<double>(new double[]{
3,
3,
3,
3,
3
});
var result = TechnicalAnalisysMethods.SimpleMovingAverage(data);
int zeroCnt = result.Where(x => x == 0.0).Count();
int valueCnt = result.Length - zeroCnt;
Assert.That(result.Length == data.Count());
Assert.That(zeroCnt == 4);
double sma = result.Where(x => x != 0.0).First();
Assert.That(sma == 3.0);
}
示例14: PrintEmailsGroupedByDomain_ExtractLocalVariablesResharper
public void PrintEmailsGroupedByDomain_ExtractLocalVariablesResharper()
{
var emails = new List<string> { "[email protected]", "[email protected]", "[email protected]" };
var groups = new Dictionary<string, List<string>>();
for (var i = 0; i < emails.Count(); i++)
{
var email = emails[i];
var split = Regex.Matches(email, @"[^@]*@(.*)")[0];
var domain = split.Groups[1].Value;
if (!groups.ContainsKey(domain))
{
groups.Add(domain, new List<string> { email });
}
else
{
groups[domain].Add(email);
}
}
foreach (var key in groups.Keys)
{
Console.WriteLine("Emails for domain: " + key);
var emailsInDomain = groups[key];
for (var i = 0; i < emailsInDomain.Count; i++)
{
Console.WriteLine(emailsInDomain[i]);
}
Console.WriteLine();
}
}
示例15: AreEqual
public static void AreEqual(List<TimeScope> timescopes, List<TIM> tims)
{
for (var i = 0; i < timescopes.Count(); i++)
{
AreEqual(timescopes[i], tims[i]);
}
}