Skip to content
Snippets Groups Projects
Commit 69cf765f authored by Aksel Baardsen's avatar Aksel Baardsen
Browse files

bad tests, but works

parent afc81762
No related branches found
No related tags found
No related merge requests found
package main
import (
"assignment-1/pkg"
"net/http"
"testing"
)
func TestGetString(t *testing.T) {
s, i := pkg.GetString("https://www.nrk.no/")
if i != http.StatusOK {
t.Errorf("[if nrk is up]Expected 200 OK, got %d", i)
}
if len(s) < 50 {
t.Errorf("[if nrk is up]Expected a body, got %s", s)
}
}
func TestContains(t *testing.T) {
var array = []int{1, 2, 3, 5, 28}
testCases := map[int]bool{
5: true,
4: false,
3: true,
29: false,
}
for i, b := range testCases {
if pkg.Contains(array, i) != b {
t.Errorf("Expected true, got false")
}
}
}
\ No newline at end of file
......@@ -25,12 +25,21 @@ func getString(url string) (string, int) {
return bodyString, resp.StatusCode
}
func contains(s []int, e int) bool {
for _, a := range s {
if a == e {
func contains(array []int, x int) bool {
for _, i := range array {
if i == x {
return true
}
}
return false
}
/*
funcs for testing purposes
*/
func Contains(array []int, x int) bool {
return contains(array, x)
}
func GetString(url string) (string, int) {
return getString(url)
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment