annotate tests/mini/typeinfo10.d @ 341:1bb99290e03a trunk

[svn r362] Started merging the old 'test' dir as well as the newer 'tangotests' dir into 'tests/mini' and 'tests/minicomplex'.
author lindquist
date Sun, 13 Jul 2008 02:51:19 +0200
parents test/typeinfo10.d@d7e764e62462
children 0a5f7890f327
rev   line source
lindquist@72 1 module typeinfo10;
lindquist@72 2
lindquist@72 3 struct S
lindquist@72 4 {
lindquist@72 5 long l;
lindquist@72 6 float f;
lindquist@72 7 void* vp;
lindquist@72 8
lindquist@72 9 hash_t toHash()
lindquist@72 10 {
lindquist@72 11 return l + cast(size_t)f;
lindquist@72 12 }
lindquist@72 13
lindquist@72 14 int opEquals(S s)
lindquist@72 15 {
lindquist@72 16 return (s.l == l) && (s.f == f);
lindquist@72 17 }
lindquist@72 18
lindquist@72 19 int opCmp(S a)
lindquist@72 20 {
lindquist@72 21 if (l == a.l) {
lindquist@72 22 return (f < a.f) ? -1 : (f > a.f) ? 1 : 0;
lindquist@72 23 }
lindquist@72 24 return (l < a.l) ? -1 : 1;
lindquist@72 25 }
lindquist@72 26
lindquist@72 27 char[] toString()
lindquist@72 28 {
lindquist@72 29 return "S instance";
lindquist@72 30 }
lindquist@72 31 }
lindquist@72 32
lindquist@72 33 void main()
lindquist@72 34 {
lindquist@72 35 S s=S(-1, 0);
lindquist@72 36 S t=S(-1, 1);
lindquist@72 37 S u=S(11,-1);
lindquist@72 38 S v=S(12,13);
lindquist@72 39
lindquist@72 40 {
lindquist@72 41 assert(s == s);
lindquist@72 42 assert(s != t);
lindquist@72 43 assert(s != v);
lindquist@72 44 assert(s < t);
lindquist@72 45 assert(u > s);
lindquist@72 46 assert(v > u);
lindquist@72 47 }
lindquist@72 48
lindquist@72 49 {
lindquist@72 50 auto ti = typeid(S);
lindquist@72 51 assert(ti.getHash(&s) == s.toHash());
lindquist@72 52 assert(ti.equals(&s,&s));
lindquist@72 53 assert(!ti.equals(&s,&t));
lindquist@72 54 assert(!ti.equals(&s,&v));
lindquist@72 55 assert(ti.compare(&s,&s) == 0);
lindquist@72 56 assert(ti.compare(&s,&t) < 0);
lindquist@72 57 assert(ti.compare(&u,&s) > 0);
lindquist@72 58 assert(ti.compare(&v,&u) > 0);
lindquist@72 59 {
lindquist@72 60 auto tis = cast(TypeInfo_Struct)ti;
lindquist@72 61 assert(tis.xtoString(&s) == s.toString());
lindquist@72 62 }
lindquist@72 63 }
lindquist@72 64 }