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
|
// slices4
// Make me compile!
// I AM NOT DONE
package main_test
import (
"reflect"
"testing"
)
func TestGetOnlyFirstName(t *testing.T) {
names := []string{"John", "Maria", "Carl", "Peter"}
firstName := names[3]
if firstName != "John" {
t.Errorf("firstName value must be John")
}
}
func TestGetFirstTwoNames(t *testing.T) {
names := []string{"John", "Maria", "Carl", "Peter"}
firstTwoNames := names[5:10]
expectedFirstTwoNames := []string{"John", "Maria"}
if !reflect.DeepEqual(firstTwoNames, expectedFirstTwoNames) {
t.Errorf("firstTwoNames should be %v, but got %v", expectedFirstTwoNames, firstTwoNames)
}
}
func TestGetLastTwoNames(t *testing.T) {
names := []string{"John", "Maria", "Carl", "Peter"}
lastTwoNames := names[5:10]
expectedLastTwoNames := []string{"Carl", "Peter"}
if !reflect.DeepEqual(lastTwoNames, expectedLastTwoNames) {
t.Errorf("firstTwoNames should be %v, but got %v", expectedLastTwoNames, lastTwoNames)
}
}
|