Example #1
0
// Euler2 solution
func Euler2(l int) int {
	FibSeq := goutils.FibonacciLimit(l)
	var SumOfEvens int

	for i := 1; i < len(FibSeq); i++ {
		FibElem := FibSeq[i]
		if FibElem < l && goutils.IsDiv(FibElem, 2) {
			SumOfEvens += FibElem
		}
	}
	return SumOfEvens
}
// TestFibonacciLimit tests FibonacciLimit
func TestFibonacciLimit(t *testing.T) {
	var tt = []goutils.TTII{
		{10, 8},
	}

	for i := 0; i < len(tt); i++ {
		testIn := goutils.FibonacciLimit(tt[i].Test)
		lastTestIn := testIn[len(testIn)-1]
		testExp := tt[i].Expt

		if testExp != lastTestIn {
			t.Error("FibonacciLimit test failed")
		}
	}
}