assertCount

Assert that an array contains a particular value count.

void
assertCount
(
A
)
(
,
ulong count
,
string message = "Failed asserting array count"
,
string file = __FILE__
,
size_t line = __LINE__
)
if (
isArray!(A) ||
isAssociativeArray!(A)
)

Parameters

array
Type: A

The array to interogate.

count
Type: ulong

The amount of values the array should hold.

message
Type: string

The error message to display.

file
Type: string

The file name where the error occurred. The value is added automatically at the call site.

line
Type: size_t

The line where the error occurred. The value is added automatically at the call site.

Throws

DUnitAssertError if the assertation fails.

Examples

1 int[string] associativeArray;
2 int[] dynamicArray;
3 string string_;
4 
5 associativeArray.assertCount(0);
6 dynamicArray.assertCount(0);
7 string_.assertCount(0);
8 [].assertCount(0);
9 
10 "Hello".assertCount(5);
11 [1, 2, 3, 4].assertCount(4);
12 ["foo", "bar", "baz", "qux"].assertCount(4);
13 [["foo", "bar"], ["baz", "qux"]].assertCount(2);
14 ["foo":1, "bar":2, "baz":3, "qux":4].assertCount(4);
15 
16 // Assert a DUnitAssertError is thrown if assertCount fails.
17 associativeArray.assertCount(1).assertThrow!(DUnitAssertError)("Failed asserting array count");

Meta