-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListModel_should.cs
162 lines (149 loc) · 4.72 KB
/
ListModel_should.cs
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System.Collections.Generic;
using NUnit.Framework;
namespace TodoApplication
{
[TestFixture]
public class ListModel_Should
{
[Test]
public void AddItems()
{
var model = new ListModel<string>(20);
model.AddItem("a");
model.AddItem("bb");
model.AddItem("ccc");
Assert.AreEqual(new List<string>{"a", "bb", "ccc"}, model.Items);
}
[Test]
public void RemoveFromTheEnd()
{
var model = new ListModel<string>(20);
model.AddItem("a");
model.AddItem("bb");
model.AddItem("ccc");
model.RemoveItem(2);
Assert.AreEqual(new List<string> { "a", "bb" }, model.Items);
}
[Test]
public void RemoveFromTheBeginning()
{
var model = new ListModel<string>(20);
model.AddItem("a");
model.AddItem("bb");
model.AddItem("ccc");
model.RemoveItem(0);
Assert.AreEqual(new List<string> { "bb", "ccc" }, model.Items);
}
[Test]
public void RemoveFromTheMiddle()
{
var model = new ListModel<string>(20);
model.AddItem("a");
model.AddItem("bb");
model.AddItem("ccc");
model.RemoveItem(1);
Assert.AreEqual(new List<string> { "a", "ccc" }, model.Items);
model.Undo();
Assert.AreEqual(new List<string> { "a", "bb", "ccc" }, model.Items);
}
[Test]
public void RemoveAndUndoAllItems()
{
var model = new ListModel<string>(20);
model.AddItem("a");
model.AddItem("bb");
model.AddItem("ccc");
model.RemoveItem(0);
model.RemoveItem(0);
model.RemoveItem(0);
Assert.AreEqual(new List<string>(), model.Items);
model.Undo();
model.Undo();
model.Undo();
Assert.AreEqual(new List<string> { "a", "bb", "ccc" }, model.Items);
}
[Test]
public void UndoAddOperations()
{
var model = new ListModel<string>(20);
model.AddItem("a");
Assert.AreEqual(true, model.CanUndo());
model.Undo();
Assert.AreEqual(0, model.Items.Count);
}
[Test]
public void NotUndo_WhenEverythingIsUndone()
{
var model = new ListModel<string>(20);
model.AddItem("a");
model.AddItem("bb");
model.Undo();
model.Undo();
Assert.AreEqual(false, model.CanUndo());
}
[Test]
public void Add_AfterUndo()
{
var model = new ListModel<string>(20);
model.AddItem("a");
model.AddItem("bb");
model.Undo();
model.Undo();
model.AddItem("qq");
Assert.AreEqual(new List<string> { "qq" }, model.Items);
}
[Test]
public void Undo_AfterRemove()
{
var model = new ListModel<string>(20);
model.AddItem("a");
model.AddItem("bb");
model.RemoveItem(1);
model.Undo();
Assert.AreEqual(new List<string> { "a", "bb" }, model.Items);
}
[Test]
public void Remove_AfterUndo()
{
var model = new ListModel<string>(20);
model.AddItem("a");
model.AddItem("bb");
model.Undo();
model.RemoveItem(0);
Assert.AreEqual(0, model.Items.Count);
}
[Test]
public void NotUndo_WhenUndoLimitIsReached()
{
var model = new ListModel<string>(2);
model.AddItem("a");
model.AddItem("bb");
model.RemoveItem(1);
model.Undo();
model.Undo();
Assert.AreEqual(false, model.CanUndo());
Assert.AreEqual(new List<string> {"a"}, model.Items);
}
[Test]
public void CanUndo_ReturnsFalse_WhenUndoLimitIsReached()
{
var model = new ListModel<string>(1);
Assert.AreEqual(false, model.CanUndo());
model.AddItem("a");
model.AddItem("bb");
model.Undo();
Assert.AreEqual(false, model.CanUndo());
model.AddItem("ccc");
Assert.AreEqual(true, model.CanUndo());
}
[Test]
public void CanUndo_ReturnsFalse_WhenUndoLimitIsZero()
{
var model = new ListModel<string>(0);
Assert.AreEqual(false, model.CanUndo());
model.AddItem("a");
model.AddItem("bb");
Assert.AreEqual(false, model.CanUndo());
}
}
}