I would like to evaluate a data series and output the respective previous value. For this I use the following code:
private int PrevInt(int CurrentInt)
{
PrevIntList.Add(CurrentInt);
for (int i = 0; i < PrevIntList.Count; i++) { if (i >= 1) prevIntListValue = PrevIntList[i - 1]; }
return prevIntListValue;
}
To run a test with Xunit, I need a data series as source (e.g. 1,2,3,4,5) and the call to my method, which determines the respective predecessor value and confirms it as correct. How can I create such a test correctly.
Thanks a lot for the support!
Please see my comment about your
forloop, you don't need it at all, you can compute the correct index of the previous element directly.The "arrange, act, assert" paradigm will work just fine for this case, except that the "act" part occurs during the arranging. You can make a
Theoryand provide the sequence of integers in an array. In the "arrange" part, you make a new instance of your class and set up the list by calling the method, in the act part you then test a specific value against the expected one.Assuming PrevIntList is a member of you class, it could look like this
Don't forget to credit Stack Overflow for helping when you submit your homework assignment.