-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathexercise_one_test.go
53 lines (40 loc) · 1.25 KB
/
exercise_one_test.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
package go_unit_test_bootcamp
import (
"math/rand"
"testing"
"time"
)
func TestFindMissingDrone_basic(t *testing.T) {
result := FindMissingDrone([]int{1, 3, 2, 2, 3})
if result != 1 {
t.Errorf("expected missing drone ID to be 1, got %d", result)
}
}
func TestFindMissingDrone_basic2(t *testing.T) {
result := FindMissingDrone([]int{1, 4, 4, 2, 3, 1, 2})
if result != 3 {
t.Errorf("expected missing drone ID to be 3, got %d", result)
}
}
func TestFindMissingDrone_single(t *testing.T) {
result := FindMissingDrone([]int{3})
if result != 3 {
t.Errorf("expected missing drone ID to be 3, got %d", result)
}
}
func TestFindMissingDrone_random(t *testing.T) {
rand.Seed(time.Now().UnixNano())
missingDrone := rand.Int()
droneIds := []int{missingDrone}
for i := 0; i < rand.Intn(20); i++ {
randomDroneId := rand.Int()
droneIds = append(droneIds, randomDroneId, randomDroneId)
}
rand.Shuffle(len(droneIds), func(i, j int) {
droneIds[i], droneIds[j] = droneIds[j], droneIds[i]
})
result := FindMissingDrone(droneIds)
if result != missingDrone {
t.Errorf("expected missing drone ID to be %d, got %d", missingDrone, result)
}
}