-
Notifications
You must be signed in to change notification settings - Fork 0
/
_9_memStress.d
48 lines (37 loc) · 1.21 KB
/
_9_memStress.d
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
unittest
{
import core.stdc.stdio;
enum LOCAL_DATA_NUM = 1000;
enum INSTANCES_NUM = 10000;
class ARandomClass {
int counter = 0;
int[LOCAL_DATA_NUM] data;
this(){}
void method1() {
for (int i = 0; i < LOCAL_DATA_NUM; i++) {
ulong temp = ((LOCAL_DATA_NUM - 1) * (LOCAL_DATA_NUM - 1)
* (LOCAL_DATA_NUM - 1) * i);
data[i] = temp % cast(ulong)(int.max);
}
}
void method2() {
ulong temp = ((LOCAL_DATA_NUM - 1) * (LOCAL_DATA_NUM - 1)
* (LOCAL_DATA_NUM - 1) * counter);
assert(data[counter] == temp % cast(ulong)(int.max));
}
}
ARandomClass[] instancesArray = new ARandomClass[INSTANCES_NUM];
for (int i = 0; i < INSTANCES_NUM; i++) {
instancesArray[i] = new ARandomClass;
assert(instancesArray[i]);
int[] array = new int[10];
instancesArray[i].method1();
}
for (int i = 0; i < INSTANCES_NUM; i++) {
for (int j = 0; j < LOCAL_DATA_NUM - 1; j++) {
assert(instancesArray[i]);
instancesArray[i].method2();
}
}
printf("Test #9 passed\n");
}