-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
89 lines (83 loc) · 2.69 KB
/
test.js
File metadata and controls
89 lines (83 loc) · 2.69 KB
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
86
87
88
89
var test = require("tape");
var logic = require("./logic");
test("Example test", function(t) {
t.pass();
t.end();
});
test("add new to do item ", function(t) {
var actual = logic.addTodo(
[
{ id: -3, description: "first todo", done: false },
{ id: -2, description: "second todo", done: false },
{ id: -1, description: "third todo", done: false }
],
{ id: -4, description: "first todo", done: false }
);
var expected = [
{ id: -3, description: "first todo", done: false },
{ id: -2, description: "second todo", done: false },
{ id: -1, description: "third todo", done: false },
{ id: -4, description: "first todo", done: false }
];
console.log(actual + "actual\n");
console.log(expected + "expected\n");
t.deepEqual(actual, expected, "the item should add to the list");
t.end();
});
test("delete todo item ", function(t) {
var actual = logic.deleteTodo(
[
{ id: -3, description: "first todo", done: false },
{ id: -2, description: "second todo", done: false },
{ id: -1, description: "third todo", done: false }
],
-3
);
var expected = [
{ id: -2, description: "second todo", done: false },
{ id: -1, description: "third todo", done: false }
];
console.log(actual + "actual\n");
console.log(expected + "expected\n");
t.deepEqual(actual, expected, "the to do item should deleted");
t.end();
});
test(" mark todo item ", function(t) {
var actual = logic.markTodo(
[
{ id: -3, description: "first todo", done: false },
{ id: -2, description: "second todo", done: false },
{ id: -1, description: "third todo", done: false }
],
-3
);
var expected = [
{ id: -3, description: "first todo", done: true },
{ id: -2, description: "second todo", done: false },
{ id: -1, description: "third todo", done: false }
];
console.log(actual + "actual\n");
console.log(expected + "expected\n");
t.deepEqual(actual, expected, "the to do item should be mark");
t.end();
});
test("sortTodos", function(t) {
var arr = [
{ id: -1, description: "third todo", done: true },
{ id: -2, description: "second todo", done: true },
{ id: 0, description: "zero todo", done: false }
];
var actual = logic.sortTodos(arr, function(a, b) {
return a["description"] > b["description"];
});
var expected = [
{ id: -2, description: "second todo", done: true },
{ id: -1, description: "third todo", done: true },
{ id: 0, description: "zero todo", done: false }
];
console.log(a[0]["description"] + "\n");
console.log(b[0]["description"] + "\n");
console.log(v[0]["description"] + "\n");
t.deepEqual(actual, expected, "the to do list should be sort");
t.end();
});