Skip to content

Commit

Permalink
Added tests for 0 and 1 as requested by PR review and tidied up some …
Browse files Browse the repository at this point in the history
…code formatting
  • Loading branch information
Jim hejtmanek committed Sep 9, 2019
1 parent da9a556 commit a799821
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions 01_fib/jimbotech/ex_fib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ func TestFib(t *testing.T) {

for _, val := range fibResults {
if r := f(); r != val {
t.Fail()
t.Logf("Returned value %v does not match %v", r, val)
t.Errorf("Returned value %v does not match %v", r, val)
}
}
}

func TestMain(t *testing.T) {
want := "1\n1\n2\n3\n5\n8\n13\n"

want := "1\n1\n2\n3\n5\n8\n13\n"
var buf bytes.Buffer
out = &buf
main()
Expand All @@ -33,8 +32,8 @@ func TestMain(t *testing.T) {
}

func TestNeg(t *testing.T) {
want := "1\n-1\n2\n-3\n5\n-8\n13\n"

want := "1\n-1\n2\n-3\n5\n-8\n13\n"
var buf bytes.Buffer
out = &buf
fib(-7)
Expand All @@ -44,3 +43,28 @@ func TestNeg(t *testing.T) {
t.Errorf("expected %v, got %v", want, result)
}
}

func TestZero(t *testing.T) {

var buf bytes.Buffer
out = &buf
fib(0)
result := buf.String()

if len(result) > 0 {
t.Errorf("Expected nothing to be printed, got %v", result)
}
}

func TestOne(t *testing.T) {

want := "1\n"
var buf bytes.Buffer
out = &buf
fib(1)
result := buf.String()

if result != want {
t.Errorf("expected %v, got %v", want, result)
}
}

0 comments on commit a799821

Please sign in to comment.