-
Notifications
You must be signed in to change notification settings - Fork 1
/
locator_test.go
60 lines (49 loc) · 1.41 KB
/
locator_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
54
55
56
57
58
59
60
package twitchchatscraper
import (
"testing"
)
func TestLocator_GetChatServerAddress_ReturnsValidChatServerAddress(t *testing.T) {
underTest := NewLocator()
chatServers := underTest.GetIrcServerAddress("test_channel")
if len(chatServers) == 0 {
t.Fail()
}
}
func TestLocator_GetTopTwitchStreams_ReturnsListOfCorrectLength(t *testing.T) {
underTest := NewLocator()
numberOfChannelsToRequest := 10
topStreams := underTest.GetTopNChannels(numberOfChannelsToRequest)
if len(topStreams) != numberOfChannelsToRequest {
t.Fatalf("Expected %d channels, got %d", numberOfChannelsToRequest,
len(topStreams))
t.Fail()
}
if !arrayContainsUniqueValues(topStreams) {
t.Fatalf("Returned channels should be unique")
t.Fail()
}
}
func TestLocator_GetTopTwitchStreams_ReturnsBigListOfCorrectLength(t *testing.T) {
underTest := NewLocator()
numberOfChannelsToRequest := 201
topStreams := underTest.GetTopNChannels(numberOfChannelsToRequest)
if len(topStreams) != numberOfChannelsToRequest {
t.Fatalf("Expected %d channels, got %d", numberOfChannelsToRequest,
len(topStreams))
t.Fail()
}
if !arrayContainsUniqueValues(topStreams) {
t.Fatalf("Returned channels should be unique")
t.Fail()
}
}
func arrayContainsUniqueValues(givenArray []string) bool {
valueMap := make(map[string]bool, 0)
for _, value := range givenArray {
if valueMap[value] {
return false
}
valueMap[value] = true
}
return true
}