-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathaverage_test.go
42 lines (34 loc) · 1.03 KB
/
average_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
package goterators
import (
"fmt"
"testing"
)
func TestAverage(t *testing.T) {
testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
expectedValue := 10.5
actualValue := Average(testSource)
if actualValue != expectedValue {
t.Errorf("Expected = %v , got = %v", expectedValue, actualValue)
}
actualValue = Mean(testSource)
if actualValue != expectedValue {
t.Errorf("Expected = %v , got = %v", expectedValue, actualValue)
}
}
func TestAverageOfEmptyList(t *testing.T) {
var testSource []int
expectedValue := 0.0
actualValue := Average(testSource)
if actualValue != expectedValue {
t.Errorf("Expected = %v , got = %v", expectedValue, actualValue)
}
actualValue = Mean(testSource)
if actualValue != expectedValue {
t.Errorf("Expected = %v , got = %v", expectedValue, actualValue)
}
}
func ExampleAverage() {
testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
fmt.Println("Average: ", Average(testSource))
fmt.Println("Mean: ", Mean(testSource))
}