Unit tests via DUB

Salih Dincer salihdb at hotmail.com
Sat Apr 2 14:35:49 UTC 2022


On Saturday, 2 April 2022 at 13:31:47 UTC, Alexander Zhirov wrote:
> 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));
> }
> ```
is there main()? if isn't it, please add the following line at 
the end:
```d
void main() {}
```



More information about the Digitalmars-d-learn mailing list