Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if a sequence of values is correctly ordered?

I have many Action objects with a property long Timestamp. I want to do something like this:

Assert.IsTrue(a1.Timestamp < a2.Timestamp < a3.Timestamp < ... < an.Timestamp);

Unfortunately, this syntax is illegal. Is there a built-in way or a extension\LINQ\whatever way to perform this?

Note that it's target for a unit test class, so get crazy. I don't care about performance, readability and etc.

like image 361
HuBeZa Avatar asked Dec 17 '22 17:12

HuBeZa


1 Answers

private static bool isValid(params Action[] actions)
{
  for (int i = 1; i < actions.Length; i++)
    if (actions[i-1].TimeStamp >= actions[i].TimeStamp)
      return false;
  return true;
}

Assert.IsTrue(isValid(a1,a2,...,an));
like image 108
Itay Karo Avatar answered Dec 19 '22 06:12

Itay Karo