Answer the question
In order to leave comments, you need to log in
C# giving wrong expected number from list?
Good day.
There was a problem in the class code that uses the list.
I need to test it with nunit. Below is the class code and a test for it.
The problem is described at the very bottom.
Class code:
public class MyClass01
{
public MyClass01(string _name, int _kol)
{
name = _name;
kol = _kol;
}
public string name;
public int kol;
}
public class cAAA
{
List<MyClass01> my = new List<MyClass01>();
public cAAA()
{
my.Add(new MyClass01("one", 1));
my.Add(new MyClass01("two", 2));
my.Add(new MyClass01("three", 3));
}
public List<MyClass01> Read(string _name)
{
List<MyClass01> x = new List<MyClass01>();
foreach (var item in my)
{
if (item.name == _name)
{
x.Add(item);
}
}
return x;
}
}
[Test()]
public void Test1()
{
var instance = new ArrayUtils.cAAA();
List<ArrayUtils.MyClass01> actualList = instance.Read("three");
// проверить, что элемент 3
Assert.AreEqual(3, actualList.Count);
int actual = actualList.Single().kol; // извлечь элемент
}
Answer the question
In order to leave comments, you need to log in
You are comparing the number of elements in the list and 3. You have all the elements under one instance. What do you think is the bug?
PS And for naming it is necessary to force coding while sitting on a stool. And with a mouse on a ball without scrolling.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question