on master help sign in
added test.dart
commitc92ac809a5966d925858faacc22e260fe92bb899 authorAkshat Gadhwal <akshatgadhwal1@gmail.com> dateMon 5 Oct 2020, 10:57 (6 years ago) parentec842e8
2 files changed+266
tests/syntax-tests/highlighted/Dart/test.dart+133 tests/syntax-tests/source/Dart/test.dart+133
tests/syntax-tests/highlighted/Dart/test.dartnew file+133
@@ -0,0 +1,133 @@
1+/* array sorting alogorithm */
2+int partition(List list, int low, int high) {
3+ if (list == null || list.length == 0) return 0;
4+ int pivot = list[high];
5+ int i = low - 1;
6+
7+ void swap(List list, int i, int j) {
8+ int temp = list[i];
9+ list[i] = list[j];
10+ list[j] = temp;
11+ }
12+
13+ for (int j = low; j < high; j++) {
14+ if (list[j] <= pivot) {
15+ i++;
16+ swap(list, i, j);
17+ }
18+ swap(list, i + 1, high);
19+ return i + 1;
20+ }
21+}
22+
23+void quickSort(List list, int low, int high) {
24+ if (low < high) {
25+ int pi = partition(list, low, high);
26+ quickSort(list, low, pi - 1);
27+ quickSort(list, pi + 1, high);
28+ }
29+}
30+
31+void merge(List list, int leftIndex, int middleIndex, int rightIndex) {
32+ int leftSize = middleIndex - leftIndex + 1;
33+ int rightSize = rightIndex - middleIndex;
34+
35+ List leftList = new List(leftSize);
36+ List rightList = new List(rightSize);
37+
38+ for (int i = 0; i < leftSize; i++) leftList[i] = list[leftIndex + i];
39+ for (int j = 0; j < rightSize; j++) rightList[j] = list[middleIndex + j + 1];
40+
41+ int i = 0, j = 0;
42+ int k = leftIndex;
43+
44+ while (i < leftSize && j < rightSize) {
45+ if (leftList[i] <= rightList[j]) {
46+ list[k] = leftList[i];
47+ i++;
48+ } else {
49+ list[k] = rightList[j];
50+ j++;
51+ }
52+ k++;
53+ }
54+
55+ while (i < leftSize) {
56+ list[k] = leftList[i];
57+ i++;
58+ k++;
59+ }
60+
61+ while (j < rightSize) {
62+ list[k] = rightList[j];
63+ j++;
64+ k++;
65+ }
66+}
67+
68+void mergeSort(List list, int leftIndex, int rightIndex) {
69+ if (leftIndex < rightIndex) {
70+ int middleIndex = (rightIndex + leftIndex) ~/ 2;
71+
72+ mergeSort(list, leftIndex, middleIndex);
73+ mergeSort(list, middleIndex + 1, rightIndex);
74+
75+ merge(list, leftIndex, middleIndex, rightIndex);
76+ }
77+}
78+
79+/* variables */
80+var name = 'Voyager I';
81+var year = 1977;
82+var antennaDiameter = 3.7;
83+var flybyObjects = ['Jupiter', 'Saturn', 'Uranus', 'Neptune'];
84+var image = {
85+ 'tags': ['saturn'],
86+ 'url': '//path/to/saturn.jpg'
87+};
88+
89+/*classes */
90+class Spacecraft {
91+ String name;
92+ DateTime launchDate;
93+ Spacecraft(this.name, this.launchDate) {}
94+
95+ // Named constructor that forwards to the default one.
96+ Spacecraft.unlaunched(String name) : this(name, null);
97+
98+ int get launchYear => launchDate?.year;
99+
100+ void describe() {
101+ print('Spacecraft: $name');
102+ if (launchDate != null) {
103+ int years = DateTime.now().difference(launchDate).inDays ~/ 365;
104+ print('Launched: $launchYear ($years years ago)');
105+ } else {
106+ print('Unlaunched');
107+ }
108+ }
109+}
110+
111+/* Mixins */
112+class PilotedCraft extends Spacecraft with Piloted {
113+ // ···
114+}
115+
116+/* Interfaces and abstract classes */
117+class MockSpaceship implements Spacecraft {
118+ // ···
119+}
120+
121+/* async */
122+Future<void> printWithDelay(String message) {
123+ return Future.delayed(const Duration(seconds: 2)).then((_) {
124+ print(message);
125+ });
126+}
127+
128+Stream<String> report(Spacecraft craft, Iterable<String> objects) async* {
129+ for (var object in objects) {
130+ await Future.delayed(const Duration(seconds: 2));
131+ yield '${craft.name} flies by $object';
132+ }
133+}
tests/syntax-tests/source/Dart/test.dartnew file+133
@@ -0,0 +1,133 @@
1+/* array sorting alogorithm */
2+int partition(List list, int low, int high) {
3+ if (list == null || list.length == 0) return 0;
4+ int pivot = list[high];
5+ int i = low - 1;
6+
7+ void swap(List list, int i, int j) {
8+ int temp = list[i];
9+ list[i] = list[j];
10+ list[j] = temp;
11+ }
12+
13+ for (int j = low; j < high; j++) {
14+ if (list[j] <= pivot) {
15+ i++;
16+ swap(list, i, j);
17+ }
18+ swap(list, i + 1, high);
19+ return i + 1;
20+ }
21+}
22+
23+void quickSort(List list, int low, int high) {
24+ if (low < high) {
25+ int pi = partition(list, low, high);
26+ quickSort(list, low, pi - 1);
27+ quickSort(list, pi + 1, high);
28+ }
29+}
30+
31+void merge(List list, int leftIndex, int middleIndex, int rightIndex) {
32+ int leftSize = middleIndex - leftIndex + 1;
33+ int rightSize = rightIndex - middleIndex;
34+
35+ List leftList = new List(leftSize);
36+ List rightList = new List(rightSize);
37+
38+ for (int i = 0; i < leftSize; i++) leftList[i] = list[leftIndex + i];
39+ for (int j = 0; j < rightSize; j++) rightList[j] = list[middleIndex + j + 1];
40+
41+ int i = 0, j = 0;
42+ int k = leftIndex;
43+
44+ while (i < leftSize && j < rightSize) {
45+ if (leftList[i] <= rightList[j]) {
46+ list[k] = leftList[i];
47+ i++;
48+ } else {
49+ list[k] = rightList[j];
50+ j++;
51+ }
52+ k++;
53+ }
54+
55+ while (i < leftSize) {
56+ list[k] = leftList[i];
57+ i++;
58+ k++;
59+ }
60+
61+ while (j < rightSize) {
62+ list[k] = rightList[j];
63+ j++;
64+ k++;
65+ }
66+}
67+
68+void mergeSort(List list, int leftIndex, int rightIndex) {
69+ if (leftIndex < rightIndex) {
70+ int middleIndex = (rightIndex + leftIndex) ~/ 2;
71+
72+ mergeSort(list, leftIndex, middleIndex);
73+ mergeSort(list, middleIndex + 1, rightIndex);
74+
75+ merge(list, leftIndex, middleIndex, rightIndex);
76+ }
77+}
78+
79+/* variables */
80+var name = 'Voyager I';
81+var year = 1977;
82+var antennaDiameter = 3.7;
83+var flybyObjects = ['Jupiter', 'Saturn', 'Uranus', 'Neptune'];
84+var image = {
85+ 'tags': ['saturn'],
86+ 'url': '//path/to/saturn.jpg'
87+};
88+
89+/*classes */
90+class Spacecraft {
91+ String name;
92+ DateTime launchDate;
93+ Spacecraft(this.name, this.launchDate) {}
94+
95+ // Named constructor that forwards to the default one.
96+ Spacecraft.unlaunched(String name) : this(name, null);
97+
98+ int get launchYear => launchDate?.year;
99+
100+ void describe() {
101+ print('Spacecraft: $name');
102+ if (launchDate != null) {
103+ int years = DateTime.now().difference(launchDate).inDays ~/ 365;
104+ print('Launched: $launchYear ($years years ago)');
105+ } else {
106+ print('Unlaunched');
107+ }
108+ }
109+}
110+
111+/* Mixins */
112+class PilotedCraft extends Spacecraft with Piloted {
113+ // ···
114+}
115+
116+/* Interfaces and abstract classes */
117+class MockSpaceship implements Spacecraft {
118+ // ···
119+}
120+
121+/* async */
122+Future<void> printWithDelay(String message) {
123+ return Future.delayed(const Duration(seconds: 2)).then((_) {
124+ print(message);
125+ });
126+}
127+
128+Stream<String> report(Spacecraft craft, Iterable<String> objects) async* {
129+ for (var object in objects) {
130+ await Future.delayed(const Duration(seconds: 2));
131+ yield '${craft.name} flies by $object';
132+ }
133+}