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
|
// maps3
// Make me compile!
//
// I AM NOT DONE
package main
import "testing"
func TestGetPhone(t *testing.T) {
phoneBook := map[string]string{
"Ana": "+01 101 102",
"John": "+01 333 666",
}
phone, _ := phoneBook["Anna"] // something seems wrong here
expectedPhone := "+01 101 102"
if phone != expectedPhone {
t.Errorf("phone should be %s but got %s", expectedPhone, phone)
}
}
func TestInsertPhone(t *testing.T) {
phoneBook := map[string]string{
"Ana": "+01 101 102",
"John": "+01 333 666",
}
phone, _ := phoneBook["Laura"] // don't change this line
expectedPhone := "+11 99 98 97"
if phone != expectedPhone {
t.Errorf("phone should be %s but got %s", expectedPhone, phone)
}
}
func TestDeletePhone(t *testing.T) {
phoneBook := map[string]string{
"Ana": "+01 101 102",
"John": "+01 333 666",
} // don't change the original map
totalPhones := len(phoneBook)
expectedTotalPhones := 1
if totalPhones != expectedTotalPhones {
t.Errorf("phoneBook should have only %d contact, but got %d", expectedTotalPhones, totalPhones)
}
}
|