comparison test/bug9.d @ 40:8b0e809563df trunk

[svn r44] Lots of bug fixes. New array literal support New array ~= operator support (for single element) New with statement support More...
author lindquist
date Fri, 19 Oct 2007 07:43:21 +0200
parents
children d9d5d59873d8
comparison
equal deleted inserted replaced
39:fd5e8bbfcb25 40:8b0e809563df
1 module bug9;
2 struct rgb
3 {
4 ubyte[3] values;
5 rgb average(rgb other)
6 {
7 rgb res;
8 foreach (id, ref v; res.values) v=(values[id]+other.values[id])/2;
9 return res;
10 }
11 void print()
12 {
13 printf("[%d,%d,%d]\n", values[0], values[1], values[2]);
14 }
15 }
16
17 void main()
18 {
19 rgb a,b;
20 a.values[0] = 10;
21 a.values[1] = 20;
22 a.values[2] = 30;
23 b.values[0] = 30;
24 b.values[1] = 20;
25 b.values[2] = 10;
26 rgb avg = a.average(b);
27 avg.print();
28 assert(avg.values[0] == 20);
29 assert(avg.values[1] == 20);
30 assert(avg.values[2] == 20);
31 }
32