-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
51 lines (41 loc) · 1.48 KB
/
main_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
package main
import (
"bytes"
"strings"
"testing"
)
func TestRun(t *testing.T) {
// Set up a fake input string and a buffer to capture output
inputStr := "SF\n"
expectedOutput := "Predicted wins for the upcoming season: 97.31\n"
outputBuf := bytes.NewBuffer(nil)
// Run the function with the fake input and capture the output
run(strings.NewReader(inputStr), outputBuf)
actualOutput := outputBuf.String()
// Compare the actual and expected output
if actualOutput != expectedOutput {
t.Errorf("Unexpected output:\nExpected: %s\nActual: %s", expectedOutput, actualOutput)
}
// Test for invalid team abbreviation
inputStr = "INVALID\n"
expectedOutput = "Table not found in HTML\n"
outputBuf.Reset()
// Run the function with the fake input and capture the output
run(strings.NewReader(inputStr), outputBuf)
actualOutput = outputBuf.String()
// Compare the actual and expected output
if actualOutput != expectedOutput {
t.Errorf("Unexpected output:\nExpected: %s\nActual: %s", expectedOutput, actualOutput)
}
// Test for table with less than two columns
inputStr = "SD\n"
expectedOutput = "Error parsing data: row 0 has length 1 instead of 2\n"
outputBuf.Reset()
// Run the function with the fake input and capture the output
run(strings.NewReader(inputStr), outputBuf)
actualOutput = outputBuf.String()
// Compare the actual and expected output
if actualOutput != expectedOutput {
t.Errorf("Unexpected output:\nExpected: %s\nActual: %s", expectedOutput, actualOutput)
}
}