-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_collections_test.vala
85 lines (67 loc) · 2.58 KB
/
task_collections_test.vala
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using Tasks;
using TaskCollections;
class TaskCollectionsTest : GLib.Object {
public static int main (string[] args) {
TaskCollection collection = new BasicTaskCollection ("Personal");
test_collection (collection);
collection = new GrowableTaskCollection ("Work");
test_collection (collection);
return 0;
}
private static void test_collection (TaskCollection collection) {
var task1 = new Task ("buy new helmet");
var task2 = new Task ("test new helmet");
var task3 = new LongTimeTask.with_progress ("improve English", 10);
stdout.printf("\n\n");
stdout.printf ("===Testing collection '%s'===\n", collection.title);
try {
collection.add_task (task1);
}
catch (TaskCollectionError e) {
stdout.printf (@"Failed to add task '$task1': %s\n", e.message);
}
try {
collection.add_task (task2);
}
catch (TaskCollectionError e) {
stdout.printf (@"Failed to add task '$task2': %s\n", e.message);
}
try {
collection.add_task (task3);
}
catch (TaskCollectionError e) {
stdout.printf (@"Failed to add task '$task3': %s\n", e.message);
}
stdout.printf ("%s", collection.dump);
stdout.printf ("Number of tasks: %d", collection.number_of_tasks);
stdout.printf (@"\nremoving task '$task2'\n\n");
collection.remove_task (task2);
stdout.printf("Tasks:\n");
foreach (var task in collection) {
if (task == null)
stdout.printf("**(null)**\n");
else
stdout.printf(@"$task\n");
}
stdout.printf ("Number of tasks: %d", collection.number_of_tasks);
string in_not_in = (task2 in collection) ? "in" : "not in";
stdout.printf (@"\nTask '$task2' $in_not_in collection\n");
stdout.printf (@"\nadding task '$task2' back\n\n");
try {
collection.add_task (task2);
}
catch (TaskCollectionError e) {
stdout.printf (@"Failed to add task '$task2': %s\n", e.message);
}
stdout.printf("Tasks:\n");
foreach (var task in collection) {
if (task == null)
stdout.printf("**(null)**\n");
else
stdout.printf(@"$task\n");
}
stdout.printf ("Number of tasks: %d", collection.number_of_tasks);
in_not_in = (task2 in collection) ? "in" : "not in";
stdout.printf (@"\nTask '$task2' $in_not_in collection\n");
}
}