Demo entry 6659286

go

   

Submitted by anonymous on Nov 10, 2017 at 11:21
Language: Go. Code size: 449 Bytes.

func TestFibonacci(t *testing.T) {
	type FibData struct {
		n        int
		expected int
	}
	type FibDatas []FibData

	var testDatas = FibDatas{
		{0, 0},
		{1, 1},
		{2, 1},
		{3, 2},
		{4, 3},
		{5, 5},
		{6, 8},
		{7, 13},
		{8, 21},
	}

	for _, Data := range testDatas {
		if res := Fib(uint64(Data.n)); res != uint64(Data.expected) {
			t.Errorf("Fib(%d) expected %d. Got %d instead", Data.n, Data.expected, res)
		}
	}
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).