eq

check equals a and b

bool
eq
(
A
B
)
(
A a
,
B b
)

Examples

1 assert(  eq( 1, 1.0 ) );
2 assert(  eq( [1,2,3], [1.0,2,3] ) );
3 assert(  eq( [1.0f,2,3], [1.0,2,3] ) );
4 assert(  eq( [1,2,3], iota(1,4) ) );
5 assert( !eq( [1.0000001,2,3], [1,2,3] ) );
6 assert(  eq( [[1,2],[3,4]], [[1.0f,2],[3.0f,4]] ) );
7 assert( !eq( [[1,2],[3,4]], [[1.1f,2],[3.0f,4]] ) );
8 assert( !eq( [[1,2],[3,4]], [[1.0f,2],[3.0f]] ) );
1 // string from Jonathan M Davis presentation
2 auto s1 = `さいごの果実 / ミツバチと科学者`;
3 auto s2 = `さいごの果実 / ミツバチと科学者`w;
4 
5 assert( s1.length != s2.length );
6 assert( !eq( cast(void[])s1, cast(void[])s2 ) );
7 assert( eq( s1, s2 ) );
8 
9 auto s1a = `さいごの果実`;
10 auto s1b = `ミツバチと科学者`;
11 
12 auto s2a = `さいごの果実`w;
13 auto s2b = `ミツバチと科学者`w;
14 
15 assert( eq( [s1a,s1b], [s2a,s2b] ) );
16 
17 assert( !eq( "hello", [1,2,3] ) );
18 assert( eq( " "w, [ 32 ] ) );
19 static assert( !__traits(compiles, eq(["hello"],1)) );
20 static assert( !__traits(compiles, eq(["hello"],[1,2,3])) );

Meta