Unit tests via DUB

Alexander Zhirov alexander at zhirov.website
Sat Apr 2 13:31:47 UTC 2022


On Saturday, 2 April 2022 at 13:12:04 UTC, Salih Dincer wrote:
> On Saturday, 2 April 2022 at 11:53:12 UTC, alexanderzhirov 
> wrote:
>> I don't quite understand why compiling unit tests using DUB 
>> doesn't work.
>
> Source code?

A common example from a textbook

```d
import std.array;

bool binarySearch(T)(T[] input, T value)
{
     while (!input.empty)
     {
         auto i = input.length / 2;
         auto mid = input[i];
         if (mid > value)
             input = input[0 .. i];
         else if (mid < value)
             input = input[i + 1 .. $];
         else
             return true;
     }
     return false;
}

unittest
{
     assert(binarySearch([1, 3, 6, 7, 9, 15], 7));
     assert(!binarySearch([1, 3, 6, 7, 9, 15], 5));
}
```


More information about the Digitalmars-d-learn mailing list