PageRenderTime 31ms CodeModel.GetById 24ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/specs/runtime/array.ds

http://github.com/wilkie/djehuty
Unknown | 42 lines | 34 code | 8 blank | 0 comment | 0 complexity | a8e9aa7b14dbf780ee12e0db7d47f115 MD5 | raw file
 1module specs.runtime.array;
 2
 3import io.console;
 4
 5import math.random;
 6
 7describe runtime() {
 8	describe _adCmp() {
 9		it should_handle_empty_arrays() {
10			int[] empty = [];
11			shouldNot(empty == [1,2,3]);
12		}
13	}
14
15	describe _adSort {
16		it should_sort_simple_int_arrays {
17			int[] sorted = [2,1,3].sort;
18			should(sorted == [1,2,3]);
19		}
20
21		it should_sort_random_arrays {
22			int[500] foo;
23			auto r = new Random();
24
25			foreach(ref element; foo) {
26				element = cast(int)r.next();
27			}
28
29			foo.sort;
30			int cur = foo[0];
31			foreach(element; foo) {
32				// Ensure it is ascending
33				should(element >= cur);
34			}
35		}
36
37		it should_sort_simple_double_arrays {
38			double[] sorted = [0.0, 0.8, 0.4, 0.2, 0.9].sort;
39			should(sorted == [0.0,0.2,0.4,0.8,0.9]);
40		}
41	}
42}