-
Notifications
You must be signed in to change notification settings - Fork 0
/
arraylist_test.gen.go
195 lines (149 loc) · 3.67 KB
/
arraylist_test.gen.go
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package list
import "testing"
func TestALG_Vacia(t *testing.T) {
lista := NewArrayListGeneric[int](5)
// Tendra un size == 0
if lista.Length() != 0 {
t.Error("Elementos esperados 0, obtenidos", lista.Length())
}
}
func TestALG_Append(t *testing.T) {
lista := NewArrayListGeneric[int](5)
lista.Append(10)
lista.Append(20)
// Tendra 2 elementos
if lista.Length() != 2 {
t.Error("Elementos esperados 2, obtenidos", lista.Length())
}
lista.MoveToPos(0) // lista.MoveToStart()
valor_1, _ := lista.CurrentElement()
if valor_1 != 10 {
t.Error("Esperado 10, obtenido", valor_1)
}
lista.MoveToPos(1)
valor_2, _ := lista.CurrentElement()
if valor_2 != 20 {
t.Error("Esperado 20, obtenido", valor_2)
}
}
func TestALG_Remove(t *testing.T) {
lista := NewArrayListGeneric[int](5)
lista.Append(10)
lista.Append(20)
lista.MoveToStart()
removido_1, error := lista.Remove() // Remueve el primero
if error != nil {
t.Error("Error inesperado", error)
}
if removido_1 != 10 {
t.Error("Esperado 10, obtenido", removido_1)
}
if lista.Length() != 1 {
t.Error("Esperado 1 elemento, obtenido", lista.Length())
}
removido_2, error := lista.Remove()
if error != nil {
t.Error("Error inesperado:", error)
}
if removido_2 != 20 {
t.Error("Esperadoo 20, obtenido", removido_2)
}
if lista.Length() != 0 {
t.Error("Esperado 0, obtenido", lista.Length())
}
_, error = lista.Remove()
if error == nil {
t.Error("Debio generarse un error")
}
}
func TestALG_Clear(t *testing.T) {
lista := NewArrayListGeneric[int](5)
lista.Append(10)
lista.Append(20)
lista.Clear()
if lista.Length() != 0 {
t.Error("Debia estar vacio pero hay ", lista.Length(), "elementos")
}
}
func TestALG_Next(t *testing.T) {
lista := NewArrayListGeneric[int](5)
lista.Append(10)
lista.Append(20)
lista.Append(30)
lista.MoveToStart()
lista.Next()
primero, _ := lista.CurrentElement()
if primero != 20 {
t.Error("Esperado 20, obtenido", primero)
}
lista.Next()
segundo, _ := lista.CurrentElement()
if segundo != 30 {
t.Error("Esperado 30, obtenido", segundo)
}
lista.Next()
tercero, _ := lista.CurrentElement()
if tercero != 30 {
t.Error("Esperado 30, obtenido ", tercero)
}
}
func TestALG_Prev(t *testing.T) {
lista := NewArrayListGeneric[int](5)
lista.Append(10)
lista.Append(20)
lista.Append(30)
lista.MoveToEnd()
primero, _ := lista.CurrentElement()
if primero != 30 {
t.Error("Esperado 30, obtenido", primero)
}
lista.Prev()
segundo, _ := lista.CurrentElement()
if segundo != 20 {
t.Error("Esperado 20, obtenido", segundo)
}
lista.Prev()
tercero, _ := lista.CurrentElement()
if tercero != 10 {
t.Error("Esperado 10 obtenido", tercero)
}
// Ese es el comportamiento del libro: al llegar al principio no retrocede mas
lista.Prev()
tercero_2, _ := lista.CurrentElement()
if tercero_2 != 10 {
t.Error("Esperado 10 obtenido", tercero_2)
}
}
func TestALG_Insert(t *testing.T) {
lista := NewArrayListGeneric[int](5)
lista.Append(10)
lista.Append(30)
lista.MoveToPos(1)
lista.Insert(20)
valor, _ := lista.CurrentElement()
if lista.Length() != 3 {
t.Error("Esperados 3 elementos, obtenido", lista.Length())
}
if valor != 20 {
t.Error("Esperado 20, obtenido ", valor)
}
lista.MoveToEnd()
valor, _ = lista.CurrentElement()
if valor != 30 {
t.Error("Esperado 30, obtenido ", valor)
}
}
func TestALG_Find(t *testing.T) {
lista := NewArrayListGeneric[int](5)
lista.Append(10) // 0
lista.Append(20) // 1
lista.Append(30) // 2
hallado_1 := lista.Find(20)
if hallado_1 != 1 {
t.Error("Posicion requerida 1, obtenida", hallado_1)
}
hallado_2 := lista.Find(50)
if hallado_2 != -1 {
t.Error("Posicion requerida -1, obtenida", hallado_2)
}
}