Skip to content

Commit

Permalink
test22: Fix real/creal tests.
Browse files Browse the repository at this point in the history
The old code also compared the padding bytes, which are not guaranteed
to be set to any particular value.
  • Loading branch information
dnadlinger committed Sep 29, 2012
1 parent 9af1fac commit 488b158
Showing 1 changed file with 37 additions and 59 deletions.
96 changes: 37 additions & 59 deletions test/runnable/test22.d
Expand Up @@ -230,68 +230,61 @@ void test11()

/*************************************/

void test12()
void assertEqual(real* a, real* b, string file = __FILE__, size_t line = __LINE__)
{
creal a = creal.nan;
creal b;
ubyte* X = cast(ubyte*)(cast(void*)&a);

b = real.nan + ireal.nan;
ubyte* Y = cast(ubyte*)(cast(void*)&b);
auto x = cast(ubyte*)a;
auto y = cast(ubyte*)b;

for(int i=0; i<a.sizeof; i++)
// Only compare the 10 value bytes, the padding bytes are of undefined
// value.
version (X86) enum count = 10;
else version (X86_64) enum count = 10;
else enum count = real.sizeof;
for (size_t i = 0; i < count; i++)
{
printf("%d: %02x %02x\n", i, X[i], Y[i]);
assert(X[i] == Y[i]);
if (x[i] != y[i])
{
printf("%02d: %02x %02x\n", i, x[i], y[i]);
import core.exception;
throw new AssertError(file, line);
}
}
}

void assertEqual(creal* a, creal* b, string file = __FILE__, size_t line = __LINE__)
{
assertEqual(cast(real*)a, cast(real*)b, file, line);
assertEqual(cast(real*)a + 1, cast(real*)b + 1, file, line);
}

void test12()
{
creal a = creal.nan;
creal b = real.nan + ireal.nan;
assertEqual(&a, &b);

real c= real.nan;
real d=a.re;
X = cast(ubyte*)(cast(void*)&c);
Y = cast(ubyte*)(cast(void*)&d);

for(int i=0; i<c.sizeof; i++){
assert(X[i]==Y[i]);
}
assertEqual(&c, &d);

d=a.im;
X = cast(ubyte*)(cast(void*)&c);
Y = cast(ubyte*)(cast(void*)&d);
for(int i=0; i<c.sizeof; i++){
assert(X[i]==Y[i]);
}
assertEqual(&c, &d);
}

/*************************************/

void test13()
{
creal a = creal.infinity;
creal b;
byte* X = cast(byte*)(cast(void*)&a);

b = real.infinity + ireal.infinity;
byte* Y = cast(byte*)(cast(void*)&b);

for(int i=0; i<a.sizeof; i++){
assert(X[i]==Y[i]);
}
creal b = real.infinity + ireal.infinity;
assertEqual(&a, &b);

real c = real.infinity;
real d=a.re;
X = cast(byte*)(cast(void*)&c);
Y = cast(byte*)(cast(void*)&d);

for(int i=0; i<c.sizeof; i++){
assert(X[i]==Y[i]);
}
assertEqual(&c, &d);

d=a.im;
X = cast(byte*)(cast(void*)&c);
Y = cast(byte*)(cast(void*)&d);
for(int i=0; i<c.sizeof; i++){
assert(X[i]==Y[i]);
}
assertEqual(&c, &d);
}

/*************************************/
Expand All @@ -300,30 +293,15 @@ void test14()
{
creal a = creal.nan;
creal b = creal.nan;
byte* X = cast(byte*)(cast(void*)&a);

b = real.nan + ireal.nan;
byte* Y = cast(byte*)(cast(void*)&b);

for(int i=0; i<a.sizeof; i++){
assert(X[i]==Y[i]);
}
assertEqual(&a, &b);

real c = real.nan;
real d=a.re;
X = cast(byte*)(cast(void*)&c);
Y = cast(byte*)(cast(void*)&d);

for(int i=0; i<c.sizeof; i++){
assert(X[i]==Y[i]);
}
assertEqual(&c, &d);

d=a.im;
X = cast(byte*)(cast(void*)&c);
Y = cast(byte*)(cast(void*)&d);
for(int i=0; i<c.sizeof; i++){
assert(X[i]==Y[i]);
}
assertEqual(&c, &d);
}

/*************************************/
Expand Down

0 comments on commit 488b158

Please sign in to comment.