Ejemplo n.º 1
0
func TestListClone(t *testing.T) {
	fmt.Println("ArrayList Clone")

	list = strings.NewArrayList()
	list.Add(arg1)
	list.Add(arg2)
	set1 := list.Clone()
	if set1.Size() != 2 {
		t.Errorf("Clone failed: size %v != 2\n", set1.Size())
	}
}
Ejemplo n.º 2
0
func TestListClear(t *testing.T) {
	fmt.Println("ArrayList Clear")

	list = strings.NewArrayList()
	list.Add(arg1)
	list.Add(arg2)
	list.Clear()
	if !list.Empty() {
		t.Errorf("Clear failed: Should be empty\n")
	}
}
Ejemplo n.º 3
0
func TestListSize(t *testing.T) {
	fmt.Println("ArrayList Size")

	list = strings.NewArrayList()
	list.Add(arg1)
	list.Add(arg2)

	if list.Size() != 2 {
		t.Errorf("Size failed: wrong size %v != 2\n", list.Size())
	}
}
Ejemplo n.º 4
0
func TestListInsert(t *testing.T) {
	fmt.Println("ArrayList Insert")

	list = strings.NewArrayList()
	list.Add(arg1, arg2, arg3)

	v := arg4
	list.Insert(0, v)
	if list.Size() != 4 {
		t.Errorf("Wrong size %v != 4\n", list.Size())
	}

	r := list.Get(0)
	if r != v {
		t.Errorf("Insert: failed insert at 0\n")
	}

	v = arg4
	list.Insert(2, v)
	if list.Size() != 5 {
		t.Errorf("Wrong size %v != 5\n", list.Size())
	}

	r = list.Get(2)
	if r != v {
		t.Errorf("Insert: failed insert at 2\n")
	}

	v = arg4
	list.Insert(5, v)
	if list.Size() != 6 {
		t.Errorf("Wrong size %v != 6\n", list.Size())
	}

	r = list.Get(5)
	if r != v {
		t.Errorf("Insert: failed insert at 5\n")
	}

	v = arg2
	list.Insert(99, v)
	if list.Size() != 7 {
		t.Errorf("Wrong size %v != 7\n", list.Size())
	}

	r = list.Get(6)
	if r != v {
		t.Errorf("Insert: failed insert at 99\n")
	}
}
Ejemplo n.º 5
0
func TestListEmpty(t *testing.T) {
	fmt.Println("ArrayList Empty")

	list = strings.NewArrayList()

	if !list.Empty() {
		t.Errorf("Empty: should be empty\n")
	}

	list.Add(arg1)

	if list.Empty() {
		t.Errorf("Empty: should not be empty\n")
	}
}
Ejemplo n.º 6
0
func TestListSet(t *testing.T) {
	fmt.Println("ArrayList Set")

	list = strings.NewArrayList()
	list.Add(arg1, arg2, arg3)

	v := "NewValue"
	r := list.Set(1, v)
	s := list.Get(1)
	if s != v {
		t.Errorf("Set failed: %v != %v\n", s, v)
	}
	if r != arg2 {
		t.Errorf("Set return failed: %v != %v\n", arg2, r)
	}
}
Ejemplo n.º 7
0
func TestListIndexOf(t *testing.T) {
	fmt.Println("ArrayList IndexOf")

	list = strings.NewArrayList()
	list.Add(arg1, arg2, arg3)

	i := list.IndexOf(arg2)
	j := list.IndexOf(arg4)

	if i != 1 {
		t.Errorf("Wrong index: %v != 1\n", i)
	}
	if j != -1 {
		t.Errorf("Wrong index: %v != -1\n", j)
	}
}
Ejemplo n.º 8
0
func TestListContains(t *testing.T) {
	fmt.Println("ArrayList Contains")

	list = strings.NewArrayList()
	list.Add(arg1, arg2, arg3)
	if list.Size() != 3 {
		t.Errorf("Wrong size %v != 3\n", list.Size())
	}

	expected := []string{arg1, arg2, arg3}
	for _, v := range list.Iterator() {
		if !list.Contains(v) {
			t.Errorf("Contains failed: %v not in %v", v, expected)
		}
	}

	v := arg4
	if list.Contains(v) {
		t.Errorf("Contains failed: %v found in %v", v, expected)
	}
}
Ejemplo n.º 9
0
func TestListDelete(t *testing.T) {
	fmt.Println("ArrayList Delete")

	list = strings.NewArrayList()
	list.Add(arg1, arg2, arg3)

	list.Delete(5)
	if list.Size() != 3 {
		t.Errorf("Wrong size %v != 3\n", list.Size())
	}

	list.Delete(1)
	if list.Size() != 2 {
		t.Errorf("Wrong size %v != 2\n", list.Size())
	}

	r := list.Get(1)

	if r == arg2 {
		t.Errorf("Delete failed: still contains %v", r)
	}
}
Ejemplo n.º 10
0
func TestListIterator(t *testing.T) {
	fmt.Println("ArrayList Iterator")

	list = strings.NewArrayList()
	list.Add(arg1, arg2, arg3)
	if list.Size() != 3 {
		t.Errorf("Wrong size %v != 3\n", list.Size())
	}

	found := 0
	expected := []string{arg1, arg2, arg3}
	for _, v := range list.Iterator() {
		for _, x := range expected {
			if x == v {
				found++
				break
			}
		}
	}
	if found != 3 {
		t.Errorf("Iterator failed: %v != %v", list.Iterator(), expected)
	}
}
Ejemplo n.º 11
0
func TestListRemove(t *testing.T) {
	fmt.Println("ArrayList Remove")

	list = strings.NewArrayList()
	list.Add(arg1, arg2, arg3)
	list.Remove(arg4) // ignores this correctly
	if list.Size() != 3 {
		t.Errorf("Wrong size %v != 3\n", list.Size())
	}

	v := arg2
	list.Remove(v)
	if list.Size() != 2 {
		t.Errorf("Wrong size %v != 2\n", list.Size())
	}
	if list.Contains(v) {
		t.Errorf("Remove failed: still contains %v", v)
	}

	list.Remove(arg1, arg3)
	if !list.Empty() {
		t.Errorf("Empty: should be empty\n")
	}
}