PageRenderTime 55ms CodeModel.GetById 1ms app.highlight 51ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/example_balancing.d

http://github.com/baryluk/cords
D | 63 lines | 50 code | 12 blank | 1 comment | 6 complexity | 8ccc822675022ef8db466ffa692e9e16 MD5 | raw file
 1module example_balancing;
 2
 3import std.stdio;
 4import std.string : ts = toString;
 5import cords : RBCord;
 6
 7void main() {
 8
 9	RBCord r1;
10
11	// Balancing
12
13	auto expected_depth1 = [
14	   0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,  30,  31,
15	  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,
16	  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,
17	  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  15,  16,  17,  18,  19,  20,  21,  22,  23,
18	  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  15,  16,  17,  18,  19,  20,  21,  22,
19	  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  16,  17,  18,  19,  20,  21,  22,
20	  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  16,  17,  18,  19,  20,  21,  22,
21	  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  17,  18,  19,  20,  21,  22,  23,
22	  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  17,  18,  19,  20,  21,  22,  23,  24,
23	  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  17,  18,  19,  20,  21,  22,  23,  24,  25,
24	  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,
25	  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,
26	  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44
27	];
28
29	auto expected_depth = [
30	   0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,  30,  31,
31	  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  11,  12,  13,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,
32	  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,
33	  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  15,  16,  17,  18,  19,  20,  21,  22,  23,
34	  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  15,  16,  17,  18,  19,  20,  21,  22,
35	  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  16,  17,  18,  19,  20,  21,  22,
36	  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  16,  17,  18,  19,  20,  21,  22,
37	  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  17,  18,  19,  20,  21,  22,  23,
38	  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  17,  18,  19,  20,  21,  22,  23,  24,
39	  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  17,  18,  19,  20,  21,  22,  23,  24,  25,
40	  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,
41	  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,
42	  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44
43	];
44
45	r1 = RBCord();
46
47	r1 = "Ala ma kota";
48
49	for (int i = 0; i < 400; i++) {
50		r1 = r1 ~ "ABCDEFG123456";
51		assert(r1.get_depth() == expected_depth1[i]);
52	}
53	assert(r1.get_depth() == 44);
54
55	r1 = RBCord();
56
57	for (int i = 0; i < 400; i++) {
58		r1 = "ABCDEFG123456" ~ r1;
59		assert(r1.get_depth() == expected_depth1[i]);
60	}
61
62	assert(r1.get_depth == 44);
63}